diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-13 16:39:04 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-13 16:39:04 +0100 |
commit | 212f89e61a96f9755590bc6f7c807808af5c057e (patch) | |
tree | 9f44a187aa30ae58c426e6f230f97f31dd1c78b8 /stmhal/usbd_cdc_interface.c | |
parent | 0e4ba258349ae94a18fb4e56dee7e1d4cc1ba3f0 (diff) | |
download | micropython-212f89e61a96f9755590bc6f7c807808af5c057e.tar.gz micropython-212f89e61a96f9755590bc6f7c807808af5c057e.zip |
stmhal: Improve USB CDC write function (increase timeout).
Diffstat (limited to 'stmhal/usbd_cdc_interface.c')
-rw-r--r-- | stmhal/usbd_cdc_interface.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/stmhal/usbd_cdc_interface.c b/stmhal/usbd_cdc_interface.c index 693f51b7c8..81f541df43 100644 --- a/stmhal/usbd_cdc_interface.c +++ b/stmhal/usbd_cdc_interface.c @@ -362,12 +362,10 @@ void USBD_CDC_SetInterrupt(int chr, void *data) { void USBD_CDC_Tx(const char *str, uint32_t len) { for (int i = 0; i < len; i++) { - uint timeout = 200; - while (((UserTxBufPtrIn + 1) & (APP_TX_DATA_SIZE - 1)) == UserTxBufPtrOut) { - if (timeout-- == 0) { - break; - } - HAL_Delay(1); + // if the buffer is full, wait until it gets drained, with a timeout of 1000ms (wraparound of tick is taken care of by 2's complement arithmetic) + uint32_t start = HAL_GetTick(); + while (((UserTxBufPtrIn + 1) & (APP_TX_DATA_SIZE - 1)) == UserTxBufPtrOut && HAL_GetTick() - start <= 1000) { + __WFI(); // enter sleep mode, waiting for interrupt } UserTxBuffer[UserTxBufPtrIn] = str[i]; UserTxBufPtrIn = (UserTxBufPtrIn + 1) & (APP_TX_DATA_SIZE - 1); |