From e33bcb822e262b00a135b1d09f336e47d3275b30 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Thu, 4 Jan 2024 16:03:46 +0100 Subject: [PATCH] USB CDC: avoid hung devices when USB host is not connected see https://github.com/espressif/arduino-esp32/issues/9043 " The S3, C3, C6 and H2 that have HW CDC JTAG USB port may cause a delay when using HWCDC in Serial by activating CDC on Boot and selecting the USB Mode for Hardware CDC and JTAG. This happens when no USB application in USB Host side is started to receive the data sent by the ESP32xx. The USB CDC buffer gets full and the Arduino HW CDC layer will timeout, by default 100ms, until give up trying to send the CDC data. As a workaround, it is necessary to use HWCDC::setTxTimeoutMs(timeout_ms) and set it to zero. " --- wled00/wled.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index be897d3c..b2dcc3f3 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -451,6 +451,10 @@ void WLED::setup() if (!Serial) delay(2500); // WLEDMM allow CDC USB serial to initialise #endif #if ARDUINO_USB_CDC_ON_BOOT || ARDUINO_USB_MODE + #if ARDUINO_USB_CDC_ON_BOOT && (defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6)) + // WLEDMM avoid "hung devices" when USB_CDC is enabled; see https://github.com/espressif/arduino-esp32/issues/9043 + Serial.setTxTimeoutMs(0); // potential side-effect: incomplete debug output, with missing characters whenever TX buffer is full. + #endif if (!Serial) delay(2500); // WLEDMM: always allow CDC USB serial to initialise if (Serial) Serial.println("wait 1"); // waiting a bit longer ensures that a debug messages are shown in serial monitor if (!Serial) delay(2500);