diff options
| author | robert-hh <robert@hammelrath.com> | 2022-10-16 12:06:58 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-11-09 11:12:53 +1100 |
| commit | 8447fef9f9d0db8104d0e600b79870c4aafa9725 (patch) | |
| tree | 0db476eb569825c33a16905acb8e13185f2377fd | |
| parent | d0687e90ab27c064270aed648c27424d06c9814c (diff) | |
rp2/mphalport: Add a timeout to mp_hal_stdout_tx_strn().
If USB CDC is connected and the board sends data, but the host does not
receive the data, the device locks up. This is fixed in this commit by
having a timeout of 500ms, after which time the transmission is skipped.
Fixes issue #9634.
| -rw-r--r-- | ports/rp2/mphalport.c | 7 | ||||
| -rw-r--r-- | ports/rp2/mphalport.h | 1 |
2 files changed, 7 insertions, 1 deletions
diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c index 63ff76f5d..6ba234c66 100644 --- a/ports/rp2/mphalport.c +++ b/ports/rp2/mphalport.c @@ -139,9 +139,14 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { if (n > CFG_TUD_CDC_EP_BUFSIZE) { n = CFG_TUD_CDC_EP_BUFSIZE; } - while (n > tud_cdc_write_available()) { + int timeout = 0; + // Wait with a max of USC_CDC_TIMEOUT ms + while (n > tud_cdc_write_available() && timeout++ < MICROPY_HW_USB_CDC_TX_TIMEOUT) { MICROPY_EVENT_POLL_HOOK } + if (timeout >= MICROPY_HW_USB_CDC_TX_TIMEOUT) { + break; + } uint32_t n2 = tud_cdc_write(str + i, n); tud_cdc_write_flush(); i += n2; diff --git a/ports/rp2/mphalport.h b/ports/rp2/mphalport.h index 31bedf338..73a503f5a 100644 --- a/ports/rp2/mphalport.h +++ b/ports/rp2/mphalport.h @@ -33,6 +33,7 @@ #include "RP2040.h" // cmsis, for __WFI #define SYSTICK_MAX (0xffffff) +#define MICROPY_HW_USB_CDC_TX_TIMEOUT (500) extern int mp_interrupt_char; extern ringbuf_t stdin_ringbuf; |
