🛠 Strapping GPIO2/8/9 : le diagnostic de boot
Objectives
At reset, the ESP32-C3 samples three strapping pins: GPIO2, GPIO8, and GPIO9. Their levels determine the boot mode (flash, JTAG, ROM messages). A sensor, a NeoPixel, or a poorly placed pull-down on one of these pins can cause boot loops, "invalid header" errors, or phantom USB ports. This tutorial teaches you how to diagnose the state of these pins and the reason for the reset.
Hardware
- 1 ESP32-C3 board
- 3 jumpers to pull the pins to GND during testing
- USB-Serial/JTAG console open
Complete code
const int STRAP[] = {2, 8, 9}; // broches echantillonnees au reset
void setup {
Serial.begin(115200);
delay(1000); // le temps d'ouvrir le terminal
esp_reset_reason_t r = esp_reset_reason;
Serial.printf("Raison de reset : %d "
"(1=POWERON, 3=SW, 8=BROWNOUT...)\n", (int)r);
for (int p : STRAP) {
pinMode(p, INPUT); // lecture sans forcer de pull
int niveau = digitalRead(p);
Serial.printf("GPIO%d = %d %s\n", p, niveau,
niveau == 0 ? "<- BAS : risque au prochain reset !"
: "OK");
}
}
void loop { delay(1000); }
Expected verification
At rest, GPIO9 (BOOT button) and GPIO8 read 1, and GPIO2 is floating. Pulling GPIO9 to ground and then resetting causes the log to show a switch to download mode; pulling GPIO8 low changes the boot behavior (ROM messages disabled, mode modified). The diagnostic cross-references these levels with the reset reason.
Common errors
- LED or NeoPixel on GPIO8 with a pull-down at rest: the strapping pin is read as 0 at reset, causing boot divergence; move the data line to GPIO0-7 or 10+.
- Interpreting a brown-out (reason 8) as a strapping issue: measure the power supply before blaming the pins.
- Forgetting that GPIO9 is the BOOT button: holding it during flashing is normal for flashing, but pressing it at the wrong moment during reset causes a restart in download mode.
- Relying on runtime pin readings to know the level at reset: only the level present at the instant of reset matters; replay the reset to observe it.
Other tutorials for this board
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinorespiration.inoArduinodht22.inoArduinooled-i2c.inoArduinoserveur-web.inoArduino