diff --git a/Makefile b/Makefile index 03d1aad..0ba4c20 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -68,6 +69,7 @@ OBJECTS := \ espcomm/espcomm_boards.o \ infohelper/infohelper.o \ serialport/serialport.o \ + serialport/weirdbaud.o \ main.o INCLUDES := $(addprefix -I,$(MODULES)) diff --git a/serialport/serialport.c b/serialport/serialport.c index e9a1eb3..8c324da 100644 --- a/serialport/serialport.c +++ b/serialport/serialport.c @@ -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 @@ -67,7 +69,6 @@ static unsigned int timeout; #define CBR_921600 921600 #endif - void serialport_setbaudrate(unsigned int baudrate) { DWORD br = 0; @@ -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; } @@ -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); @@ -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) @@ -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); @@ -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; } } diff --git a/serialport/weirdbaud.c b/serialport/weirdbaud.c new file mode 100644 index 0000000..cba5fd3 --- /dev/null +++ b/serialport/weirdbaud.c @@ -0,0 +1,22 @@ +#ifdef _WIN32 +#include +#include +#include +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