ESP32 "Wrong boot mode detected! The chip needs to be in download mode"
This one is good news of a kind: the cable, port and driver work, because esptool read the chip's boot log. The chip just started your application instead of the download mode.
Connecting...................................... A fatal error occurred: Failed to connect to ESP32: Wrong boot mode detected (0x13)! The chip needs to be in download mode.
The number in brackets is the strapping register the ROM printed at boot (boot:0x13 in the boot log): the pins it read at reset, one bit each. It shows that the boot pin was high, so the chip started normally.
The usual causes
- The auto-reset did not pull the boot pin low in time. Common on cheap boards and on boards without a capacitor on EN. Enter download mode by hand (below), or add a 1 µF to 10 µF capacitor between EN and GND, as Espressif recommends.
- Something holds the boot pin high: a pull-up, a button, or a module wired to
GPIO0(orGPIO9on the C3, C6, H2). - A USB-serial adapter without DTR and RTS wired, on a custom board. Then the boot mode must be entered by hand every time.
- On Linux, a reset loop from the port settings: Espressif suggests turning off HUPCL, for example
stty -F /dev/ttyUSB0 -hupcl.
Download mode, and the pin that selects it
esptool can only flash a chip that has started in its ROM's download mode. The chip decides at reset, from a strapping pin:
- ESP32, ESP32-S2, ESP32-S3:
GPIO0low at reset. On the ESP32,GPIO2must also be low or left floating. - ESP32-C3, C6, H2:
GPIO9low at reset. On the ESP32-C3,GPIO8must be high at the same time.
Development boards do this for you: esptool pulses the serial chip's DTR and RTS lines, which a two-transistor circuit turns into GPIO0 and EN. Boards with the chip's built-in USB (USB-Serial/JTAG on the C3, S3, C6 and others) do it over USB without that circuit. To do it by hand: hold BOOT, press and release EN (or RST), then release BOOT, and start the upload.
Try it from the browser
To rule out the computer's setup (drivers, Python, the IDE's settings), try the free ESP32 web flasher in Chrome or Edge: it uses the same ROM protocol over WebSerial and needs nothing installed. If it cannot connect either, the problem is the board, the cable or the boot mode.
And once a device is flashed and installed somewhere, you should not need a cable again: Pinscope updates the firmware over the internet, with a rollback if the new build does not come back. OTA over the internet.
Related errors: Failed to connect to ESP32 · Invalid head of packet · rst:0x… reset reasons · Could not open port, the port is busy. All ESP32 errors: the list. Message from esptool's source (loader.py); causes from Espressif's esptool Troubleshooting guide and Boot Mode Selection.
More
- Remote access to an ESP32 without TLS: what it measured and what it costs
- Reaching an ESP32 web server from outside its network
- Updating ESP32 firmware over the internet, with rollback
- Guru Meditation Error: decoding the backtrace, and crashes from the field
- Remote logging: ESP_LOG without a serial cable
- Heap and stack monitoring in the field
- An ESP32 behind CGNAT, 4G or Starlink
- TLS memory usage on the ESP32, and how to reduce it
- Sharing an ESP32 sensor page with anyone, without port forwarding
- ArduinoOTA over the internet, with a rollback
- ESP32 remote access compared: port forwarding, ngrok, Cloudflare Tunnel, Tailscale
- esp_http_server slow? The 250 ms delay and the fix
- Before the first ESP32 ships: a field support checklist
- ESP32 exception decoder: a Guru Meditation backtrace to lines, in the browser