cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411RE stm32cube fatfs sdio sdcard always returns FR_DISK_ERR

Jakub Lasinski
Associate II
Posted on March 03, 2018 at 14:37

Hello.

I've tried to test sdcard with fatfs on STM32F411RE on NUCLEO-F411RE board.

I don't have a compleat 100% sure hardware or software, so I'm struggling to debug if its a software or hardware issue.

I've read trough some topics hear, one with issue with sd initialization (but it seams that in my version this issue is already resolved).

I've tripple cheked all the connections and when the card is not in the socket I get fast resposne.

I've generated the code from stm32cubemx, and added a custom code:

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_SDIO_SD_Init();

  MX_FATFS_Init();

  /* USER CODE BEGIN 2 */

  FRESULT res;

  FATFS SDFatFs;  /* File system object for SD disk logical drive */

  FIL MyFile;     /* File object */

  res =  f_mount(&SDFatFs, (TCHAR const*)SDPath, 0);

  if (res != FR_OK)

      while(1);

  res=  f_open(&MyFile, ''STM32.TXT'', FA_CREATE_ALWAYS | FA_WRITE);

  if (res != FR_OK)

        while(1);

  /* USER CODE END 2 */

f_mount is ok, but f_open after around 30s gives back an FR_DISK_ERR . When there is no card in the socket I'm getting fast FR_NOT_READY return.

When exacuting f_open the funcion stucks on line 3050 from ff.c  

fmt = check_fs(fs, bsect);            /* Load sector 0 and check if it is an FAT-VBR as SFD */

It check_fs returns 4 code back and then f_open returns with FR_DISK_ERR

The only thing I did is change some SDIO pins to other options, and setup the clock. I'v tried with SDIO divider up to 96 and it didn't resolve my issue.

Am i forgetting about something? I know that the socket is on jumper wires, but at 250khz clock it should work... Of course tried few cards, tried to use f_mkfs to format card....

I'm software I'm using:

Attolic True studio v9.0

STM32Cube FW_F4 V1.19.0

FatFs R0.12c

STM32Cube 4.240690X00000604RFQAY.jpg0690X00000609tJQAQ.png0690X00000609m9QAA.png0690X00000609tOQAQ.png0690X00000609tTQAQ.png

#fatfs-sdio #sdio #stm32f411re #nucleo-f411re #fatfs-r0.12c #nucleo-f411 #stm32f4
16 REPLIES 16

share your project please

Unfortunately its a company newly developing product so I cant share the whole project here but I'll attach a text file just for the sd card part. Nothing fancy I've done in this file but from the above post i've initialise the DMA for SDIO and haven't set the SDIO pins to pullup as our board has external pullup resistors on the SDIO line so didn't changed that. Other then that its all cube MX generated code nothing fancy.

did you use BSP_SD_WriteCpltCallback and BSP_SD_ReadCpltCallback like in @Jakub Lasinski​  post?

No call-back functions used

@dungeonlords789​ if you have problem with DMA, just turn on SDMMC interrupts, and DMA should work finely.

kaamil1984
Associate II

Thank you @Jakub Lasinski​ for writing this:

3. Optionally enable internally pull-ups on all lines except sdio_clk. The card works with only internal pull-ups without any problems at almost full speeds.

So, it looks like that some SD cards require pull up, and some not.

I had "FR_DISK_ERR" problem that came out from nothing when I tried to use my old, tested code after few months. In my case it turned out that everything was fine on diffrent SD card, but when I came back to work on filesystem in my project - I got this error. And the worst part was that in the meantime I added FreeRTOS to the project and thought my problem was related to FreeRTOS.

Bill Dempsey
Senior

Awesome post!  I have been trying to solve this same issue and just found your post.  Once I enabled DMA everything worked great.  Now to see if I can get 4 bit mode to work on my board :)