diff options
| -rw-r--r-- | ports/mimxrt/mphalport.c | 10 | ||||
| -rw-r--r-- | ports/mimxrt/mphalport.h | 2 |
2 files changed, 10 insertions, 2 deletions
diff --git a/ports/mimxrt/mphalport.c b/ports/mimxrt/mphalport.c index 87741e0b5..33f9c2691 100644 --- a/ports/mimxrt/mphalport.c +++ b/ports/mimxrt/mphalport.c @@ -116,9 +116,15 @@ 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()) { - __WFE(); + uint64_t timeout = ticks_us64() + (uint64_t)(MICROPY_HW_USB_CDC_TX_TIMEOUT * 1000); + // Wait with a max of USC_CDC_TIMEOUT ms + while (n > tud_cdc_write_available() && ticks_us64() < timeout) { + MICROPY_EVENT_POLL_HOOK } + if (ticks_us64() >= timeout) { + break; + } + uint32_t n2 = tud_cdc_write(str + i, n); tud_cdc_write_flush(); i += n2; diff --git a/ports/mimxrt/mphalport.h b/ports/mimxrt/mphalport.h index 30390a4a4..5136a36b3 100644 --- a/ports/mimxrt/mphalport.h +++ b/ports/mimxrt/mphalport.h @@ -35,6 +35,8 @@ #define MICROPY_HAL_VERSION "2.8.0" +#define MICROPY_HW_USB_CDC_TX_TIMEOUT (500) + #define MP_HAL_PIN_FMT "%q" extern ringbuf_t stdin_ringbuf; |
