0

I am trying to write firmware code for RFID device which will have config data storage as well as the temporary storage that maybe can be read and then if convenient be removed.

I am using Arduino IDE to program this on an ESP32 Wroom32. I have tried to understand how the storage actually works, finding various resources. One being datasheet of the same, that says that there could be 4 MB of program code storage possible, and that sounds fantastic, my question is if for example I take EEPROM library and save about 214 bytes to config which will rarely be touched, where is it exactly being stored? Is it simply in NVS? I can see that the default settings show me about 1310720 Bytes of storage and I know that I can utilise other partitions as well to store more in case I ever try to have more sketch storage than 1310720 Bytes.

My question is if I am trying to store data such as config and real time data, how much would I possibly be able to store? Is there a limit? Would it cause any kind of problems if I try to use the other such partitions to write the code? Will it be only NVS that is storing that data or can I utilise the other app0, app1, spiffs etc to store extra Bytes? A lot of the resources are confusing me, here are the data that I am referring to from online 1 and 2. Any idea would help me proceed very further.

P.S. I am aware that the EEPROM library has been deprecated and I shall use either Preferences or littlefs for better management but if I am aware correctly I can still utilise them, and without much issue that will work since there is still compatibility for that. I am also curious about using inbuilt SRAM of RTC with the RTC attribute RTC_DATA_ATTR, since I hope to also utilise deep sleep mode incorporated.

NaidarDevil
  • 23
  • 1
  • 6
  • Read the Espressif documentation on [partitions](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html#) and [NVS](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/storage/nvs_flash.html) to understand what's going on. Note that the beginner-oriented Arduino framework hides such details and makes decisions on your behalf. It's up to you to decide how to deal with it. – Tarmo Apr 15 '22 at 03:32
  • @Tarmo yeah, I saw the partition and decided to test the EEPROM by myself. It only stores values to the keys about 8191 Byte address and I guess to utilise the full 20 kB capacity I may need to use the Preferences library, although I am not sure how to check if I can store a value on a particular address like I could with EEPROM, I am going to look into that I guess. – NaidarDevil Apr 15 '22 at 13:22
  • That may come from the page size of the Flash chip. Talking directly to the low level may be educational, but it's certainly not productive. Use NVS if you want to get stuff done. – Tarmo Apr 16 '22 at 19:33

1 Answers1

0

My question is if I am trying to store data such as config and real time data, how much would I possibly be able to store? Is there a limit?

It depends. First on the module; there is ESP32-WROOM with 4MB flash but you could also order different flash sizes.

Then the question is: how big is your application (code)? Obviously this needs to be saved on the flash as well, reducing the total usable amount for data storage (by the size of the application). Also there is a bootloader which needs some small space as well.

Next, ESP32 is using a partition scheme. One partition is reserved for the bootloader. The rest can be divided between one or more application partitions, NVS partitions, and possibly other utility partitions (i.e. OTAData).

If you are using the OTA functions, there will be at least 3 application partitions of equal size, further reducing the total usable amount for data storage.

So the absolute upper limit of what you can store using NVS functions is the size of your NVS partition. However since it's a key-value storage, you must take into account the size of the key, which can be considerably larger than the data you store (up to 12 times for a 12 character key and a uint8 value).

So there is no way to say exactly how much data you can put into the system without knowing exactly how you're going to use it. For example, you could store one very large "blob" value that could take "up to 97.6%" of the partition size. But you could not store 10 "blob" values of 1/10 (9.76%) the size since you must take into account the keys and some flash metadata used internally.

Would it cause any kind of problems if I try to use the other such partitions to write the code? That depends on what these partitions are used for. If you override the partition table, or bootloader, or your application code, yes there will be problems. If there is "free space" then it won't be a problem, but then you should redefine this free space as NVS space. It's nice of Espressif to provide this NVS library, dont work around it, work with it.

Using Espressif's esptool you can create custom partition tables where you could minimize the size of the application partition to just barely fit your application, and maximize the NVS partition size. This way you will get the most storage out of your device without manually implementing a filesystem. If you are using OTA, you should leave some empty room in your application partition, in case your application code grows, as it usually does.

Will it be only NVS that is storing that data or can I utilise the other app0, app1, spiffs etc to store extra Bytes? You absolutely can, but you will destroy whatever data is on that partition. And you will have lots of work to do, because you'll have to implement all of this yourself (basically roll your own flash driver). If you don't need OTA, you dont need app0/app1 partitions at all.

Note that SPIFFS is also a way to store data, except it's not key-value but file-based. If you dont need it, remove that partition, and fill the space with your NVS partition.

On the other hand, SPIFFS is probably a better alternative if you are really tight on flash space, since you can omit the key and do your own referencing.

markus-nm
  • 805
  • 5
  • 8
  • So what you said about NVS partition, does that mean, if I were to write with EEPROM on NVS, I would also be storing the variables as well and not just the variable values? Or do you just mean that it will only store the value that is for example int something =4; which will store about 4 Bytes of something to EEPROM? Because that's totally ok, I am just trying to get the storage. – NaidarDevil Apr 14 '22 at 08:11
  • So, then if I code the sketch in Arduino, as it tells me the default maximum size is 1310720 Bytes, that's the sketch stored somewhere else in Flash and not NVS? Maybe App0 since it has the same storage size, and that means whatever values I am trying to store using EEPROM is stored in NVS? Because if that's the case, I don't have to worry about reducing the code way below 1310720. It will be a moment of hurrah. – NaidarDevil Apr 14 '22 at 08:15
  • Yeah, you are right about creating custom partitions with esptool as I had seen quite many users trying that to manipulate the partitions, but a great number of what I had seen were having great troubles and had been posted in the forums like you said might have created difficulties. – NaidarDevil Apr 14 '22 at 08:18