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.
"
This commit is contained in:
Frank
2024-01-04 16:03:46 +01:00
parent 889e27fed5
commit e33bcb822e

View File

@@ -451,6 +451,10 @@ void WLED::setup()
if (!Serial) delay(2500); // WLEDMM allow CDC USB serial to initialise if (!Serial) delay(2500); // WLEDMM allow CDC USB serial to initialise
#endif #endif
#if ARDUINO_USB_CDC_ON_BOOT || ARDUINO_USB_MODE #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) 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) Serial.println("wait 1"); // waiting a bit longer ensures that a debug messages are shown in serial monitor
if (!Serial) delay(2500); if (!Serial) delay(2500);