summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/esp32/usb.c3
-rw-r--r--ports/esp32/usb.h2
2 files changed, 4 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;
diff --git a/ports/esp32/usb.h b/ports/esp32/usb.h
index a10378033..009bf4262 100644
--- a/ports/esp32/usb.h
+++ b/ports/esp32/usb.h
@@ -26,6 +26,8 @@
#ifndef MICROPY_INCLUDED_ESP32_USB_H
#define MICROPY_INCLUDED_ESP32_USB_H
+#define MICROPY_HW_USB_CDC_TX_TIMEOUT (500)
+
void usb_init(void);
void usb_tx_strn(const char *str, size_t len);