Skip to content

Commit

Permalink
USB CDC: avoid hung devices when USB host is not connected
Browse files Browse the repository at this point in the history
see espressif/arduino-esp32#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.
"
  • Loading branch information
softhack007 committed Jan 4, 2024
1 parent 889e27f commit e33bcb8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e33bcb8

Please sign in to comment.