AnsweredAssumed Answered

SDIO (SDMMC) and FatFS with CubeMX

Question asked by debegr on May 12, 2016
Latest reply on Sep 13, 2017 by Joerg Wagner
Hello!
I try to use the SDMMC1 interface together with FatFS. Initialization is created with CubeMX.
My init is something like this:
...
MX_LTDC_Init();
MX_SDMMC1_SD_Init();
MX_FATFS_Init();
...

Then I try to use the SD card. The CardInfo is right, I get data from. But with the FatFS I got some problems. Initialization and f_mount is no problem but then I get uSD: FatFs format Error with the Error code 3 -> NOT_READY

UG_ConsoleSetForecolor(C_YELLOW);
UG_ConsolePutString("System start uSD debugging...!\n");

if(HAL_SD_Get_CardInfo(&hsd1, &SDCardInfo1) != SD_OK)
{
    UG_ConsoleSetForecolor(C_RED);
    UG_ConsolePutString("uSD: HAL_SD_Get_CardInfo != SD_OK!\n");
    Error_Handler();
}

// Put infos about SD card
UG_ConsoleSetForecolor(C_WHITE);
sprintf(itoaBuffer, "SD capacity: %d\n",SDCardInfo1.CardCapacity);
UG_ConsolePutString(itoaBuffer);
sprintf(itoaBuffer, "SD block size: %d\n",SDCardInfo1.CardBlockSize);
UG_ConsolePutString(itoaBuffer);
sprintf(itoaBuffer, "SD type: %d\n",SDCardInfo1.CardType);
UG_ConsolePutString(itoaBuffer);


/*##-2- Register the file system object to the FatFs module ##############*/
FRESULT tempRes = f_mount(&SDFatFs, (TCHAR const*)SDPath, 0);
if(tempRes != FR_OK)
{
    /* FatFs Initialization Error */
    UG_ConsoleSetForecolor(C_RED);
    sprintf(itoaBuffer, "uSD: FatFs Initialization Error (%d)\n", tempRes);
    UG_ConsolePutString(itoaBuffer);
    Error_Handler();
}
else
{
/*##-3- Create a FAT file system (format) on the logical drive #########*/
/* WARNING: Formatting the uSD card will delete all content on the device */
tempRes = f_mkfs((TCHAR const*)SDPath, 0, 0);
if(tempRes != FR_OK)
{
    /* FatFs Format Error */
    UG_ConsoleSetForecolor(C_RED);
    sprintf(itoaBuffer, "uSD: FatFs format Error (%d)\n", tempRes);
    UG_ConsolePutString(itoaBuffer);
    Error_Handler();
}

Do I have to do something else after the init from Cube? I am a bit in trouble with the FatFS...
Would be great if someone has an answer for me!

Outcomes