cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 + SDIO + FatFS

daniele2
Associate II
Posted on May 19, 2014 at 15:36

Hi all,

I've a problem with my STM32F103. I need to use fat filesystem on SD card to read/write/create files.

I've connected the SD card to the SDIO interface and 4 wires mode with 47Kohm pull-up on cmd and data pins.

I tried to use Chan FatFs module but it didn't working.

When I debug the f_open(), inside the check_fs() function can't retrieve 0xAA55 on boot sector, and the function returns NO_FILE_SYSTEM.

I've tried different SD card but the result was always the same. The clock of the board is 72MHz. I've read other discussions on this forum without luck.

Can someone help me?

Thanks.

Update1: The check_fs() method call the low level SD_ReadBlock() and here, where the code try to set the block size for the card, it returns SD_CMD_RSP_TIMEOUT.

#stm32f103-fat-sdio
23 REPLIES 23
Posted on May 19, 2014 at 16:31

Which specific STM32F103 part are you using?

What board are you using?

Can you draw a schematic of the socket connectivity?

What cards are you using MMC, SD, SDHC, MicroSD, etc?

What capacity?

What low level software are you using to access the cards?

Some ST Library?

Yes, you should verify the low level SD access functions before integrating FatFs on top.

Check the pin configurations, and SD_Init() code.

Check if the 1-bit access mode at 400 KHz is actually working and pulling device geometry from the card.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
daniele2
Associate II
Posted on May 20, 2014 at 08:29

Hi Clive and thanks for the reply.

I'm using an STM32F103VE in a custom board (attached there is the schematic for the SD connection).

I'm using 2 different cards with the same specification: SDHC 4GB class 4.

The low level software used for access the card is sdcard.c fromMCD Application Team of STMcivroelectronics.

This is the GPIO configuration:

GPIO_InitTypeDef GPIO_InitStructure;

/* GPIOC and GPIOD Periph clock enable */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);

/* Configure PC.08, PC.09, PC.10, PC.11, PC.12 pin: D0, D1, D2, D3, CLK pin */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //(GPIOMode_TypeDef)(GPIO_Mode_AF_PP | GPIO_Mode_IPU | GPIO_Mode_Out_PP);

GPIO_Init(GPIOC, &GPIO_InitStructure);

/* Configure PD.02 CMD line */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

GPIO_Init(GPIOD, &GPIO_InitStructure);

In fact, inside theSD_Init(), the functionSD_PowerON() method returns ''SD_CMD_RSP_TIMEOUT'' when it sendsCMD8 to verify SD card interface operating condition.The SD_CLK clock is about 370KHz.

How can I test the sd low level software before integrate it in the FatFS code?

Thank you very much.

________________

Attachments :

SD_schematic.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzD2&d=%2Fa%2F0X0000000bLc%2FhjNc8nN0Ij8jGccEZjX2hE3R_yQ.56Q0YrVsG6xWipk&asPdf=false
daniele2
Associate II
Posted on May 20, 2014 at 14:34

I've reduced the code at the lowest terms.

The main only does:

SD_Error result;

result = SD_Init();

where SD_Init() is:

SD_Error SD_Init(void)

{

  __IO SD_Error errorstatus = SD_OK;

  

  /* SDIO Peripheral Low Level Init */

  SD_LowLevel_Init();

  SDIO_DeInit();

  errorstatus = SD_PowerON();

  if (errorstatus != SD_OK)

  {

    /*!< CMD Response TimeOut (wait for CMDSENT flag) */

    return(errorstatus);

  }

  errorstatus = SD_InitializeCards();

  if (errorstatus != SD_OK)

  {

    /*!< CMD Response TimeOut (wait for CMDSENT flag) */

    return(errorstatus);

  }

  /*!< Configure the SDIO peripheral */

  /*!< SDIO_CK = SDIOCLK / (SDIO_TRANSFER_CLK_DIV + 2) */

  SDIO_InitStructure.SDIO_ClockDiv = SDIO_TRANSFER_CLK_DIV;

  SDIO_InitStructure.SDIO_ClockEdge = SDIO_ClockEdge_Rising;

  SDIO_InitStructure.SDIO_ClockBypass = SDIO_ClockBypass_Disable;

  SDIO_InitStructure.SDIO_ClockPowerSave = SDIO_ClockPowerSave_Disable;

  SDIO_InitStructure.SDIO_BusWide = SDIO_BusWide_1b;

  SDIO_InitStructure.SDIO_HardwareFlowControl = SDIO_HardwareFlowControl_Disable;

  SDIO_Init(&SDIO_InitStructure);

  /*----------------- Read CSD/CID MSD registers ------------------*/

  errorstatus = SD_GetCardInfo(&SDCardInfo);

  if (errorstatus == SD_OK)

  {

    /*----------------- Select Card --------------------------------*/

    errorstatus = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16));

  }

  if (errorstatus == SD_OK)

  {

    errorstatus = SD_EnableWideBusOperation(SDIO_BusWide_4b);

  }  

  return(errorstatus);

}

but the SD_PowerOn() method exits with SD_CMD_RSP_TIMEOUT code.

It doesn't recognize that the card inserted is an SDHC card.

Please, can someone help me?

Thanks

Posted on May 20, 2014 at 18:49

And the supply is enabled?

STM32F10x_StdPeriph_Lib_V3.5.0\Utilities\STM32_EVAL\Common\stm32_eval_sdio_sd.c

* @file stm32_eval_sdio_sd.c
* @author MCD Application Team
* @version V4.5.0
* @date 07-March-2011
* @brief This file provides a set of functions needed to manage the SDIO SD
* Card memory mounted on STM32xx-EVAL board (refer to stm32_eval.h
* to know about the boards supporting this memory).

One would typically test the code by looking at the ReadBlock and ReadMultiBlocks. The code needs the NVIC enabled, the IRQ Handler, and a Card Detect GPIO signal. The aforementioned code will have issues with cards >=4GB as it handles byte addresses as 32-bit rather than using block addressing. A 2GB SD Card might be a better starting point.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 20, 2014 at 18:50

Watch that the writes in the example code are destructive.

STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Examples\SDIO\uSDCard
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 20, 2014 at 19:28

My STM3210E-EVAL has a MicroSD card wired as follows.

0690X00000605cZQAQ.png
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 21, 2014 at 21:41

Did a quick test with a 16GB Ultra MicroSD card, got 9.1 MBps Write, 10.4 MBps Read.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
daniele2
Associate II
Posted on May 23, 2014 at 12:33

Hi Clive

thanks for the answers.

At the end the problem was only the SD card connector (form Molex) whose pins were not good contact when the card was inserted.

Thanks for advice.

guillaumefaye
Associate II
Posted on September 28, 2014 at 20:31

Hi,

I try also to port last fatfs library to my stm32f103ve on port103v board from waveshare , with µsd connector wired on SDIO .

I use sdio exemple from STM32F10x_StdPeriph_Lib_V3.5.0.

With raw exemple all test are ok .

When i test the low level for fatfs , i note SD_WriteBlock fonction work fine with unformated sd card and write nothing with fat32 fomated card in spite of sd_ok retuened by fonction.

To test this, i use sd init of exemple , read first sd sector (i can read fat32 description),

write first sector  with a buffer preloaded(1, 2,3.......fe.ff....)

reread first sector , nothing0 was  write ,i have always fat descriptor.

This test work fine with unformated card.

i use µvision4 v4.73 and 2GB µsd card.