Skip to content

Commit

Permalink
FIX: add missing text
Browse files Browse the repository at this point in the history
  • Loading branch information
r2axz committed Feb 9, 2022
1 parent 15c06af commit ae334a3
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,55 @@ 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
the **RTS** state changes. However, on the **DTR** state change, the driver sends
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 <windows.h>
#include <stdio.h>

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
Expand Down

0 comments on commit ae334a3

Please # to comment.