Back to resources
Chip programming
Firmware
HIL

Flashing an ESP32 over its ROM bootloader with a BenchPod

How the BenchPod writes an ESP32-WROOM-32 through the chip's built-in serial bootloader, over its UART pins or over USB through a dev kit's USB-serial chip, with no esptool and no stub on the host: the protocol, the wiring, and bench results.

Edward Viaene · November 16, 2026 · 9 min read

The ESP32-WROOM-32 is a module built around the original ESP32: a dual-core chip with Wi-Fi and Bluetooth and, in the module, external SPI flash (4 MB on the one we used). Its firmware gets in through the chip's ROM serial bootloader, a loader burned into the chip that listens on UART0 when the boot strap pin IO0 is low at reset. esptool talks to it from a computer, usually through the USB-serial chip of a dev kit.

A BenchPod can do the same job without a computer in the loop. The pod speaks the ROM loader's protocol itself, either on two of its logic analyzer pins wired to the chip's UART0, or over USB through a dev kit's USB-serial chip. This article is part of a series, one per chip we have run on real hardware: the overview of how the BenchPod flashes microcontrollers lists them all. It covers the protocol, both wiring options and what we measured.

The ROM loader protocol

The ROM loader is a request and reply protocol over UART. Every packet is wrapped in SLIP framing: it starts and ends with 0xC0, and a 0xC0 or 0xDB inside the packet is escaped as 0xDB 0xDC or 0xDB 0xDD. A request carries a direction byte, an opcode, a length, a checksum field and its data; the chip's reply echoes the opcode and ends with a status.

CommandOpcodeWhat the pod uses it for
SYNC0x08Wake the loader; the chip answers once it is listening
CHANGE_BAUDRATE0x0FLeave the 115200 start rate for a faster one
SPI_ATTACH0x0DConnect the loader to the SPI flash
SPI_SET_PARAMS0x0BTell it the flash size, block, sector and page sizes
FLASH_BEGIN0x02Erase the region and announce the block count and size
FLASH_DATA0x03One block of the image, with its sequence number and checksum
SPI_FLASH_MD50x13Ask the chip for the MD5 of what it wrote
FLASH_END0x04Finish, staying in the loader; the pod then pulses EN to boot the new image

Two details trip up first implementations. FLASH_BEGIN takes four words on the original ESP32 (erase size, block count, block size, offset); the later ESP32 family members take a fifth. And the checksum of a FLASH_DATA packet is an XOR of the block's bytes seeded with 0xEF, and it covers only the data, not the header.

The write sequence between the pod and the ESP32 ROM loader, from the reset into the loader to the MD5 check and FLASH_END
The write sequence between the pod and the ESP32 ROM loader, from the reset into the loader to the MD5 check and FLASH_END

The sequence the pod runs:

  1. Enter the loader. IO0 low, EN low for 100 ms, EN released, then 50 ms for the ROM to sample the strap.
  2. SYNC at 115200 baud, retried until the chip answers. Once it does, the pod releases IO0.
  3. CHANGE_BAUDRATE to the write rate (460800 by default; the pod accepts 9600 to 2000000).
  4. SPI_ATTACH and SPI_SET_PARAMS with the flash size.
  5. FLASH_BEGIN. The ROM erases the region, which takes seconds for a large image.
  6. FLASH_DATA in 1 KB blocks. A block that is not acknowledged is sent again, and the pod counts the resends.
  7. SPI_FLASH_MD5 asks the chip for the MD5 of the region. The result is ok only when it matches the MD5 of what the pod sent.
  8. FLASH_END. With run on (the default) the pod pulses EN with IO0 released, and the chip boots the new image.

No stub is uploaded to the chip: the pod uses the loader that is already in ROM, so nothing about the flash depends on a helper program running on the target.

How the pod runs it

Who does what: the host stages the image, the pod's MCU runs the ROM loader job, and the UART pins or the USB host port reach the chip
Who does what: the host stages the image, the pod's MCU runs the ROM loader job, and the UART pins or the USB host port reach the chip
  • The host (the Python SDK, the CLI or the MCP server) reads a .bin or an ESP-IDF flasher_args.json, and stages each region in the pod's memory. It then starts one job per region and polls its progress. No esptool and no stub run on the host.
  • The pod's MCU runs the ROM loader protocol above as a background state machine, so the job takes the same time over the LAN, USB or the cloud. status reports the phase, the 1 KB blocks done out of the total, the chip, the resends and the MD5.
  • The FPGA provides the serial port on two LA pins for the UART method. The boot strap is driven open-drain on a third LA pin, and EN goes on the pod's own reset pin.
  • The USB host port is the other way in. The pod is the USB host and the dev kit's USB-serial chip shows up as a serial port; the pod toggles DTR and RTS, which the dev kit's auto-reset circuit turns into IO0 and EN, and then runs the same job.

Region writes are independent: write a bootloader, a partition table and an application with one job each, with run only on the last.

Method 1: the chip's UART pins

This is the method that needs no USB cable to the target. The chip's UART0 pins, its boot strap and EN go to the pod.

PodESP32-WROOM-32Signal
LA1TX0chip transmits, pod receives
LA2RX0chip receives, pod transmits
reset pinENreset
5 V outputVINsupply
GNDGNDground
an LA pin (or hold BOOT by hand)IO0boot strap, driven open-drain
Wiring an ESP32-WROOM-32 to the pod: TX0 to LA1, RX0 to LA2, EN to the reset pin, VIN to the 5 V output, GND, and IO0 to an LA pin
Wiring an ESP32-WROOM-32 to the pod: TX0 to LA1, RX0 to LA2, EN to the reset pin, VIN to the 5 V output, GND, and IO0 to an LA pin

The firmware's esp_flash command works on the original ESP32 and on the S2, S3, C2, C3, C6 and H2; the ESP8266 is refused. The boot pin is IO0 on the ESP32, S2 and S3, and IO9 on the C2, C3, C6 and H2. While a job runs the pod also holds the receive pin high with its pull-up where the channel has one, and it releases every pin at the end whatever the result.

In the bench run below, IO0 (the BOOT button) was held by hand. Driving IO0 from an LA pin is how the command is designed to work; that part was not in the run.

Method 2: over USB through a dev kit

Many ESP32 dev kits put a USB-serial chip (CH340, CP210x or FTDI) between the USB connector and the chip's UART0, with a small transistor circuit that turns DTR and RTS into IO0 and EN. esptool uses exactly that to reset the chip into its loader.

The pod can do this as a USB host. With USB host mode on, the dev kit plugs into the pod's USB host port, and the pod opens its serial port, toggles DTR and RTS the way esptool does, and runs the same ROM loader job. The pod supports the vendor chips (CP210x, CH34x, FTDI) and the chip's own USB serial port on the ESP32-C3, C6, S3 and H2; the CH340 dev kit below is the one we ran on real hardware.

The pod needs nothing wired except the dev kit's USB cable to the pod's USB host port: no LA pins, no reset line.

Bench results

UART pins. An ESP32-WROOM-32 (4 MB flash) with the Espressif AT firmware in its application slot, wired as in the table with TX0 on LA1, RX0 on LA2, EN on the pod's reset pin and VIN on the pod's 5 V output:

CallRateRegionTimeResends
SDK11520032 KB at 0x3F0000, MD5 verified3.7 s0
SDK46080032 KB at 0x3F0000, MD5 verified1.4 s0
CLI46080032 KB at 0x3F0000, MD5 verified1.9 s0

The AT firmware still booted afterwards: 0x3F0000 is in the last 64 KB of the 4 MB flash, away from the application.

USB. An ESP32 dev kit with a CH340 USB-serial chip on the pod's USB host port took a 1 MB write in 36 s at 460800 baud, and a separate 256 KB write was MD5 verified.

Things to know

  • Switch both sides after CHANGE_BAUDRATE. The chip acknowledges the command at the old rate and then switches. The host must switch its own serial port to the new rate right after that acknowledgment, or the two sides talk at different speeds.
  • Native USB and vendor chips differ. A chip's own USB serial port (CDC ACM) moves data at USB speed, so there is no baud rate to change. A vendor USB-serial chip (CH34x, CP210x, FTDI) carries the data at the UART baud rate, so the pod uses 460800 for the write there. It tells them apart by the interface subclass.
  • The erase takes time. FLASH_BEGIN is acknowledged only after the ROM has erased the region, which takes seconds for a large image.
  • The strap is sampled at reset. IO0 must be low when EN rises, and released afterwards, or the chip boots the application instead of the loader.

Using it

From Python, with the pytest package, over the chip's UART pins:

from embeddedci.benchpod import BenchPod

with BenchPod("192.168.1.50", la_voltage=3.3) as bp:
    # rx is the LA pin on the chip's TX0, tx on its RX0, boot on IO0 (required; if IO0 is not wired, hold BOOT by hand).
    r = bp.flash(target="esp32", file="build/flasher_args.json",
                 rx=1, tx=2, boot=3, nreset=True)
    assert r.ok, r.stderr

file is either a .bin (written at load_address, default 0, for example a merged image) or an ESP-IDF flasher_args.json, which writes every region at its own offset. Without rx, tx and boot the SDK takes them from the pod's wiring profile (uart_rx, uart_tx, and a signal named BOOT, IO0 or IO9).

Over USB:

with BenchPod("192.168.1.50") as bp:
    r = bp.usb_flash("build/merged.bin", address=0)
    assert r.ok

The SDK chooses esp from the file (an ESP image starts with 0xE9) and the device that mounted, starts USB host mode if it is off, and waits for the device.

From the command line:

benchpod flash --target esp32 --file flasher_args.json --rx 1 --tx 2 --boot 3 --nreset
benchpod usb-flash merged.bin

From an AI agent, the MCP server has the same two calls: flash(target="esp32", file=..., rx=..., tx=..., boot=...) and usb_flash(file=..., address=...).

Underneath all of these is one JSON command per region. Stage the image with load_bin into the pod's memory, then:

{"cmd":"esp_flash","op":"start","rx":1,"tx":2,"boot":3,"en":"nrst","offset":4128768,"len":32768,
 "baud":460800,"flash_size":4194304,"run":true}
{"cmd":"esp_flash","op":"status"}
{"cmd":"usb_flash","mode":"esp","address":0,"len":1048576}

"op":"sync" enters the loader and reads the chip without touching the flash, which is a good wiring check. The status reply gives the phase, blocks done, the chip, resends, the MD5 and a result: ok when the chip's MD5 matched, unverified when every block was acknowledged but no MD5 came back, or the failure in words (no answer from the ROM loader means wiring, straps, or an unpowered target).

UART flashing needs firmware 3.10.7 or later; flashing over USB needs 4.0.3 or later. Both need a direct network, USB or cloud connection to the pod, because the image is staged in the pod's memory first; the CLI's flash needs the pod's network address or usb, and usb-flash needs its network address. The full reference is on the ESP32 chips page, the USB page and in the API docs. Every chip and method we have verified on real hardware is in How the BenchPod flashes microcontrollers.