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

Migrate from esptool, bossac or avrdude

nanoflash replaces the flashing tool of each family with one command and one manifest per project. This page maps the usual commands of esptool, bossac and avrdude to nanoflash.

From esptool

Write the offsets of the images in a board manifest once, or give each image a partition of a layout:

[[board]]
identifier = "my-board"
protocol = "espressif"
chip = "esp32-s3"

[[board.image]]
offset = 0x0
path = "build/bootloader/bootloader.bin"

[[board.image]]
offset = 0x8000
path = "build/partition_table/partition-table.bin"

[[board.image]]
offset = 0x10000
path = "build/hello_world.bin"

esptool 5 writes its commands with hyphens (write-flash), and esptool 4 with underscores (write_flash).

esptoolnanoflash
write-flash <offset> <file> ...nanoflash flash --board <manifest>
erase-flash before a writenanoflash flash --board <manifest> --erase-all
chip-id, flash-idnanoflash detect --port <port>
merge-binnanoflash image build --board <manifest> --output <file>
An esp-web-tools manifestUse it as it is: nanoflash flash --board manifest.json
--baud--baud-rate (USB-Serial-JTAG boards and the ESP32-C2 stay at 115200 baud, see Espressif)
--port--port, or nothing when only one port suits the board

These esptool commands have no equivalent: read-flash, verify-flash, read-mac, image-info and elf2image. nanoflash has no command that reads the flash. erase-region is an [[board.erase]] entry of the manifest.

With a layout, nanoflash also generates the partition table, so the manifest does not list it. Do not list the image of the partition table with a layout whose partitions grow with the flash.

nanoflash does not patch the bootloader header (flash size, mode, frequency) and does not initialise otadata. Build the bootloader with the right header, and list an image or an erase entry for otadata when you need it reset.

From bossac (Nano 33 BLE, SAMD21)

bossacnanoflash
bossac -d --port=<name> -U -i -e -w -v <bin> -Rnanoflash flash --board <manifest> --port <port> --json
bossac -U -R (leave the bootloader)nanoflash detect --port <bootloader port> --protocol samba
  • -i prints the device information: the output of flash and detect already names the chip and the flash.
  • -e sends X from the start of the application, which erases nothing on the bootloader of the Nano 33 BLE: the writes erase the pages. nanoflash flash does the same by default. --erase-all is the stricter equivalent: it clears the whole application area with 0xFF pages (slower), for when stale bytes after the image must go.
  • The touch, the wait for the bootloader and the reset happen inside flash. The port may be the port of the sketch or of the bootloader.
  • Exit code 2 replaces “No device found”, and exit code 3 a failed verification.

A manifest for a firmware with its own USB identity lists:

  • application-devices = [{ vendor = 0x1209, product = 0x0001 }] (its pid.codes identity, for a firmware that enters the bootloader on baud == 1200 && !dtr);
  • bootloader-devices = [{ vendor = 0x2341, product = 0x005a }];
  • an image at offset = 0x10000 of the .bin file, or the ELF file itself.

nanoflash layout write --format linker or the constants of the build feature give the same FLASH region as a hand-written memory.x.

A Cargo runner that calls objcopy and bossac

A firmware that Cargo flashes with a runner that calls objcopy and bossac can use nanoflash run instead. The runner takes the ELF file, so the conversion is not needed.

  1. Add a board manifest and a layout file (copy the ones of examples/nano33ble/board), and name the manifest in [package.metadata.nanoflash].

  2. List the USB identities of the board in application-devices and bootloader-devices. The touch at 1200 baud moves the board from the first to the second. An Arduino board with a 1200-baud touch shows the entries of the Nano 33 BLE. Add the identity of your firmware to application-devices when it has its own.

  3. Replace the runner in .cargo/config.toml with nanoflash run. When the serial port of the application speaks a binary protocol and not text, use nanoflash run --no-monitor, which only flashes.

From avrdude (Uno, Nano, Mega 2560, Leonardo)

avrdude -p<mcu> -c<protocol> -P<port> -b<speed> -D -Uflash:w:<file>.hex:i becomes:

$ nanoflash flash --board <manifest> --port <port> --json
  • -D (no chip erase) is the default behaviour: pages are erased as they are written.
  • The chip and the protocol come from the manifest. -b<speed> is --baud-rate. Without it, nanoflash tries the usual rates of the bootloader (see Supported boards). -carduino is protocol = "stk500v1" (or "arduino"), -cwiring is "stk500v2" (or "wiring"), and -cavr109 is "avr109".
  • The image is the same .hex file.
  • nanoflash reads back every page that it writes.