esptool "Invalid head of packet: Possible serial noise or corruption"
esptool expected a packet starting with 0xC0 and got something else. The link works enough to carry bytes, but not cleanly.
A fatal error occurred: Invalid head of packet (0x46): Possible serial noise or corruption.
Related messages from the same part of esptool: Packet content transfer stopped (received 8 bytes) and Serial data stream stopped: Possible serial noise or corruption., when the stream breaks off in the middle of a packet.
The usual causes
From Espressif's troubleshooting guide:
- A poor USB cable, or a long one through hubs.
- Shorts on the SPI flash pins on a breadboard (
GPIO6toGPIO11on the ESP32). - A brownout from a weak supply, which resets the chip in the middle of the transfer. See brownout.
- Your application still running and printing, if the chip did not enter download mode: the "packet" is its log text. The byte in brackets is often a printable character, such as
0x46forF.
Try
- A short, known-good data cable, directly to the computer.
- A lower speed:
--baud 9600. --chip esp32(or your chip) to skip autodetection, and--traceto see what actually arrives.
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 · Wrong boot mode detected · Brownout detector was triggered · Could not open port, the port is busy. All ESP32 errors: the list. Messages from esptool's source (loader.py); causes from Espressif's esptool Troubleshooting guide.
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