diff options
author | Damien George <damien@micropython.org> | 2021-02-12 14:09:01 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2021-02-12 14:09:01 +1100 |
commit | ede6b86a08ea3a749e1785c5263723c875b08359 (patch) | |
tree | 4b872e8357bf9cc446794da1db14e6d4697b4b4a | |
parent | f31c6b484060eb3554aa13bb758cc9a5974cafbb (diff) |
samd/mphalport: Fix USB CDC tx handling to work reliably.
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r-- | ports/samd/mphalport.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/ports/samd/mphalport.c b/ports/samd/mphalport.c index 67fc2cb0d..357ec93a6 100644 --- a/ports/samd/mphalport.c +++ b/ports/samd/mphalport.c @@ -80,17 +80,16 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { if (tud_cdc_connected()) { for (size_t i = 0; i < len;) { uint32_t n = len - i; - uint32_t n2 = tud_cdc_write(str + i, n); - if (n2 < n) { - while (!tud_cdc_write_flush()) { - __WFI(); - } + if (n > CFG_TUD_CDC_EP_BUFSIZE) { + n = CFG_TUD_CDC_EP_BUFSIZE; + } + while (n > tud_cdc_write_available()) { + __WFI(); } + uint32_t n2 = tud_cdc_write(str + i, n); + tud_cdc_write_flush(); i += n2; } - while (!tud_cdc_write_flush()) { - __WFI(); - } } while (len--) { while (!(USARTx->USART.INTFLAG.bit.DRE)) { |