Skip to main content
Visitor II
November 19, 2024
Question

STM32F401RE: failed to mound SDcard

  • November 19, 2024
  • 2 replies
  • 1110 views

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

    This topic has been closed for replies.

    2 replies

    Super User
    November 19, 2024

    @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.

     

    TonyMayAuthor
    Visitor II
    November 19, 2024

    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.......

    Technical Moderator
    November 19, 2024

    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

    TonyMayAuthor
    Visitor II
    November 19, 2024

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

    Technical Moderator
    November 19, 2024

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