Page 1 of 1

writing and readting to/from Flash memory

Posted: Mon Feb 10, 2025 9:26 am
by aygh4266
Hello everyone,

I am planning to implement a function to read from and write to the flash.

While searching through the ESP documentation, I found direct APIs such as esp_flash_write and esp_flash_read.

I am not sure if these APIs support wear leveling. Any feedback would be appreciated.

P.S. I have found other APIs that support wear leveling, but I would like to know if these APIs also support it.

Re: writing and readting to/from Flash memory

Posted: Mon Feb 10, 2025 11:49 am
by MicroController
aygh4266 wrote:
Mon Feb 10, 2025 9:26 am
I have found other APIs that support wear leveling, but I would like to know if these APIs also support it.
What do you mean?
The wear-levelling API does flash wear-levelling. If you want this, use the API.

Re: writing and readting to/from Flash memory

Posted: Mon Feb 10, 2025 12:03 pm
by RathiSonika
ESP's esp_flash_write and esp_flash_read APIs provide direct access to flash memory but do not inherently handle wear leveling. To enable wear leveling, you can use LittleFS or FatFS with the wear-leveling enabled on top of the flash storage. Hope this helps!

Re: writing and readting to/from Flash memory

Posted: Mon Feb 10, 2025 12:15 pm
by aygh4266
RathiSonika wrote:
Mon Feb 10, 2025 12:03 pm
ESP's esp_flash_write and esp_flash_read APIs provide direct access to flash memory but do not inherently handle wear leveling. To enable wear leveling, you can use LittleFS or FatFS with the wear-leveling enabled on top of the flash storage. Hope this helps!
Thank you ! That helped a lot. Any recommendation to store data from a ringbuffer to the flash. New data should overwrite the existed data considering wear leveling ? I don't need a filesystem, I would like to store the data without a filesystem

Re: writing and readting to/from Flash memory

Posted: Mon Feb 10, 2025 12:56 pm
by RathiSonika
Please refer to the Wear Leveling APIs here https://docs.espressif.com/projects/esp ... lling.html. You can try these steps: load the partition using esp_partition_find_first(), mount Wear Leveling using wl_mount(), and then use wl_write() and wl_read() to write and read from flash memory (refer to the documentation for details). This should solve your problem. Let me know if you face any issues!

Re: writing and readting to/from Flash memory

Posted: Wed Feb 12, 2025 10:30 am
by aygh4266
RathiSonika wrote:
Mon Feb 10, 2025 12:56 pm
Please refer to the Wear Leveling APIs here https://docs.espressif.com/projects/esp ... lling.html. You can try these steps: load the partition using esp_partition_find_first(), mount Wear Leveling using wl_mount(), and then use wl_write() and wl_read() to write and read from flash memory (refer to the documentation for details). This should solve your problem. Let me know if you face any issues!
erasing flash for every new writing seems to me not the best solution. How about nvs ? I have read that nvs supports wear leveling automatically. Can I use a BLOB to store big data i.e. data from a ringbuffer ? About 1024 bytes ?

Re: writing and readting to/from Flash memory

Posted: Wed Feb 12, 2025 12:28 pm
by RathiSonika
Yes, NVS supports wear leveling. NVS is useful for applications that manage multiple key-value pairs, such as system configuration. You can refer to this https://docs.espressif.com/projects/esp ... vs-library for more details on NVS.