Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.
Upload error · esptool

Fix “Invalid head of packet” when uploading to ESP32

esptool receives garbled bytes instead of a valid reply — serial noise, a too-high upload speed, or something else talking on the port.

ESP32ESP8266ESP32-CAMUpdated 31 Oct 2026

Community draft — report a mistake

What you see

OutputOutput
Connecting....
Chip is ESP32-D0WD-V3 (revision v3.1)
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600

A fatal error occurred: Invalid head of packet (0x1B): Possible serial noise or corruption.
Failed uploading: uploading error: exit status 2

esptool expects every reply from the bootloader to start with a fixed marker byte. “Invalid head of packet” means it got something else — the reply was corrupted on the way, or another device on the line was talking.

Slowing the upload down is the quickest test: if 115200 works, the cable or USB-serial chip cannot handle 921600.

Quick fix — try in order

  1. 1

    Lower the upload speed

    Tools → Upload Speed → 115200. This error often appears right after “Changing baud rate to 921600”.

  2. 2

    Use a shorter, better cable

    Long or thin cables and USB extension leads corrupt high-speed serial data.

  3. 3

    Disconnect anything on TX0/RX0

    GPS, Bluetooth or a second serial device on GPIO1/GPIO3 injects bytes into the conversation.

  4. 4

    Avoid hubs and front-panel ports

    Plug straight into the computer.

Why it happens

Why after the baud rate change?

esptool switches from 115200 to 921600 to speed up writing. Cheap USB-serial chips and long cables cannot hold that speed reliably, so the replies arrive corrupted.

Debug output on the same UART

If the sketch already running prints a lot on Serial at boot, its bytes can be mistaken for bootloader replies. Holding BOOT while uploading prevents the sketch from starting.

Brownout during the upload

A sagging supply can reset the chip mid-transfer. See brownout detector was triggered.

Board-specific notes

ESP8266 NodeMCU: The same error appears with esptool on ESP8266; 115200 baud and a good cable fix it in most cases.

↑↓ to move · Enter to open