wagiminator / CH552-DAPLink

CMSIS-DAP compliant debugging probe with SWD, JTAG, and VCP support
https://oshwlab.com/wagiminator/ch552g-daplink
Other
22 stars 7 forks source link

CDC_write is blocking #2

Open dunarri opened 9 months ago

dunarri commented 9 months ago

First off a big thank you for creating this and putting it on github!

I created a board with a CH551 on it to use as a build in SWD, however the DAPLink would become unresponsive. After some debugging I realized this was because my target was sending serial data to the CH551 UART, but I didn't have a serial monitor connected. This caused CDC_write to hang at the following line:

https://github.com/wagiminator/CH552-DAPLink/blob/c7975f84171129db54b3eef053588d27d78ec935/software/src/usb_cdc.c#L73

My quick and dirty fix was to use the DTR flag to decide if it should try to write the data to the CDC, so I changed line 97 of daplink.c to: if(CDC_getDTR() && UART_available()) {

This of course requires the serial monitor to set DTR, but it solved the problem for me. With no terminal connected the UART just continues happily overwriting the old data in buffer.

wagiminator commented 9 months ago

Hi, thank you very much for the tip. It's not entirely clear to me why it hangs, but if the fix helps, that's good. At least every serial monitor I know also sets the DTR flag, so that shouldn't be a problem.

dunarri commented 8 months ago

It hangs at the line I quoted above because the busy flag never gets cleared. It's normally cleared in CDC_EP2_IN(), but that only gets called when a serial monitor is connected.

Anyway, I found one other thing I had to fix that I might post a separate issue for. After that everything is working smoothly.

wagiminator commented 8 months ago

Perhaps the problem depends on the CDC driver or operating system used. Actually, the packages should be accepted even if no serial monitor accesses the driver.

dunarri commented 8 months ago

In that case, it may be relevant that I'm using Mac OS.