summaryrefslogtreecommitdiff
path: root/ports/esp32/usb.c
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2022-10-16 13:49:03 +0200
committerDamien George <damien@micropython.org>2022-11-09 11:16:55 +1100
commitd68e3b03b1053a6de0c7eb28f5989132c138364b (patch)
treee24734a49b6ab94da96ec8881981018c6ae478c0 /ports/esp32/usb.c
parent5d473d309396942092077f4917be3e044c9a6c39 (diff)
esp32/usb: Add a timeout to usb_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.
Diffstat (limited to 'ports/esp32/usb.c')
-rw-r--r--ports/esp32/usb.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/ports/esp32/usb.c b/ports/esp32/usb.c
index 5a613d244..953c5422b 100644
--- a/ports/esp32/usb.c
+++ b/ports/esp32/usb.c
@@ -88,7 +88,8 @@ void usb_init(void) {
void usb_tx_strn(const char *str, size_t len) {
// Write out the data to the CDC interface, but only while the USB host is connected.
- while (usb_cdc_connected && len) {
+ uint64_t timeout = esp_timer_get_time() + (uint64_t)(MICROPY_HW_USB_CDC_TX_TIMEOUT * 1000);
+ while (usb_cdc_connected && len && esp_timer_get_time() < timeout) {
size_t l = tinyusb_cdcacm_write_queue(CDC_ITF, (uint8_t *)str, len);
str += l;
len -= l;