Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Flash ESP32 and Arduino boards from Rust and the browser

nanoflash is a Rust toolkit that lays out flash and writes firmware to ESP32 and Arduino boards, from the command line, as a Cargo runner and in the browser. One API serves the boards of several vendors. In the browser, it uses Web Serial. One layout file describes the partitions of a board, one manifest describes what to write, and nanoflash checks every image before it erases a byte.

It flashes the ESP32 family (ESP32, ESP32-S2, ESP32-S3, ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-H2, ESP32-P4) through the Espressif ROM loader, the Arduino Nano 33 BLE and the Arduino SAMD21 boards through SAM-BA, and Arduino’s AVR boards (Uno, Nano, Pro Mini, Mega 2560, Leonardo, Micro, Pro Micro) through their STK500v1, STK500v2 and AVR109 bootloaders.

What it does

  • Lays out the flash. A TOML layout file gives the flash size and named partitions with a role. nanoflash computes the offsets, checks alignment, overlap and size, reports the headroom of every partition, and writes the table that each family needs: the Espressif partition table, an MBR, linker regions or Rust constants. Partitions can grow with the flash that the chip reports.
  • Flashes boards. One board manifest gives the protocol, chip, layout, images, reset sequence and optional SHA-256 digests. Existing esp-web-tools manifests work unchanged. Images can be binary, Intel HEX or ELF files. Nothing is erased before every input is checked.
  • Fits the Rust workflow. nanoflash run is a Cargo runner, so cargo run builds, flashes and opens the serial monitor. cargo nanoflash runs every command as a Cargo subcommand. The build feature gives the build.rs of a firmware its layout constants and a whole memory.x.
  • Monitors the board. nanoflash monitor shows the serial output, sends what you type, follows the board through resets, and decodes defmt frames.
  • Runs in the browser. The npm package and the <nanoflash-button> web component use the same Rust code, compiled to WebAssembly, over Web Serial. The flasher page flashes a board from a manifest URL or from files on your computer, with nothing to install.
  • Works in CI. No prompts, --json output, clear exit codes.

Who it is for

  • Firmware developers who flash ESP32 and Arduino boards and want one tool instead of esptool, bossac and avrdude.
  • Rust embedded developers who want cargo run to flash and monitor, and a layout file as the one source of truth for the partitions and the linker regions.
  • Projects that ship firmware to users and want a web flasher, or a flash button on their own page.

What it does not do

  • It does not build firmware, sign it or provision secure boot. Verification of signatures is a hook of the caller.
  • It is not a debugger. Debug probes (CMSIS-DAP) come later.
  • It does not flash from Firefox or Safari, which do not implement Web Serial. Use the command there.
  • It does not patch the Espressif bootloader header or initialise otadata.

How this guide is organized

It has four parts, one per need:

Status

Layout checks, the table writers and flashing work natively and in the browser. They are tested against recorded transcripts, Espressif’s QEMU (ESP32 and ESP32-C3), arduino/BOSSA’s emulated SAM-BA bootloader and the Arduino STK500 bootloaders emulated by simavr. The release workflow attaches the binaries of the command to its GitHub releases. The crates nanoflash and nanoflash-cli are on crates.io, and the browser package nanoflash is on npm. USB DFU, UF2, CMSIS-DAP and Nordic serial DFU come next.

nanoflash is free software under the MIT or Apache-2.0 licence, at your option. The source, issues and releases are on GitHub.