cancel
Showing results for 
Search instead for 
Did you mean: 

fatfs disk error

er3481
Senior
Posted on January 11, 2017 at 14:59

Hi,

I am using fatfs sdio with my stm32f429 mcu , i can, open read, write files correctly. When i plug out the sd card from my board at runtime, the f_open, f_write and f_read functions do not work and so i can not open or write anything to file, until i reset the mcu. I use for open and write sequence with my code below:

 if(f_mount(&SDFatFs, '0:', 0) == FR_OK)//sd kart yazma işlemleri    

  {      

    if(f_open(&MyFile, 'STM32.TXT', FA_CREATE_ALWAYS | FA_WRITE) == FR_OK)      

    {        

      if(f_write(&MyFile, (const void *)wtext, sizeof(wtext), (void *)&wbytes) == FR_OK);        

      {          

        f_close(&MyFile);        

      }      

    }    

  }

Any advise??

6 REPLIES 6
Posted on January 11, 2017 at 15:28

Reinitialize the SDIO layer?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 11, 2017 at 15:34

Hi Clive One,

Yes i have called the 'MX_SDIO_SD_Init();' function when i re-plug the sdcard, but it doesnt work.

AvaTar
Lead
Posted on January 11, 2017 at 17:24

Just pulling the card during operation is not a supported use case.

What do other OSs do when 'unmounting' a SD card ?

Pretty sure you need to incorporate that procedure - SD cards have a controller on their own, and thus are asynchronous.

I have several projects with fatfs usage, but none is ready for 'hot plugging'.

Posted on January 11, 2017 at 17:03

Then evidently you'll need to dig into that and make it more robust in terms of it's ability to get the peripheral/interface/card into an agreeable state. I'm not sure what is supplied is a commercially robust solution. There is no code to determine what state things are in, or retry, or reset the interface.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 11, 2017 at 17:54

Pulling a card during active usage is a whole level of grief in terms of tearing down the system and recovering. It also runs significant risk of destroying or corrupting content.

Getting something into a safe state where you can 'eject' the card, and then remount a new one, is more achievable, but does require a lot of work and thought. The code as supplied by ST has very poor error handling or recovery, and has a lot of expectations about initial conditions, and run-once usage.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 17, 2017 at 13:33

Hi,

when i have tried fatfs with spi, it works well for this situation. I think the problem is about the sdio layer. I have used the sdio_init function when i have re-ejected the sdcard but it does not work. Do you  know any extra init or reset condition for sdio layer ??