Skip to content

Replace tud_cdc_connected() with tud_ready() to ensure proper USB state detection #63

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BerranRemzi
Copy link
Contributor

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

tud_ready() - the device is ready to communicate.
tud_cdc_connected() - DTR flag
@BerranRemzi BerranRemzi marked this pull request as draft March 24, 2025 21:19
@pico-coder
Copy link
Owner

@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:

  1. The my_stdio_usb_out_chars function is only called when we have received a command from the host. That means that the USB link must be up, the device must be found by the OS and pulseview/sigrok-cli/some other application is issuing downstream requests. That all doesn't guarantee that the DTR is set, but it's hard to imagine that it wouldn't be by now.
  2. Most issues folks have with the devices are a fairly hard "it either works completely, or it doesn't" and is usually fixed with Zadig or something else.
    Again, I can't say it's not the problem, and I'm mostly wondering if you actually created some kind of failure to connect with tud_cdc_connected that was fixed with tud_ready, or if you just ran the build with tud_ready and confirmed that things didn't at least get any worse?

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.

@BerranRemzi
Copy link
Contributor Author

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

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

Successfully merging this pull request may close these issues.

2 participants