cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F401RE: failed to mound SDcard

TonyMay
Associate II

Hello Everyone

I am using FATFS on STM32F401RE, with the code generated by CubeMX, which is version 6.12.0. When I perform the mount operation, the return value is FR_NOT_READY. However, initializing the SD card through the HAL library and reading SD card information using the HAL library are both normal operations. Therefore, the SD card is functioning correctly, and the circuitry between the SD card and STM32F401RE is also normal. So, how can I resolve the issue of not being able to mount the file system?

 

AND this is sdio config

1.jpg

 

TEST CODE:

 

 

 

printf("Micro SD Card Test...\r\n");
    HAL_SD_Init(&hsd);
    if(HAL_SD_GetCardState(&hsd) == HAL_SD_CARD_TRANSFER)
    {

        printf("Initialize SD card successfully!\r\n");
        printf(" SD card information! \r\n");
        printf(" CardCapacity : %llu \r\n", (unsigned long long)hsd.SdCard.BlockSize * hsd.SdCard.BlockNbr);
        printf(" CardBlockSize : %ld \r\n", hsd.SdCard.BlockSize);
        printf(" LogBlockNbr : %ld \r\n", hsd.SdCard.LogBlockNbr);
        printf(" LogBlockSize : %ld \r\n", hsd.SdCard.LogBlockSize);
        printf(" RCA : %ld \r\n", hsd.SdCard.RelCardAdd);
        printf(" CardType : %ld \r\n", hsd.SdCard.CardType);
        HAL_SD_CardCIDTypeDef sdcard_cid;
        HAL_SD_GetCardCID(&hsd,&sdcard_cid);
        printf(" ManufacturerID: %d \r\n",sdcard_cid.ManufacturerID);
    }
    else
    {

        printf("SD card init fail!\r\n" );
    }
    HAL_Delay(50);
    FRESULT res = f_mount(&fs, "0:", 1);
    if (res != FR_OK) {
        printf("Mount Error ,err code: %d\n", res);
        return 0;
    } else {
        printf("Mount OK \n");
    }

 

 

 

 

RESULT

abc.jpg

6 REPLIES 6

@TonyMay wrote:

When I perform the mount operation, the return value is FR_NOT_READY. 


So step into that function, and see  what causes it to give that return value.

 


@TonyMay wrote:

However, initializing the SD card through the HAL library and reading SD card information using the HAL library are both normal operations. .


So compare & contrast what the HAL is doing against what your FatFs version is doing.

Don't just look at the software - also use an oscilloscope or logic analyser to see what's actually happening in the hardware.

 

SofLit
ST Employee

Hello,

It could be something related to the bit mode: 1-bit / 4 bit.

See this thread: https://community.st.com/t5/stm32cubemx-mcus/solution-for-stm32-f7-sdmmc-in-4-bit-wide-bus-mode-issue/td-p/618418

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hello, I have tried using SD 1-bit mode and SD 4-bit bus mode, but the problem persists

Check your HW (pull up resistors etc ..), your SD card, your wiring ..

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hello, I suspect the issue lies with the FATFS part, as the HAL library can read the SD card normally and print the SD card information correctly, which indicates that there are no problems with the SD card or the circuitry. This can be seen from the initial test code and the serial output results. Therefore, my focus is on the FATFS part. By the way, I also enabled RTOS using CUBEMX, and I am currently checking if there are any anomalies in the FATFS configuration.

Hello
Since the HAL library can communicate with the SD card normally, I have compared the code involved in the HAL library initialization and the f_mount part, but there seems to be no direction for a solution at the moment. Because using the HAL alone without FATFS can correctly read the SD card information, the only thing that can be confirmed is that the SD card and its circuitry are normal. The problem seems to be with the FatFs configuration, and the issue is still being resolved.......