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

ldudel
Posts: 9
Joined: Thu Jun 24, 2021 11:23 pm

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

Postby ldudel » Sun Nov 14, 2021 6:20 pm

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!

ESP_Sprite
Posts: 9759
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Mon Nov 15, 2021 1:16 am

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.

ldudel
Posts: 9
Joined: Thu Jun 24, 2021 11:23 pm

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

Postby ldudel » Mon Nov 15, 2021 6:04 am

Thanks for your answer! Are you sure that nvs_set_blob uses wear leveling? It is really hard to tell from the documentation.

ESP_Sprite
Posts: 9759
Joined: Thu Nov 26, 2015 4:08 am

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

Postby ESP_Sprite » Tue Nov 16, 2021 9:51 am

Yes, all NVS functions use wear levelling.

Who is online

Users browsing this forum: No registered users and 107 guests