I am using SPIFFS on ESP32-S3 with a 27 MB(Total flash size 32 MB) partition for sensor data logging.
Implementation:
* Sensor data recorded every 2 seconds
* Buffered in RAM
* Buffer flushed to CSV file every 50 seconds
* One file per day
* Oldest file deleted after 30 days
* Using normal fopen/fwrite/fclose operations
Issue:
* First ~10 days of files are correct
* After that, newer files start getting corrupted
* Some files contain random/sketch data
* Some files are much smaller than expected (100 KB instead of ~700 KB)
* Missing records also observed
Has anyone faced similar SPIFFS issues with long-term logging or continuous append operations? Any suggestions or better approach for reliable 30-day logging on ESP32?
ESP32-S3 SPIFFS file corruption after ~10(8 MB) days of continuous logging
-
RathiSonika
- Espressif staff

- Posts: 27
- Joined: Thu Jun 22, 2023 2:58 pm
Re: ESP32-S3 SPIFFS file corruption after ~10(8 MB) days of continuous logging
According to the ESP32-S3 SPIFFS documentation https://docs.espressif.com/projects/esp ... filesystem, SPIFFS can reliably use about 75% of the allocated partition size. Since you are only using ~8 MB of a 27 MB partition (~30%), this does not look like a storage capacity issue.
To narrow down the corruption problem, does it occur consistently after a similar number of files or days (for example, after ~10 daily files)?
I would recommend checking the following:
* Log fwrite(), ferror(), fflush(), fsync(), and fclose() return values.
* Monitor free space using esp_spiffs_info().
* Check reset/power stability during writes (esp_reset_reason()).
* After corruption, run esp_spiffs_check() and log the result.
* Power loss during filesystem operations can cause the corruption. So verify the power stability and reset behavior during filesystem operations
For this application, LittleFS may be a better fit because it generally handles power-loss scenarios more robustly. You can check this document for file system consideration - https://docs.espressif.com/projects/esp ... iderations
To narrow down the corruption problem, does it occur consistently after a similar number of files or days (for example, after ~10 daily files)?
I would recommend checking the following:
* Log fwrite(), ferror(), fflush(), fsync(), and fclose() return values.
* Monitor free space using esp_spiffs_info().
* Check reset/power stability during writes (esp_reset_reason()).
* After corruption, run esp_spiffs_check() and log the result.
* Power loss during filesystem operations can cause the corruption. So verify the power stability and reset behavior during filesystem operations
For this application, LittleFS may be a better fit because it generally handles power-loss scenarios more robustly. You can check this document for file system consideration - https://docs.espressif.com/projects/esp ... iderations
Who is online
Users browsing this forum: No registered users and 10 guests