writing and readting to/from Flash memory

aygh4266
Posts: 30
Joined: Mon Mar 04, 2024 10:33 am

writing and readting to/from Flash memory

Postby aygh4266 » Mon Feb 10, 2025 9:26 am

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.

MicroController
Posts: 2045
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: writing and readting to/from Flash memory

Postby MicroController » Mon Feb 10, 2025 11:49 am

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.

RathiSonika
Posts: 18
Joined: Thu Jun 22, 2023 2:58 pm

Re: writing and readting to/from Flash memory

Postby RathiSonika » 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!

aygh4266
Posts: 30
Joined: Mon Mar 04, 2024 10:33 am

Re: writing and readting to/from Flash memory

Postby aygh4266 » Mon Feb 10, 2025 12:15 pm

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

RathiSonika
Posts: 18
Joined: Thu Jun 22, 2023 2:58 pm

Re: writing and readting to/from Flash memory

Postby RathiSonika » 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!

aygh4266
Posts: 30
Joined: Mon Mar 04, 2024 10:33 am

Re: writing and readting to/from Flash memory

Postby aygh4266 » Wed Feb 12, 2025 10:30 am

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 ?

RathiSonika
Posts: 18
Joined: Thu Jun 22, 2023 2:58 pm

Re: writing and readting to/from Flash memory

Postby RathiSonika » Wed Feb 12, 2025 12:28 pm

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.

Who is online

Users browsing this forum: aygh4266 and 182 guests