cancel
Showing results for 
Search instead for 
Did you mean: 

How to solve file system corruption on my NAND flash after power failure

S_2
Associate II

Embedded File System(EFS), Fat32, through user defined diskio is used on a NAND flash, MT29F1G08AB, in my project. After a sudden power failure during a file operation on this EFS, I realized the EFS turned to be corrupted and the file system cannot be used without a proper reformatting. How can I prevent such a file system corruption on EFS caused by a power failure? is journaling mechanism for FAT supported by Cube MX or relevant Hal libraries?

6 REPLIES 6

FAT32 isn't journaling, and ST doesn't have libraries. The things that make it fragile won't be fixed layering software on top.

You'd probably do better finding a professionally implemented journaling file system for NAND flash, one where they can provide support, and tools to check/repair in failure conditions.

The finite memory resources on most STM32 probably aren't helpful to implementation either.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S_2
Associate II

The problem is exactly what you mentioned. there is no journaling file system for this purpose unless a customized one to be implemented or I migrate to Linux and so forth. I appreciate it if you know one and lemme know about.

prain
Senior III

Are you forced to use FAT32?

if yes:

there are FAT32 libraries that incorporate fail safe journals. take a look on micrium uCFS and express logic fileX libraries. Both are hosted on GitHub.

if no?

use​ a flash friendly, fail safe file system like Littlefs.

S_2
Associate II

Yes I am forced. Because of the complexity of the data I am storing and analyzing, that's much better I manage my data through the file system. Unfortunately I couldn't find the relevant links in GitHub. Would you please send me them?

Thanks a bunch.

​you may want to know that littlefs is a full functional file system similar to FAT. It has integrated wear leveling and fail safe mechanism and highly recommend when dealing with flash storage. The littlefs library consist of just 2 files and you can get it running in 3 days. Again I recommend you to use littlefs. But for reference,

uCFS

https://github.com/SiliconLabs/uC-FS

FileX​

​https://github.com/azure-rtos/filex

Jack Peacock_2
Senior III

Supporting raw NAND flash is a complex programming task since you have to implement journaling, wear leveling and ECC correction. As pointed out above there are commerical libraries for this. From experience I would not recommend building your own raw block NAND handler unless you have extensive knowledge of what's involved (in which case you wouldn't be asking this question). I've seen projects with 7 figure USD cost overruns due to attempts to save a few BOM dollars by using raw NAND instead of eMMC.

As an alternative to pricey NAND libraries and licensing royalties you might consider using an SD card or eMMC module instead of raw NAND. The STM32 SDMMC interface supports both types (SD card for removable, eMMC for embedded). An eMMC module manages all the internal operations to reliably use NAND flash. You may still have to address journaling issues in your application.

Jack Peacock