chrispitzer
chrispitzer

Reputation: 1069

in ESP32 / ESP-IDF - when to use EEPROM vs NVS vs SPIFFS?

I'm fairly new to doing production work on ESP32 microcontrollers, and I'm wanting a little context and nuance from people who've been around the block a few times. So this question is a bit more on that kind of thing rather than a "how do I code X" kind of question.

I have lots of data storage needs on my current project.

I'm familiar with storing data in "blobs", and I'm familiar with encoding / decoding data with protocol buffers.

So given all that, I'm trying to gain context on the differences between my various storage options on the ESP32, and when to use each.

What use cases make you pick one of these options over another?

Upvotes: 8

Views: 8111

Answers (1)

Tarmo
Tarmo

Reputation: 4770

There's no EEPROM on the ESP32, just the flash.

NVS is not a file system, but a simple non-volatile key-value store with different data types (integers 8-64 bits, strings, blobs). It's reasonably convenient to use, does wear levelling and supports flash encryption. I'd use it for storing factory settings and anything else which is reasonably small (there's a 4000 byte limit on strings, 508,000 byte limit on blobs). If the device needs to write often, you might want to create a separate, dedicated, read-only NVS partition for storing device attributes (serial, hw info, certs) so it's guaranteed to not get clobbered by power failures during write.

ESP IDF natively supports SPIFFS, LittleFS and FAT file systems.

SPIFFS is very light-weight and comes with reasonable wear levelling and reliability. I'd use this for storing a small amount of larger files. It doesn't support flash encryption, unfortunately. SPIFFS also doesn't have directories, and it's not very fast for some operations.

LittleFS is a slightly more advanced embedded file system. I haven't used it personally, but I hear good things about it. I don't know if it supports flash encryption.

FAT file system is probably the worst choice because it's not really natively Flash-friendly, nor reliable. Espressif has built some kind of a layer between FAT and flash to accommodate wear levelling. The only critical advantage of FAT is that it supports flash encryption.

As always, consider the number of page erases your writes are going to cause in the flash - this gives you an estimate of how many times you can write before the chip's lifetime is reached.

Upvotes: 18

Related Questions