ESP32 - how to DISABLE "all flash erase" during upload

Hi, how I can control the flash erase behaviour when uploading.
In Arduino IDE I have an option to not erase all flash data as I have store some settings in the the NVM
Thanks for advice

Flash must be erased before writing. There is no way to avoid this.
But the NVS partition ist not erased when a new sketch is uploaded!

Here is an example using the default partition layout (default.csv):

In the default partition layout the NVS partition starts address 0x9000 with a size of 0x5000 (ends at 0xDFFF).

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x140000,
app1,     app,  ota_1,   0x150000,0x140000,
spiffs,   data, spiffs,  0x290000,0x160000,
coredump, data, coredump,0x3F0000,0x10000,

While the sketch is uploaded, you’ll noticed that 0x9000 - 0xDFFF is not erased:

Flash will be erased from 0x00001000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000e000 to 0x0000ffff...
Flash will be erased from 0x00010000 to 0x000f2fff...

So your NVS settings are not erased while uploading a new sketch.

1 Like

comming back to that topic. It seems after flashing the code my filesystem has been deleted. So there must be an option to prevent that ?

What applies to the NVS partition also applies to other data partitions.

Take another look at the example from above:
The SPIFFS partition is in the range 0x290000 to 0x3EFFFF.
This area is not deleted or rewritten during the upload of a new sketch.

The cause of your problem must therefore lie elsewhere.
One possible cause would be the modification or selection of a different partition table. This would invalidate an existing data partition after uploading a new sketch.

Please show the content of your platformio.ini and provide the smallest possible example to reproduce the ‘error’.

Thanks, I will do that later.
Background: I ported my program from Arduino IDE to PlatformIO IDE and just realized that after upload the program the first time the file system was just deleted

Then I suspect that the partition selected in the ArduinoIDE differs from the one in your PlatformIO project. This would change the partitioning and invalidate the data partition. (Just a guess).

What happens if you upload a new sketch a second, third or fourth time? Will the data partition be deleted again? (I assume: No)

platformio.ini looks like following:

platform = espressif32
board = heltec_wifi_kit_32_V3
framework = arduino
upload_port = COM[3]
monitor_speed = 115200

and yes after several uploads its not deleted anymore

what I observed as a side effect ( may be that is also a reason) in my Arduiono IDE I use ESP32 framework 2.0.14 and in platformIO its just 2.0.9. This brought up another error in wificlient … How can I change to 2.0.14 ( or any later one) to be compatible to Arduino IDE ?

flash erase space is slighly different:
Configuring flash size…

Flash will be erased from 0x00000000 to 0x00003fff…
Flash will be erased from 0x00008000 to 0x00008fff…
Flash will be erased from 0x0000e000 to 0x0000ffff…
Flash will be erased from 0x00010000 to 0x00193fff…

Then your installed Espressif32 is outdated.
Arduino 2.0.14 is available in Espressif32 Version 6.6.0

Simply change
platform = espressf32
platform = espressif32@^6.6.0

Meanwhile Espressif32 version 6.7.0 has been released.
This supports Arduino 2.0.16

1 Like

perfect thanks- its working as expected;-)