Error while uploading: esptool write_flash: error: argument <address> ... must be a number

Hi there,

I am new to PlatformIO. Came over from Arduino IDE. I forked a ESP32 project from github and now i am trying to upload it to my chip. But I get this error message which leaves me without a clue:

esptool write_flash: error: argument : Address “C:\Users\Clouseau.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\bin\bootloader_dio_40m.bin” must be a number

Here is the full terminal output when I try to upload:

Executing task: C:\Users\Clouseau\.platformio\penv\Scripts\platformio.exe run --target upload 

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Espressif 32 (4.3.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
 - framework-arduinoespressif32 @ 3.20003.0 (2.0.3)
 - tool-esptoolpy @ 1.30300.0 (3.3.0)
 - tool-mkfatfs @ 2.0.1
 - tool-mklittlefs @ 1.203.210628 (2.3)
 - tool-mkspiffs @ 2.230.0 (2.30)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 37 compatible libraries
Scanning dependencies...
Dependency Graph
|-- WiFiManager @ 2.0.16-rc.2+sha.5656e57
|-- ArduinoJson @ 6.21.3+sha.7517ecb
|-- PubSubClient @ 2.8.0+sha.2d228f2
|-- ESPHTTPUpdateServer @ 1.0.0+sha.42971eb
|-- FS @ 2.0.0
|-- LittleFS @ 2.0.0
|-- WiFi @ 2.0.0
|-- WiFiClientSecure @ 2.0.0
|-- WebServer @ 2.0.0
Building in release mode
Retrieving maximum program size build\esp32dev\firmware.elf
Checking size build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  12.0% (used 39468 bytes from 327680 bytes)
Flash: [=======   ]  71.2% (used 933037 bytes from 1310720 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa   
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: COM3
Uploading build\esp32dev\firmware.bin
usage: esptool write_flash [-h] [--erase-all]
                           [--flash_freq {keep,80m,60m,48m,40m,30m,26m,24m,20m,16m,15m,12m}]
                           [--flash_mode {keep,qio,qout,dio,dout}]
                           [--flash_size FLASH_SIZE]
                           [--spi-connection SPI_CONNECTION] [--no-progress]
                           [--verify] [--encrypt]
                           [--encrypt-files <address> <filename> [<address> <filename> ...]]
                           [--compress | --no-compress]
                           <address> <filename> [<address> <filename> ...]
esptool write_flash: error: argument <address> <filename>: Address "C:\Users\Clouseau\.platformio\packages\framework-arduinoespressif32\tools\sdk\esp32\bin\bootloader_dio_40m.bin" must be a number
*** [upload] Error 2
======================================================================== [FAILED] Took 9.73 seconds ========================================================================

Environment    Status    Duration
-------------  --------  ------------
esp32dev       FAILED    00:00:09.730

Seems like osme address in the string gets swallowed. Please post the link to the exact project that you’re trying to upload.

It is this project:

I tried to create my own fork here:

The is not safely written when any paths contain a space, because all the paths are unquoted.

Replace it with the following content


BOARD_CONFIG = env.BoardConfig()

def merge_bin(source, target, env):
    # The list contains all extra images (bootloader, partitions, eboot) and
    # the final application binary
    flash_images = env.Flatten(env.get("FLASH_EXTRA_IMAGES", [])) + ["$ESP32_APP_OFFSET", APP_BIN]

    # Run esptool to merge images into a single binary
        " ".join(
                '"%s"' % "$PYTHONEXE",
                BOARD_CONFIG.get("build.mcu", "esp32"),
                BOARD_CONFIG.get("upload.flash_size", "4MB"),
                '"%s"' % MERGED_BIN,
            + flash_images

# Add a post action that runs esptoolpy to merge available flash images
env.AddPostAction(APP_BIN , merge_bin)

# Patch the upload command to flash the merged binary at address 0x0
            '"%s"' % f
            for f in env.get("UPLOADERFLAGS")
            if f not in env.Flatten(env.get("FLASH_EXTRA_IMAGES"))
        + ["0x0", '"%s"' % MERGED_BIN],

I am sorry, but right now I have no clue what this is for and what this code does. So I just copy pasted your text over to as you suggested.
Now it shows me several problems:

  • “Import” is not defined
  • “env” is not defined

When I try to upload, I still get the same error.

The original author seems to have created this file to have a singular .bin file that can be flashed to the device instead of bootloader, partition table, firmware, nvs, etc. This file is actually optional and the error would likely also be fixed by not doing the merge and uploading the merged file, i.e., just commenting out the extra_scripts directives in the platformio.ini. But that doesn’t fix the bug at the source.

Intellisense errors in VSCode for the .py file are irrelevant because it does not know about SCons builtin functions.

Please show the logs for a verbose upload. project tasks → Advanced → Verbose upload.

Ah, I see. Yes the original author has a webpage from where you can flash his newest version. So this makes sense.

So, in the meantime I found that under Dependencies there is an option to “Update all”. In my case it updated quite a few things like espressif32 and esptoolpy. After that I was able to upload the sketch normally.

I will call this case solved.

@maxgerhardt: Many thanks for your help in this case!