Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ endif # TARGET_OS

# OS-specific settings and build flags
ifeq ($(TARGET_OS),win32)
TARGET_CFLAGS = -D_WIN32
ARCHIVE ?= zip
TARGET := esptool.exe
TARGET_LDFLAGS = -Wl,-static -static-libgcc
Expand Down Expand Up @@ -68,6 +69,7 @@ OBJECTS := \
espcomm/espcomm_boards.o \
infohelper/infohelper.o \
serialport/serialport.o \
serialport/weirdbaud.o \
main.o

INCLUDES := $(addprefix -I,$(MODULES))
Expand Down
25 changes: 15 additions & 10 deletions serialport/serialport.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ static COMMTIMEOUTS sTIMEOUTS;
static int serial_port = -1;
static struct termios term;
static unsigned int timeout;
int weirdbaud (int, int);

#endif


Expand All @@ -67,7 +69,6 @@ static unsigned int timeout;
#define CBR_921600 921600
#endif


void serialport_setbaudrate(unsigned int baudrate)
{
DWORD br = 0;
Expand All @@ -89,7 +90,7 @@ void serialport_setbaudrate(unsigned int baudrate)
}
if (br == 0)
{
LOGWARN("unsupported baud rate: %d, using 115200", baudrate);
LOGWARN("unusual baud rate: %d, Might use 115200", baudrate);
br = CBR_115200;
}

Expand Down Expand Up @@ -119,7 +120,9 @@ int serialport_open(const char *device, unsigned int baudrate)
char portName[40];
sprintf(portName,"\\\\.\\%s", device);
sPort = CreateFile(portName, GENERIC_WRITE|GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

char dbmsg[100];
sprintf(dbmsg,"serialport_open %s at %d baud",portName,baudrate);
LOGDEBUG(dbmsg);
if (sPort == INVALID_HANDLE_VALUE)
{
LOGERR("Failed to open %s", device);
Expand Down Expand Up @@ -241,9 +244,9 @@ void serialport_send_break()
}
}


// End of _WIN32 section
#else

// Not to be confused with serialport_setbaudrate in the _WIN32 compilation...
void serialport_set_baudrate(unsigned int baudrate)
{
switch(baudrate)
Expand Down Expand Up @@ -277,7 +280,7 @@ void serialport_set_baudrate(unsigned int baudrate)
cfsetispeed(&term,B57600);
cfsetospeed(&term,B57600);
break;

case 115200:
cfsetispeed(&term,B115200);
cfsetospeed(&term,B115200);
Expand All @@ -299,10 +302,12 @@ void serialport_set_baudrate(unsigned int baudrate)
break;
#endif
default:
LOGWARN("serialport_set_baudrate: baud rate %d may not work", baudrate);
cfsetispeed(&term,baudrate);
cfsetospeed(&term,baudrate);
break;
LOGWARN("serialport_set_baudrate: %d baud is unusual", baudrate);
if (0 == weirdbaud(serial_port,baudrate)) // like 74880, maybe?
LOGDEBUG("Oddball baud rate accepted");
else
LOGWARN("Oddball baud rate REJECTED");
break;
}
}

Expand Down
22 changes: 22 additions & 0 deletions serialport/weirdbaud.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifdef _WIN32
#include <stdio.h>
#include <fcntl.h>
#include <asm/termios.h>
extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;

int weirdbaud (int serial_port, int speed) {
struct termios2 tio;
ioctl(serial_port, TCGETS2, &tio);
tio.c_cflag &= ~CBAUD;
tio.c_cflag |= BOTHER;
tio.c_ispeed = speed;
tio.c_ospeed = speed;
int r = ioctl(serial_port, TCSETS2, &tio);
return r;
}
#else
// I don't know how to do this for WIN32, so it's a stub that returns failure...
int weirdbaud (int serial_port, int speed) {
return(1);
}
#endif