2016-05-12 04:55 AM
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! #sdio #stm32 #f4 #sdmmc #f72016-05-13 02:55 AM
Hi debegr,
STM32Cube_FW_F4_V1.11.0\Projects\STM324x9I_EVAL\Applications\FatFs\FatFs_uSDThis directory contains example that provide a description on how to use STM32Cube firmware with FatFs middleware component as a generic FAT file system module,in order to develop an application exploiting FatFs offered features with microSD drive configurationFor more details about FatFs implementation on STM32Cube, please refer to ''Developing Applications on STM32Cube with FatFs''.-Syrine-2016-05-14 08:32 AM
Hi Syrine,
thank you for your advice. I found exactly this example code for the STM32F7xx and copy it into my code. The if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0) was created from CubeMX init (FatFS_Init function), this is why I deleted the first if case with this line of code. Now I get the error in this line: if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK) I got the error code 3 -> Not ready. Ok there is always a FAT16/32 file system on the two cards tested, I also deleted this function and try to open the file direct. But there I also get the error 3... I am not sure, but the code in the example is not really the same like the created one from CubeMX. CubeMX calls first a function to set the SDIO (or later on STM32F7xx SDMMC) interface but do not init this, this is done later from the driver layer in FatFS. Do I miss anything or is there a hidden secret feature I have to enable?! I think with the right settings and the example code I am good to go but it still do not work and in the example code I can't see any initialization of SD or FatFS?!2017-09-12 05:59 PM
CubeMX is a nice tool but it lags behind CubeF7. Version 4.22.1 as well.
Learn to switch like I did. You spend more hours in debugging as in
building a new project without a code generator.