Clarification on Wear Leveling Performance and Safety modes

maldus
Posts: 83
Joined: Wed Jun 06, 2018 1:41 pm

Clarification on Wear Leveling Performance and Safety modes

Postby maldus » Wed Dec 04, 2019 11:21 am

Hello everyone,
I am trying to understand all the nuances of the FatFS and Wear Leveling components of the library. To quote the documentation (https://docs.espressif.com/projects/esp ... lling.html):
The wear levelling component, together with the FAT FS component, uses FAT FS sectors of 4096 bytes, which is a standard size for flash memory. With this size, the component shows the best performance but needs additional memory in RAM.

To save internal memory, the component has two additional modes which both use sectors of 512 bytes:
  • Performance mode. Erase sector operation data is stored in RAM, the sector is erased, and then data is copied back to flash memory. However, if a device is powered off for any reason, all 4096 bytes of data is lost.
  • Safety mode. The data is first saved to flash memory, and after the sector is erased, the data is saved back. If a device is powered off, the data can be recovered as soon as the device boots up.
I have a couple of doubts about this paragraph:
  • When using a sector size of 512B there are two different modes, performance and safety; what is the case when using 4096B? Do I get the best performance AND safety? What happens if a poweroff occurs during the write operation?
  • In safety mode the data is written in flash before erasing the sector, so "the data can be recovered as soon as the device boots up" in case of interruption. Is this recovery automatic or should I implement it? If so, how?
I couldn't find any further information on the documentation or the examples. Can anyone help me?

maldus
Posts: 83
Joined: Wed Jun 06, 2018 1:41 pm

Re: Clarification on Wear Leveling Performance and Safety modes

Postby maldus » Thu Dec 05, 2019 8:24 pm

I have made some tests and can confirm that a file ends up corrupted if a write operation is interrupted by a reset. This happens regardless of the safety/performance or sector size configuration. Is there a way to notice this and somehow recover?

maldus
Posts: 83
Joined: Wed Jun 06, 2018 1:41 pm

Re: Clarification on Wear Leveling Performance and Safety modes

Postby maldus » Mon Dec 09, 2019 7:54 am

I really hate to be insistent but I also feel like the documentation is somewhat lacking here. Understanding what happens in the event of an unforeseen poweroff is paramount for me and I'd like to know if and how the data is recoverable.

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 278 guests