cancel
Showing results for 
Search instead for 
Did you mean: 

FatFS SD wont initialize

stefanskos9
Associate II
Posted on January 02, 2014 at 06:01

Hi All,

I'm having problems with getting my 2Gb Micro SD card to initialize.

From deubgging, I have found the problem occurs in the FindSCR(RCA, scr) function called within SDEnWideBus(FunctionalState NewState).

Specifically the errorstatus returns 'SD_CMD_RSP_TIMEOUT' when the following code is run

  /*!< Send CMD55 APP_CMD with argument as card's RCA */

  SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;

  SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;

  SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;

  SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

  SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

  SDIO_SendCommand(&SDIO_CmdInitStructure);

  errorstatus = CmdResp1Error(SD_CMD_APP_CMD);

Any thoughts on why this would be so?

Thanks for your help in advance!

Stive

3 REPLIES 3
stefanskos9
Associate II
Posted on January 03, 2014 at 02:25

Oh, and FWIW, I am using the Mikromedia+ STM32 board which does not have pull-up resistors on the data/CMD lines, but however does have 27R inline resistors (also on CLK line).

I have enabled pullup on the ports - I assume this is enough as it was working when using the MikroElektronika example code in MikroC??

stefanskos9
Associate II
Posted on January 03, 2014 at 05:12

Okay - Update

Have fixed the issue. Problem was with the FindSCR library function being passed 'rca' but then trying to call variable 'RCA' (which was blank). Updating code to:

SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) rca << 16;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure);
errorstatus = CmdResp1Error(SD_CMD_APP_CMD);

Did the trick and errorstatus now returns SD_OK. The initialization continues to be okay until it runs the same piece of code in theSDEnWideBus function, after its completed the FindSCR function. This time 'RCA' is the correct capitalization, however the code returns the 'SD_CMD_RSP_TIMEOUT' error with the following code

/*!< If requested card supports wide bus operation */
if ((scr[1] & SD_WIDE_BUS_SUPPORT) != SD_ALLZERO)
{
/*!< Send CMD55 APP_CMD with argument as card's RCA.*/
SDIO_CmdInitStructure.SDIO_Argument = (uint32_t) RCA << 16;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_APP_CMD;
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure);
errorstatus = CmdResp1Error(SD_CMD_APP_CMD);

Seems to be identical to before when it passed. Any thoughts on why this would be so? Thanks for your help in advance! Stive
stefanskos9
Associate II
Posted on January 03, 2014 at 06:16

UPDATE AGAIN!

So I realised that RCA is suppose to be a global variable, but it was resetting in the FindSCR function after the line ''uint32_t tempscr[2] = {0, 0};''

Setting 'RCA = rca;' at the end of the FindSCR function allows the original value of RCA to be recovered and the SD card to intialize in the next parts.

For some reason the next part of the code wont work (opening a txt file) however I don't have time to look at that yet.

Why is this happening? Am I running out of memory? memory leak? Perhaps the debugger is causing issue? I am using ST-Link v2 and IAR.

The code is from an example Clive1 posted awhile ago.