Page 1 of 1

USB CDC unstable

Posted: Wed May 21, 2025 6:11 pm
by floitsch_toit
TL;DR: is there a way to ensure that the CDC starts up correctly?

I'm trying to get USB CDC to work on an ESP32S2.

If we delay the main of our program (basically a sleep in the first line), then the device correctly enumerates and is detected. If we don't then things go bad: the USB uart doesn't work and the program doesn't run. Since I don't have access to the logs at that point I don't know if there are crashes or other problems.

On my Linux machine I have output that is similar to the following:

Code: Select all

[498355.059862] cdc_acm 5-2.2:1.0: ttyACM0: USB ACM device
[498355.067022] usb 5-2.2: USB disconnect, device number 71
[498355.717746] usb 5-2.2: new full-speed USB device number 72 using xhci_hcd
[498356.302995] usb 5-2.2: device descriptor read/64, error -32
[498374.320576] usb 5-2.2: unable to read config index 0 descriptor/all
[498374.320594] usb 5-2.2: can't read configurations, error -110
As mentioned above a temporary fix is to delay the start of our program:

Code: Select all

--- a/toolchains/esp32s2/main/toit.c
+++ b/toolchains/esp32s2/main/toit.c
@@ -15,8 +15,16 @@
 
 // Toit ESP32 top level, derived from ESP-IDF Hello World example.
 
+#include <freertos/FreeRTOS.h>
+
 extern void toit_start();
 
 void app_main() {
+  vTaskDelay(1000 / portTICK_PERIOD_MS);  // Sleep for 1 second
   toit_start();
 }
Our question now: is there a way to ensure that the CDC code starts up correctly, without us delaying the main program?
Is there an easy way to see what goes wrong?

Note that the problem is not dependent on the host computer. Even without any USB-connection, our program will never connect to the WiFi. If we disable CDC in the skdconfig, it works without issues.

Edit: we are currently using esp-idf 5.3.1.