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

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:

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