🛠 Console sur l'USB-C natif (USB-Serial/JTAG)
Objectives
Unlike the classic ESP32, the ESP32-C3 integrates a USB-Serial/JTAG controller: the board's USB-C port communicates directly with the chip, without an external UART bridge (CP2102/CH340). You will learn how to use Serial over this native USB, how to avoid blocking when no terminal is open, and you will get a glimpse of JTAG debugging via the same port.
Hardware
- 1 ESP32-C3 board with native USB-C
- 1 USB-C data cable
- Serial terminal (Arduino IDE, PuTTY, or "screen")
Complete code
void setup {
Serial.begin(115200); // sur C3 : Serial = USB-Serial/JTAG
Serial.setTxTimeoutMs(0); // ne JAMAIS bloquer si terminal ferme
delay(1000); // laisse le temps d'ouvrir le terminal
Serial.println(F("Bonjour depuis l'USB natif du ESP32-C3"));
Serial.printf("Coeurs : %d, flash : %u Mo\n",
1, ESP.getFlashChipSize / 1048576);
}
void loop {
if (Serial.available) {
String s = Serial.readStringUntil('\n');
s.trim;
Serial.println(s); // echo de ce que vous tapez
}
delay(2);
}
Expected verification
Opening the terminal at 115200 bauds and then resetting the board displays the welcome message and "Cores: 1, flash: 4 MB". Everything you type is echoed back, passing through the same USB-C cable used for flashing.
Common errors
- No visible output: without a terminal open at startup, the USB-Serial/JTAG has no host; setTxTimeoutMs(0) prevents the program from hanging on printf calls.
- Double use of the port: during a flash or an OpenOCD (JTAG) session, the serial port is occupied; close the terminal before reflashing.
- Assuming Serial = UART0: on C3 boards with an additional chip (DevKitM-1 with CP2102), you must select USB CDC On Boot in the Tools menu to switch to native USB.
- Entry-level board without native USB wired: verify that the connector is properly connected to the D+/D- pins of the ESP32-C3.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinodht22.inoArduinooled-i2c.inoArduinoserveur-web.inoArduino