This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ARM RL-FlashFS native SD Card corruption ffree()

Hi,
Wonder if anyone could help me. I’ve got an SD card related problem.
My project builds under uVisionV4.73.0.0, C Compiler Armcc.Exe V5.03.0.76, device = STM32F427II.
My target platform has a native SD card device (2GB capacity and FAT file structure) for which we’re using Keil’s RL-FLashFS i.e. SDIO_STM32F4xx.c , File_Config,c (Rev V4.70). My target platform is a custom hardware design.

The problem
The SD card becomes corrupt however I can still read and write files to it from my target platform perfectly well and finit() returns 0 indicating the card is in good working order however:

- ffree() takes over 1 second to complete whereas normally it completes in approximately 70mSec on a card that hasn’t been corrupted (this very slow response prevents my target booting which is how I discovered the card corruption).

- My Windows PC reports 700+ MB of used space on the card when the files on the card add up to less than 10 MB.

- Windows CHKDSK reports the SD card has errors and can repair it; it finds around 24,000 x 32KB bad clusters. Once CHKDSK has repaired the card the used space equates roughly to the size of the files on the card and ffree() calls on my target platform complete in the usual 70mSec time period.

BTW when I make a copy of the corrupted card using HDDGuru’s HDDRawCopy1.10 the copy has the same 700+MB of wasted (corrupted) space just like the original but when I insert the card into my target platform calls to ffree() complete in the normal 70mSec time frame?

Specifically I would help with
1. Detecting the SD card corruption in my target platform, everything appears to work fine apart from the very slow ffree(); unfortunately fanalyse() and fcheck() aren’t available to me because it is a FAT file system.
2. Understanding why a low level copy of the card doesn’t suffer from the very slow ffree() response.
3. Ultimately stopping the corruption from occurring in the first place.

Many thanks in advance for any assistance/advice you can give me.

Paul

Parents
  • Just some basics, most of SD Cards basically have NAND flash chip as memory and a ASIC controller which handles accessing the NAND as well as ECC and wear-leveling and so on.

    What happens when you want to write to a sector in SD Card is it reads a block that is being accessed to internal RAM it updates RAM with new data, deletes the block and writes whole block back. Worst case if power gets lost is if it happens during block erase or write is that whole block content is lost, so it does not affect only that file data but if it happens on FAT block it corrupts much more.

    If you write a data to a file it then writes all data to blocks, then it updates FAT accordingly depending on size of FAT sectors allocated by written file or when file is closed.

    So, to make it fail safe you would need to detect power failure by a processor and have enough of capacity to hold processor running for as long as it needs to properly finish pending card writes, after that processor has to stop accessing the card and it can power of without leaving card in an odd state.

Reply
  • Just some basics, most of SD Cards basically have NAND flash chip as memory and a ASIC controller which handles accessing the NAND as well as ECC and wear-leveling and so on.

    What happens when you want to write to a sector in SD Card is it reads a block that is being accessed to internal RAM it updates RAM with new data, deletes the block and writes whole block back. Worst case if power gets lost is if it happens during block erase or write is that whole block content is lost, so it does not affect only that file data but if it happens on FAT block it corrupts much more.

    If you write a data to a file it then writes all data to blocks, then it updates FAT accordingly depending on size of FAT sectors allocated by written file or when file is closed.

    So, to make it fail safe you would need to detect power failure by a processor and have enough of capacity to hold processor running for as long as it needs to properly finish pending card writes, after that processor has to stop accessing the card and it can power of without leaving card in an odd state.

Children
No data