Seeing issue while using two CDC com ports #3362
Replies: 5 comments 4 replies
-
|
Which MCU you are using ? On version 0.20 some code refactor was done for the CDC driver, please try if 0.19 works. |
Beta Was this translation helpful? Give feedback.
-
|
After some iterations, one CDC port always shows fifo_space = 0, so even when the host sends IN tokens, the device keeps NAKing and cannot transmit. |
Beta Was this translation helpful? Give feedback.
-
|
Help Needed on ZLP Handling Issue in MUSB DCD (CDC TX Case) Hi @HiFiPhile , I am working with an MSP432E401Y device and I seem to have narrowed down a CDC transmission issue to Zero Length Packet (ZLP) handling in TinyUSB. I understand the symptom, but I am not sure what the correct fix or expected behavior should be , so I need your guidance. Root Cause I Observed : The issue appears to originate from ZLP handling in dcd_musb.c. If I disable ZLP generation, CDC transmission behaves normally across multiple iterations. Where ZLP is Triggered : Inside cdc_device.c, in: bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) When tud_task() invokes this callback: if (ep_addr == stream_tx->ep_addr) { } This eventually causes ZLP submission to the DCD. Problem Area in dcd_musb.c Specifically in: static bool handle_xfer_in(uint8_t rhport, uint_fast8_t ep_addr) When TinyUSB submits a ZLP, the buffer pointer is NULL and length is zero. Then in the handler: rem == 0 execution enters: if (!rem) { But since TXRDY is not set, the endpoint never transmits the ZLP, no interrupt fires, and the endpoint remains stuck with busy/claimed flags permanently set. This results in CDC transfer halt. My Questions :
So far, disabling ZLP handling fixes all issues in my CDC application without adverse effects.
At DCD (dcd_musb) level, the handler cannot differentiate between: A genuine ZLP request or normal endpoint buffer becoming empty temporarily Because both cases look identical (remaining length = 0). How should this distinction be made so that the DCD sends a real ZLP via TXRDY?
We send data to CDC from UART, which is slower than USB. Later, when UART buffer drains, CDC buffer empties temporarily — but we still expect more data shortly. In this case TinyUSB thinks transfer has ended, so cdcd_xfer_cb() triggers ZLP. This ZLP was not intended — we just had momentary lack of UART data. So what is the correct approach to avoid wrong ZLP generation under such conditions? Any guidance on correct ZLP handling for CDC TX transfer and MUSB controller in the dcd_musb.c would be very helpful. Thank you!! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Hi @HiFiPhile , Thank you for the help and the quick fix suggestions 😃!! I’ll try it on the MSP432 MCU and let you know how it goes. |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I am trying to implement two CDC COM ports using TinyUSB. Receiving data from the host to the device works fine, and I can see the data in the buffer. However, when I loop the same data back to the same COM port, after a few iterations one of the COM ports stops working (it can be either one, randomly).
For that port, the API tud_cdc_n_write_available(itf) keeps returning 0. I checked the USB log as well: the host is sending IN tokens, but the device is responding with NAKs only. I am using tud_cdc_n_write() and tud_cdc_n_write_flush() for transmitting data.
Could anyone explain why tud_cdc_n_write_available() keeps returning 0 for one of the ports, and what might cause this behavior?
Beta Was this translation helpful? Give feedback.
All reactions