ESP32 broken filesystem

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Posts: 3
Joined: Tue Oct 24, 2017 10:38 am

ESP32 broken filesystem

Post by krono » Fri Dec 14, 2018 2:54 pm


i have an esp32 that is plugged into a device from wich he get current and comunicate with it with serial interface.
My problem is that when the device lose current and then the esp32 turn on again, sometimes, the filesystem become corrupted.
In production this scenario makes it unusable for the user and does not allow to restore the application.

Is there a way to creare a separate partition to restore from it the entire flash memory?

Thanks in advance for the help.

Posts: 35
Joined: Mon Jul 25, 2016 11:31 am

Re: ESP32 broken filesystem

Post by fdufnews » Fri Dec 14, 2018 7:41 pm

Usually, this kind of problem arises when the file is open at the time of the power outage.
Sofware solution
So you can close the file every time you end writing a file. This will limit the risk of filesystem corruption. But don't suppress them of course.

Hardware solution
You can put a supercap between the power supply and your ESP32. And detect when the power supply is down so that you have time to cleanly halt the software. You shall put a diode between the power supply and supercap so that the supercap won't discharge into the power supply

Posts: 794
Joined: Mon Nov 20, 2017 10:18 am

Re: ESP32 broken filesystem

Post by OutoftheBOTS_ » Fri Dec 14, 2018 8:08 pm

Lots opf ESP32 devices have problems with rebooting due to dips in current. This is caused by the 2.4GHz radio. On the datasheet it shows that recommended caps but many manufactures don't put the recommended caps on and this is why there is problems with it rebooting.

The most common cap that manufactures r leaving out is the the 100nf on the EN(enable) line. If the EN pin dips even for a fraction of a sec the ESP32 reboots.

Posts: 322
Joined: Fri Oct 02, 2015 6:19 pm

Re: ESP32 broken filesystem

Post by loboris » Fri Dec 14, 2018 10:42 pm

Using SPIFFS or LittleFS for internal file system may help as they are both more resilient to power loss (by design) than FatFS.

Posts: 3
Joined: Tue Oct 24, 2017 10:38 am

Re: ESP32 broken filesystem

Post by krono » Wed Dec 19, 2018 6:47 pm

Thanks guys for the quick reply.

Unfortunately the host device has been already in production so we can't change the hardware and file is currently closed at the end of each operation and this did not solve the problem.

The file is currently in json format, if I avoid writing a file and treat this data as bytes directly on the flash, would I have the possibility to write that part of the corrupted sector avoiding to completely reset the filesystem?

Post Reply