How to upload esp8266 sketch with configuration of Erase flash

Close, but also not even close… :confounded: those are just the entries which add the menu option for erase…

You do want these lines…

but more specifically you want what’s after the upload.erase_cmd for the specific one you want… either sketch only (so no erase), Sketch + WiFi Settings (erase region rfcal), or erase all (erase flash).

Once you know that, you want to somehow add that to the upload command… there are two possible ways, not sure which one will actually work.

The easier option (if it works) is upload_flags = erase_region "{build.rfcal_addr}" 0x4000 or upload_flags = erase_flash as needed. However, since anything specified after upload_flags will be added to the end of uploader command, I’m concerned it may not work. So, Plan B is to use an extra_script based on the custom upload tool example to edit the upload command…

Import("env")

ERASE_CMD="erase_flash"
;ERASE_CMD="erase_region "{build.rfcal_addr}" 0x4000"

upload_protocol = env.subst("$UPLOAD_PROTOCOL")

if upload_protocol == "espota":
    env.Replace(UPLOADCMD="$UPLOADER $UPLOADERFLAGS $ERASE_CMD $SOURCE")
elif upload_protocol == "esptool":
    env.Replace(UPLOADCMD='"$PYTHONEXE" "$UPLOADER" $UPLOADERFLAGS $ERASE_CMD $SOURCE')

… not forgetting to also add the following to your platformio.ini

`extra_scripts = extra_script.py

… assuming you called it extra_script.py, and that it’s located in the root folder of your project, i.e. next to the platformio.ini.

Note, I don’t have time to test this atm, so it may break… but it should get you started.

I don’t see why this can’t be added as a standard platformio.ini parameter in the future… who wants to volunteer to add it? :laughing: (thinking since he said it he’ll probably do it…)

1 Like