🛠 Console série sur l'USB natif (CDC) du S3
Objectives
Master the serial console on ESP32-S3 via native USB. Unlike the classic ESP32, the S3 does not need a USB-to-serial bridge chip: it has both a USB-OTG controller (pins GPIO19/GPIO20) and a USB-Serial/JTAG peripheral. By enabling "USB CDC On Boot: Enabled", the Serial.print command outputs directly through the board's USB port. You will also learn the difference with the legacy UART0 (GPIO43 TX / GPIO44 RX by default) and how to regain access if the port disappears.
Hardware
- 1 ESP32-S3 board with native USB wired (DevKitC-1 v1.1, XIAO ESP32S3, Feather S3…)
- 1 USB data cable
- Arduino IDE 2.x with the "esp32 by Espressif Systems" core (v2.0.14 or newer)
Complete Code
// Console sur USB natif : outils Arduino -> "USB CDC On Boot: Enabled"
// (sur certaines cartes : "USB Mode: Hardware CDC and JTAG")
unsigned long t0 = millis;
uint32_t n = 0;
void setup {
Serial.begin(115200); // flux CDC, pas d'UART materielle ici
while (!Serial && millis < 5000) {
// attend que le terminal hote soit branche (max 5 s)
delay(10);
}
Serial.println;
Serial.println("ESP32-S3 : console sur USB natif (CDC)");
Serial.printf("Chip: %s, %d coeur(s), %.0f MHz\n",
"ESP32-S3", portNUM_PROCESSORS,
(double)getCpuFreqMHz);
}
void loop {
Serial.printf("[%4.1f s] message n=%u\n", (millis - t0) / 1000.0, ++n);
if (Serial.available) { // echo de ce que l'hote envoie
char c = Serial.read;
Serial.print("Recu: ");
Serial.println(c);
}
delay(1000);
}
Expected Verification
The IDE serial monitor (or PuTTY/Arduino Serial Monitor at 115200) displays the header followed by one line per second; characters typed on the computer are echoed back. All this with a single USB cable, without an external serial bridge. The Windows Device Manager confirms the presence of a "USB Serial Device" when the board is recognized.
Common Errors
- "USB CDC On Boot" left on Disabled: the code runs but Serial.print goes to UART0 (GPIO43/44) and the monitor remains hopelessly empty.
- Writing too early: on CDC, the first bytes sent before the port is opened are lost; the while (!Serial ...) loop above limits this phenomenon.
- A TinyUSB/HID later claims GPIO19/20: if you switch to TinyUSB mode, the hardware CDC port disappears; everything is decided in the Tools menu.
- Stuck in a reset loop: hold BOOT, press RESET, release RESET then BOOT forces download mode (ROM) and allows reflashing.
- Wrong board type: choose "ESP32S3 Dev Module" (or the exact board), not an ESP32 or ESP32-C3 model.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinodht22.inoArduinooled-i2c.inoArduinoserveur-web.inoArduino