Replace tud_cdc_connected() with tud_ready() to ensure proper USB state detection - #63
Conversation
tud_ready() - the device is ready to communicate. tud_cdc_connected() - DTR flag
|
@BerranRemzi . Thanks for the submission. While I generally agree that the functional call swap is correct, I'm not sure that it is the problem with issue #61. My reasoning is twofold:
Also, I noticed that the sdk stdio_usb_out_chars now uses stdio_usb_connected rather than tud_cdc_connected which includes a check on PICO_STDIO_USB_CONNECTION_WITHOUT_DTR. We may want to do something similar. |
|
You are right, I didn’t succeed to set PICO_STDIO_USB_CONNECTION_WITHOUT_DTR macro, but most probably this macro will solve connection issues independent of DTR state |
|
Got it working! Added PICO_STDIO_USB_CONNECTION_WITHOUT_DTR with add_definitions() to cmake: |
|
@pico-coder can you review the changes? |
Description:
This PR fixes the serial connection issue reported in #61. The use of
tud_cdc_connected()may not reliably indicate a fully initialized USB stack (actually it indicates the DTR state), causing communication problems.Replacing it with
tud_ready()ensures proper USB state detection, improving stability.USB connection worked flawlessly with DTR on and off
I also provided a binary file with my changes