Page 1 of 1

Loading and saving structs to flash every reboot - use nvs, wl, or fat API?

Posted: Sun Nov 14, 2021 6:20 pm
by ldudel
I'm loading and saving two structs from/to flash each boot. This will quickly add up to > 10k saves, so I need to implement some kind of wear management. I'm not sure what the best option is. I don't want to add extra power-consuming overhead, so I'm leaning toward lower-level operations. But I'm not sure what's supported by which library.

Option 1: Use nvs_set_blob, but change the key every 10k saves. Is this even guaranteed to move the write to a new sector?

Option 2: Use wl_mount, wl_write. Seems straightforward, but I'm lacking examples. Are there any examples out there of using this technique? I'm not sure how the partitions work, and how to ensure the wl is actually working.

Option 3: Use FATfs. This seems to be a lot of overhead, and I'd have to transfer from file to struct and back. I'd rather just write the struct bytes. But maybe this is the only option?

Questions: which options can be made to work? Are there any examples out there of using option #1 or #2?

Thanks in advance for any and all help!

Re: Loading and saving structs to flash every reboot - use nvs, wl, or fat API?

Posted: Mon Nov 15, 2021 1:16 am
by ESP_Sprite
I'd simply chuck it into NVS. No need to change the key, the wear-leveling algorithm works regardless of what key(s) are being written.

Re: Loading and saving structs to flash every reboot - use nvs, wl, or fat API?

Posted: Mon Nov 15, 2021 6:04 am
by ldudel
Thanks for your answer! Are you sure that nvs_set_blob uses wear leveling? It is really hard to tell from the documentation.

Re: Loading and saving structs to flash every reboot - use nvs, wl, or fat API?

Posted: Tue Nov 16, 2021 9:51 am
by ESP_Sprite
Yes, all NVS functions use wear levelling.