Esp32 jlink, delete flash upon upload

Using jlink to upload to my esp32 (upload_protocol = jlink), searching for a solution to delete flash upon uploading.

Using verbose upload I can see that the command being run is:

CURRENT: upload_protocol = jlink
openocd -d2 -s C:/Users//.platformio/packages/tool-openocd-esp32/share/openocd/scripts -f interface/jlink.cfg -f board/esp-wroom-32.cfg -c “adapter_khz 10000” -c “program_esp {{.pio\build\development\firmware.bin}} 0x10000 verify” -c "program_esp {{C:**.pio\build\development/bootloader.bin}} 0x1000 verify" -c "program_esp {{C:*.pio\build\development/partitions.bin}} 0x8000 verify" -c “reset run; shutdown”

I tried to play with upload_flags but no luck yet. Any help would be appreciated…


PlatformIO has a built-in project task “erase” for that, as documented.


The code however only works with and thus with a serial conenction. If that is not available, there’s a problem. File an issue in the platform if you want it added via JTAG uploaders as well…

You can also use this command and add it as a custom target via scripting. A more sophisticated example of that is here.

However, when uploading, the previous flash contents for a given section are erased automatically, so this shouldn’t have to be done manually.

Thank you,
I filed an issue for now since I can’t spare the time to learn openOCD and write the necessary script to use it.
If anybody previously solved this issue and can share, I will be thankful.