NAND flash files corruption

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • NAND flash files corruption

    Hi All,

    I'm working on NAND flash using emFile in FAT32 type on custom board with STM32F103VE.
    It is observed that files get corrupted when system is power cycled frequently.


    After corruption, device executes following condition:


    Source Code

    1. if (0 != FS_FindFirstFile(&dir, dir_name, file_name, sizeof(file_name))){ while (1 == FS_FAT_CheckDisk(NAND_FLASH_PREFIX "0", &Big_stack, sizeof(Big_stack), 2, On_Check_Disk_Error));}




    In above condition, function FS_FindFirstFile() returns 1 which means “No entries available in the directory”.
    In addition to that, function FS_FAT_CheckDisk() returns following message:
    “Cluster 2 is marked as used, but not assigned to a file or directory.”



    Can anybody please explain this message or provide a document which can explain it in detail?




    The post was edited 1 time, last by geekxCoder ().

  • Hello,

    The error indicates that the file system has been corrupted.
    More exactly, a FAT cluster is marked as in use in the allocation
    table but FS_CheckDisk() cannot find any file or directory
    that actually uses this cluster.

    The FAT file system is not fail-safe by design and a sudden reset can easily corrupt it.
    SEGGER provides a Journaling add-on that can be used to make the FAT file system fail-safe.
    You will have to use this add-on to protect the structure of the file system against sudden resets.

    In addition to this the hardware has to be fail-safe too. This means that from the moment the CPU
    enters reset, the power supply of the NAND flash has to remain valid for a period of time long enough
    to allow an ongoing program or erase operation to finish.

    Best regards,
    Marius