ESP32C2 - understanding the CDC port
Posted: Sat Jun 14, 2025 12:03 pm
I am trying to understand the workings of the CDC port on an ESP32. I am working on a project where the ESP is connected via USB directly to the PC. There is no UART.
The port is set up in the program as follows:
In PlatformIO/pioarduino, the following has been added to the board profile:
-D ARDUINO_USB_CDC_ON_BOOT=1
The port works, sort of in the Vscode Serial Monirot, but not in anything else.
What happens is that when initially connected to Serial Monitor, it does not respond. Then when RESET is pressed, Serial Monitor shows the connection being lost and re-established again. On re-connection, it responds and transmits data.
The problem is that in any other terminal application (also tried a Python script), the terminal quits as soon as RESET is pressed.
Is there anything else that needs to be added to force the serial connection to open? I have tried this with both Arduino core 2 and Arduino core 3 with the same result.
I am not sure whether this is a PlatfromIO/pioarduino issue, but when I use standard Arduino methods (Serial.begin(115200)) and compile in the Arduino IDE, the serial port works as expected, so I am not sure its a hardware issue. However, as can bee seen in the above snippet, evidently serial is dealt with differently when using CDC methods in the Espressif core.
The port is set up in the program as follows:
Code: Select all
mySerial =(Stream*) &(UsbCdcSerial);
UsbCdcSerial.begin();
USB.begin();-D ARDUINO_USB_CDC_ON_BOOT=1
The port works, sort of in the Vscode Serial Monirot, but not in anything else.
What happens is that when initially connected to Serial Monitor, it does not respond. Then when RESET is pressed, Serial Monitor shows the connection being lost and re-established again. On re-connection, it responds and transmits data.
The problem is that in any other terminal application (also tried a Python script), the terminal quits as soon as RESET is pressed.
Is there anything else that needs to be added to force the serial connection to open? I have tried this with both Arduino core 2 and Arduino core 3 with the same result.
I am not sure whether this is a PlatfromIO/pioarduino issue, but when I use standard Arduino methods (Serial.begin(115200)) and compile in the Arduino IDE, the serial port works as expected, so I am not sure its a hardware issue. However, as can bee seen in the above snippet, evidently serial is dealt with differently when using CDC methods in the Espressif core.