cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to mount a µSD card with STM32F7 (FR_DISK_ERR)

A guy
Associate II
Posted on June 21, 2018 at 10:01

Hi everyone,

I went through a lot of discussions regarding SD card issues this past few days, but even with that I was unable to solve my problem.

I am trying to write file(s) to an SD card but I am always getting an FR_DISK_ERR, either in f_mount if I choose to mount instantly, or with f_open if I choose to mount later.

I have tried to use different SD card (SD 2Go/GB, SDHC 16 & 32Goa and SDXC 64Go but it always ends up with the FR_DISK_ERR.

I have tried those SD cards on two different STM32F769NI discovery boards and two identical custom board with an STM32F769BI microcontroller.

The error happens when the disk_read function is called(f_mount instantly - find_volme - check_fs - move_window- disk_read), disk_read fails and in the comment it's written 'invalidate window if data is not reliable'). So move_window return 4, so does check_fs and finally find_volume returns FR_DISK_ERR.

 However in debug I can also see that there is a problem with SD_read in sd_diskio.c. At the line 206 there is '      while((HAL_GetTick() - timeout) < SD_TIMEOUT)   ' and this lead to HardFault_Handler.

Finally in SDMMC2 - STA register, RXOVERR is checked ('Received FIFO overrun error').

 I used Cube MX to generate the code. My configuration is STM32F769NI or BI, FATFS, SDMMC2, 1 bit SD Mode, RCC (HSE), and I15 input pin to detect SD card.

In main.c the code is :

 MX_GPIO_Init();

MX_FATFS_Init();

MX_SDMMC2_SD_Init();

if(BSP_SD_Init()==MSD_OK)

    {

        if(f_mount(&SDFatFS, '', 1) == FR_OK)

        {

            if (f_open(&SDFile, 'lscp.txt', FA_CREATE_ALWAYS|FA_WRITE)==FR_OK)

            {

                if(f_close(&SDFile)==FR_OK)

                {

                    return 0;// success

                }

                else

                    return -4;  //close failed

            }

            else

                return -3; // open failed

        }

        else

            return -2;    // mount failed

    }

    else{

        return -1;

    }// SD init failed

 If someone has a project mounting SD card with an F7 discovery board please share it so that I can try it to see it what is wrong.

PS: I tried the USB Host example where the USB is used to write on the SD card but even it the card appears in my PC it's impossible to write on it because as soon as I try to do that the card is disconnected from the PC and then connects itself back again.

Thanks a lot for you help !

#discovery #sd-card- #fr_disk_err #fatfs
1 REPLY 1
A guy
Associate II
Posted on June 21, 2018 at 12:32

I have found the answer in this forum =) Too bad I didn't find this earlier.

This post was a life saver :

https://community.st.com/0D50X00009XkWceSAF