Page 1 of 1

power down during erase

Posted: Wed Jun 20, 2018 12:49 pm
by maxzen
we are using a esp32-wrover, our device can be disconnected at any time, what happens if the power is lost during erase?

As an example, some code is writing to nvs and, while the system is erasing a block to make room, the user disconnect the device from the power.

For sure some data will be lost, but is this the only effect or the flash (and the device) will be damaged?

Re: power down during erase

Posted: Thu Jun 21, 2018 5:31 am
by ESP_Angus
The flash won't be damaged, but the contents of the sector being erased will be undefined (probably partially erased). The same goes for power failure during a write operation (although usually in this case some of the first bytes in the sequence will be written correctly, and the bytes after that will still be unwritten - usually 0xFF).

The NVS library is specifically designed to be failsafe under these circumstances, ie either the old or the new version of the NVS contents will be returned.