From 880f7bc0406a1ef249c833e1a88c023cd339ecf6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 24 Jun 2024 15:54:54 +1000 Subject: [PATCH] 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 --- shared/tinyusb/mp_usbd_cdc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/tinyusb/mp_usbd_cdc.c b/shared/tinyusb/mp_usbd_cdc.c index 674d6b089947e..63d015cb461f5 100644 --- a/shared/tinyusb/mp_usbd_cdc.c +++ b/shared/tinyusb/mp_usbd_cdc.c @@ -102,9 +102,9 @@ mp_uint_t mp_usbd_cdc_tx_strn(const char *str, mp_uint_t len) { n = CFG_TUD_CDC_EP_BUFSIZE; } if (tud_cdc_connected()) { - int timeout = 0; // If CDC port is connected but the buffer is full, wait for up to USC_CDC_TIMEOUT ms. - while (n > tud_cdc_write_available() && timeout++ < MICROPY_HW_USB_CDC_TX_TIMEOUT) { + mp_uint_t t0 = mp_hal_ticks_ms(); + while (n > tud_cdc_write_available() && (mp_uint_t)(mp_hal_ticks_ms() - t0) < MICROPY_HW_USB_CDC_TX_TIMEOUT) { mp_event_wait_ms(1); // Explicitly run the USB stack as the scheduler may be locked (eg we pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy