diff --git a/README.md b/README.md index 8b83802..d77c5dd 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ The **Value** field will indicate the physical UART name. ## Windows Usbser.sys RTS Bug -All versions of _Windows_ have a bug in the USB CDC system driver (usbser.sys) +All versions of _Windows_ have a bug in the USB CDC system driver (**usbser.sys**) that affects RTS signal handling. The driver does not send USB **SET_CONTROL_LINE_STATE** messages when @@ -130,6 +130,47 @@ the **RTS** state changes. However, on the **DTR** state change, the driver send a **SET_CONTROL_LINE_STATE** message containing the updated states for both **RTS** and **DTR** signals. +It is unknown why **usbser.sys** does this, but the disassembled code +of the driver suggests that sending **SET_CONTROL_LINE_STATE** on **RTS** change +is simply left out by mistake. It looks like _Microsoft_ is not going to fix +this bug. However, it can be easily worked around. + +The workaround for this bug is to update DTR (even to the same state) each time +RTS needs to be updated as in the example below: + +```c +#include +#include + +int main() { + HANDLE hComm = CreateFileA("\\\\.\\COM5", GENERIC_READ | GENERIC_WRITE, + 0, NULL, OPEN_EXISTING, 0, NULL); + if (hComm == INVALID_HANDLE_VALUE) { + printf("Error opening serial port\n"); + } else { + printf("Serial port opened\n"); + } + while (1) { + // I don't know any easy (and reliable) way to get current DTR state in WinAPI unfortunately. + // Probably the simplest solution is to keep current DTR value in a variable. + EscapeCommFunction(hComm, SETRTS); + EscapeCommFunction(hComm, CLRDTR); // or SETDTR, does not matter + (void)getc(stdin); + EscapeCommFunction(hComm, CLRRTS); + EscapeCommFunction(hComm, CLRDTR); // or SETDTR, does not matter + (void)getc(stdin); + } + CloseHandle(hComm); + return 0; +} +``` + +Some existing software already does that. _CwType_, _Win-Test_, _CoolTerm_ +are the examples of such software. Others like _N1MM Logger Plus_ or _Termite_ +do not implement the workaround. + +The RTS issue does not affect _Linux_ or _macOS_. + ## Advanced Configuration _bluepill-serial-monster_ provides a configuration shell that allows