Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CDC_write is blocking #2

Open
dunarri opened this issue Dec 11, 2023 · 4 comments
Open

CDC_write is blocking #2

dunarri opened this issue Dec 11, 2023 · 4 comments

Comments

@dunarri
Copy link

dunarri commented Dec 11, 2023

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:

while(CDC_writeBusyFlag); // wait for ready to write

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 added a commit that referenced this issue Dec 16, 2023
@wagiminator
Copy link
Owner

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
Copy link
Author

dunarri commented Dec 20, 2023

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
Copy link
Owner

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
Copy link
Author

dunarri commented Dec 20, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants