cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX FATFS SD card re-insert

petr239955
Associate III
Posted on May 11, 2016 at 10:39

Does anybody know how to solve the

re-

inserting the

SD card ?

I have a project

generated by STM32CubeMX. I have used it for re-inserting the SD card

this function

:

if (CD_CARD == b_cd)

{

  if (CD_NO_CARD == b_cd_last)

  {                               /* insert */

    res = f_mount(&SDFatFs, (TCHAR const*)SD_Path, 0);

    if (res == FR_OK)

    {

      App_Clear_Error(ERR_SD_INIT);

    }

    else

    {

      App_Set_Error(ERR_SD_INIT);

    }

  }

}

else

{

  if (CD_CARD == b_cd_last)

  {                               /* eject */

     res = f_mount(NULL, (TCHAR const*)SD_Path, 0);

     App_Set_Error(ERR_SD_INIT);

  }

}

b_cd_last = b_cd;

Card operations as f_open after re-inserting the sd card

do not work.

#stm32cubemx-fatfs-sd-re-insert
3 REPLIES 3
slimen
Senior
Posted on May 11, 2016 at 12:22

Hi,

Which firmware package are you using ?

You can find a full set of running examples and needed functions within the firmware package which is available on the ST web?

Regards

petr239955
Associate III
Posted on May 11, 2016 at 13:25

Hi,

I use STM32CubeMX 4.14.0, STM32CubeF7 1.3.1.

I found

a very simple examples for FATFS with an expected card inserted.

To test

the card

occurs

only

once after

reset.

Petr

petr239955
Associate III
Posted on May 13, 2016 at 14:29

I found some

solution.

I do not know

why there should be

a delay

(

HAL_Delay(10) ) ?

if (CD_CARD == b_cd)

{

  if (CD_NO_CARD == b_cd_last)

  {                               /* insert */

    MX_FATFS_Init();

    HAL_Delay(10);   /* min 5 ms */

    res = f_mount(&SDFatFs, (TCHAR const*)SD_Path, 1);

    if (res == FR_OK)

    {

      App_Clear_Error(ERR_SD_INIT);

    }

    else

    {

      App_Set_Error(ERR_SD_INIT);

    }

  }

}

else

{

  if (CD_CARD == b_cd_last)

  {                               /* eject */

   

FATFS_UnLinkDriver(SD_Path);

    HAL_SD_DeInit(&hsd1);

    res = f_mount(NULL, (TCHAR const*)SD_Path, 1);

    App_Set_Error(ERR_SD_INIT);

  }

}

b_cd_last = b_cd;