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.