🛠 Dompter le double USB : Serial/JTAG et OTG de front

ESP32-S3 · avance · Schéma : IMG-esp32-s3-avance-3-esp32-s3-dual-usb-jtag-cdc.svg — Carte ESP32-S3 avec deux connecteurs USB : l'un relié au périphérique USB-Serial/JTAG, l'autre au contrôleur OTG GPIO19/GPIO20, l'IDE affichant console série et débogage GDB simultanés.

Objectives

Leverage the unique feature of the ESP32-S3: two simultaneous USB personalities. On one side, the USB-Serial/JTAG peripheral (serial console + hardware debugging without an external bridge); on the other, the USB-OTG controller (HID/MSC/CDC device or host). On boards that wire both controllers to two distinct connectors (some DevKitC-1, ESP32-S3-Box), you can flash and debug via one port while emulating a keyboard on the other. You will configure the Hardware CDC+JTAG mode, launch a debug session, and understand pin routing.

Hardware

Full Code

// Mode "Hardware CDC and JTAG" : console + debug sur le port Serial/JTAG,
// le port OTG (GPIO19/20) reste libre pour un peripherique TinyUSB.
// Outils Arduino : USB CDC On Boot = Enabled,
//                  USB Mode = "Hardware CDC and JTAG"
#include "Arduino.h"

// Point d'arret logiciel : si un debogueur JTAG est attache, il s'y connecte ;
// sinon la boucle courte evite toute surprise côté watchdog.
volatile int drapeau_debug = 0;

void setup {
  Serial.begin(115200);            // passe par USB-Serial/JTAG (pas GPIO43/44)
  Serial.println("Boot sur USB-Serial/JTAG");
}

void loop {
  static uint32_t n = 0;
  if (drapeau_debug) {             // breakpoint logiciel : pause pour GDB
    while (drapeau_debug) { asm volatile("nop"); delay(1); }
  }
  if (++n % 50 == 0) Serial.printf("tick %u, heap %u\n", n, ESP.getFreeHeap);
  delay(20);
}

On the ESP-IDF side, the JTAG console is enabled via idf.py menuconfig → Component config → ESP System → “Channel for console output” → “USB Serial/JTAG”, and debugging via idf.py openocd followed by idf.py gdb (or the VS Code launch configuration “OpenOCD GDB Server”).

Expected Verification

Connected to the Serial/JTAG port, the board presents a serial port without any bridge chip; the console works at USB link speed. In debug mode (ESP-IDF), GDB attaches via the same cable: breakpoints, stepping, and memory reading without external JTAG. On a board with two connectors, the second port remains available for a TinyUSB device: the two worlds truly coexist.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials