cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 SDIO FatFs: no connection to the µSD (no f_mount, no f_open)

Jakob Czekansky
Associate II
Posted on November 02, 2017 at 18:40

Hey Guys,

I am setting up some STM32F407VETx on a chinese breakout board with �SD-card-slot. 

I try to read data from the sd card with SDIO (SD 4 bits Wide bus) and FatFs.

The Basic-Project is build with STM32 CubeMx and programmed in the OpenSTM32 Workbench

My Problem: 

The SD Card is ALWAYS in 'FR_NOT_READY'. I am not able to mount  / open / write any data, because the �C is always stuck in the following function:

/**

* @brief Checks for error conditions for R1 response.

* @param hsd SD handle

* @param SD_CMD The sent command index

* @retval SD Card error state

*/

static uint32_t SDMMC_GetCmdResp1(SDIO_TypeDef *SDIOx, uint8_t SD_CMD, uint32_t Timeout)

{

   ...

}

Because of the timeout in this function i get an errorcode '1' (R/W Error ) in diskio.c

I've tried 3 boards, 3 SD-cards - nothing is broken! I have no clue, what to do... 

I am just using the 'basic' fatfs functions, as you can the in the attachment.

Please help me!

:(

Greets!

Ps.: If you need more information, please write some comment!

#sdio #error #sd #stm32f407 #sd-card #fatfs
11 REPLIES 11
Posted on November 02, 2017 at 19:46

Can you link to a vendor page, or insert a picture of the board?

Any schematic available/provided?

Is there a card detect on the socket?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Jakob Czekansky
Associate II
Posted on November 02, 2017 at 22:15

Ok, i got the following news: 

When i build my project with an older version of CubeMx (4.22.1) then it uses an older version of FatFs (R0.11). With this setting everything works fine! 

But when i use the latest version of CubeMx (4.23.0) there is a newer version of FatFs (R0.12c) with it. 

I think the problem comes with the 

FatFs (R0.12c), ...

I have to use the newest version of CubeMx, so i have to fix this...

:(

Posted on November 03, 2017 at 11:11

I added some schematic on the top.

Posted on November 09, 2017 at 18:07

Hi Jakob,

can you share the sd_diskio.c from your project?

are you calling the BSP_SD_Init() in  your main application?

regards

Posted on November 09, 2017 at 19:10

So a board like this

https://community.st.com/0D50X00009XkgXwSAJ

 
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 09, 2017 at 19:14

The code the OP uses in the .PNG attach to the top post

Seem to be some problems with the Cube release

https://community.st.com/0D50X00009XkZk8SAF

https://community.st.com/0D50X00009Xkf8PSAR

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Haithem Rahmani
ST Employee
Posted on November 10, 2017 at 10:43

Hi Jakob and all,

the issue is that BSP_SD_Init() is not called in the sd_diskio.c file.This is a bug that is going to be fixed in the next release. Could you please modify the generated sd_diskio.c, in particular the SD_Initiaize() function as following and retest?

DSTATUS SD_initialize(BYTE lun)

{

  Stat = STA_NOINIT;

  if (BSP_SD_Init() == MSD_OK)

  {

    Stat = SD_CheckStatus(lun);

  }

  return Stat;

}

regards

Haithem.
Posted on November 10, 2017 at 13:04

Hi Haithem,

I modified the sd_diskio.c as you described, but the program now gets stuck in ff.c at

/* Find an FAT partition on the drive. Supports only generic partitioning rules, FDISK and SFD. */

bsect = 0;

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

And after a while it quits with 

if (fmt == 4) return FR_DISK_ERR; /* An error occured in the disk I/O layer */

Greets,

Jakob

Ps.: And yes, the SD Card has a working FAT system on it.

Posted on November 10, 2017 at 15:39

Hi Jakob,

the issue seems to be related to an error in the SD_read()/SD_Write() functions in the sd_dikio.c file.

Could you do the following:

 

in the function move_window() in the file ff.c check the res value after the sync_window():

 

  1. if it is

    different

    from

    FR_OK

    then rerun the program and put a break point in the function

    SD_Write() in the sd_diskio.c and check whether there is an issue in the BSP_SD_WriteBlocks_DMA()

     

  2. if is

    equal

    to

    FR_OK

    then check the whether the call below is successful or not:

    if (disk_read(fs->drv, fs->win.d8, sector, 1) != RES_OK)

    if

    it is not

    then put a break point in the SD_Read in the sd_diskio.c file and check the  

              BSP_SD_ReadBlocks_DMA()

regards