🛠 Débogage pas à pas : CMSIS-DAP et Arduino Debug Launcher
Objectives
Move beyond Serial.print for debugging: the R4 is the first UNO with an embedded hardware debugger. The embedded USB bridge (HIC) exposes a CMSIS-DAP interface connected to the RA4M1's SWD, and the official Arduino Debug Launcher extension (VS Code / PlatformIO or IDE 2.x) enables breakpoints, stepping, and inspection of variables and memory — exactly like on STM32.
Hardware
- 1 Arduino UNO R4 WiFi + USB-C data cable (connected to the USB-C port on the HIC side, the one used for uploading)
- VS Code with the Arduino Debug Launcher extension, or Arduino IDE 2.x with the debugging feature enabled
- A non-trivial sketch: a function that calculates, a loop, an array.
Procedure
- Install the Arduino Debug Launcher extension and the proposed debugging component (OpenOCD/CMSIS-DAP managed by the extension).
- Open the sketch, place a breakpoint on a line in
loop. - Launch "Start Debugging": the board is flashed and then stopped at the breakpoint.
- Explore: local variables, global variables, call stack, Cortex-M4 registers, memory; step through with step-over/step-into (F10/F11).
// Croquis de test : le bug classique du débordement d'index.
int mesures[8];
int n = 0;
void setup { Serial.begin(115200); }
void loop {
mesures[n] = analogRead(A0); // point d'arrêt ici : surveillez n
n++;
if (n > 8) n = 0; // bug volontaire : devrait etre n >= 8
delay(200);
}
Expected Verification
Execution freezes at the breakpoint; the Variables window shows n increasing. By monitoring the array, you see the out-of-bounds write when n == 8 — the kind of bug invisible with Serial.print. Resume (F5), modify the condition, reflash, and recheck: this is the complete debugging loop.
Common Errors
- Compiler optimization: with -O2, variables may "disappear" or stepping may skip lines; switch optimization to -O0 (IDE compilation option) for debugging, then restore it for production.
delayduring debugging: the debugger interrupts the core; the watchdog and WiFi continue running on the ESP32-S3 side — the system state is not frozen as in a simple pause.- Plugging the cable into the wrong USB-C port: debugging goes through the port connected to the HIC; the other port (RA4M1 native USB) does not provide CMSIS-DAP.
- Confusing the debugger and the serial monitor: during a debugging session, the serial port is often occupied by the session; use the other USB port for a separate CDC if needed.
- Expecting to debug the ESP32-S3: the debugger only controls the RA4M1; the ESP32-S3 is not accessible for stepping via this path.
Other tutorials for this board
- Premier Blink sur la UNO R4 WiFi : la première UNO 32 bits
- Apprivoiser la matrice LED 12x8 intégrée
- Toucher capacitif : touchRead sans composant
- Se connecter au WiFi et lire l'heure NTP (WiFiS3)
- Inclinomètre sur la matrice : l'IMU LSM6DSV16X en I²C
- Serveur web embarqué : piloter la matrice depuis le navigateur
Code examples for this board
clignotante.inoArduinobouton-poussoir.inoArduinodac-analogique.inoArduinoentree-analogique.inoArduinopwm-respiration.inoArduinoservo-balayage.inoArduino