8000 shared/tinyusb/mp_usbd_cdc: Fix short CDC TX timeouts. · micropython/micropython@0129368 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0129368

Browse files
committed
shared/tinyusb/mp_usbd_cdc: Fix short CDC TX timeouts.
The `mp_event_wait_ms()` function may return earlier than the requested timeout, and if that happens repeatedly (eg due to lots of USB data and IRQs) then the loop waiting for CDC TX FIFO space to become available may exit much earlier than MICROPY_HW_USB_CDC_TX_TIMEOUT, even when there is no space. Fix this by using `mp_hal_ticks_ms()` to compute a more accurate timeout. The `basics/int_big_mul.py` test fails on RPI_PICO without this fix. Signed-off-by: Damien George <damien@micropython.org>
1 parent 908ab1c commit 0129368

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

shared/tinyusb/mp_usbd_cdc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ mp_uint_t mp_usbd_cdc_tx_strn(const char *str, mp_uint_t len) {
102102
n = CFG_TUD_CDC_EP_BUFSIZE;
103103
}
104104
if (tud_cdc_connected()) {
105-
int timeout = 0;
106105
// If CDC port is connected but the buffer is full, wait for up to USC_CDC_TIMEOUT ms.
107-
while (n > tud_cdc_write_available() && timeout++ < MICROPY_HW_USB_CDC_TX_TIMEOUT) {
106+
mp_uint_t t0 = mp_hal_ticks_ms();
107+
while (n > tud_cdc_write_available() && (mp_uint_t)(mp_hal_ticks_ms() - t0) < MICROPY_HW_USB_CDC_TX_TIMEOUT) {
108108
mp_event_wait_ms(1);
109109

110110
// Explicitly run the USB stack as the scheduler may be locked (eg we

0 commit comments

Comments
 (0)
0