Skip to main content
Palacios.Bruno
Associate III
March 4, 2013
Question

Help with SDIO

  • March 4, 2013
  • 7 replies
  • 1488 views
Posted on March 04, 2013 at 18:09

Hi guys. First of all, sorry if my english is bad.

I have a problem configuring a uSD and SDIO port. I'm using the ST SDIO example for STM32f4 discovery board and I cant comunicate with de micro SD. 

I checked the pins config, clock speed and everything seems to be ok. But if I check the pins voltaje, all are at 3v (by the pull ups resistors) and the clock is at 0v always.

When I see the clock signal with my oscilloscope I can see it never starts. So I get a SD_CMD_RSP_TIMEOUT from CmdError().

Here is the code.

/**************************************************/

int main(void)

{

  /*!< At this stage the microcontroller clock setting is already configured, 

       this is done through SystemInit() function which is called from startup

       file (startup_stm32f4xx.s) before to branch to application main.

       To reconfigure the default setting of SystemInit() function, refer to

       system_stm32f4xx.c file

     */

  /* Interrupt Config */

  NVIC_Configuration();

  /*------------------------------ SD Init ---------------------------------- */

  if ((Status = SD_Init()) != SD_OK) { 

    STM_EVAL_LEDOn(LED6);  // Error LED

  }

 [...]

while(1);

}

/**************************************************/

SD_Error SD_Init(void) {

__IO SD_Error errorstatus = SD_OK;

/* SDIO Peripheral Low Level Init */

SD_LowLevel_Init();

errorstatus = SD_PowerON();

if (errorstatus != SD_OK) {

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

return (errorstatus);

[...]

}

/*******************************************/

void SD_LowLevel_Init(void)

{

  GPIO_InitTypeDef  GPIO_InitStructure;

  /* GPIOC and GPIOD Periph clock enable */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | SD_DETECT_GPIO_CLK, ENABLE);

  /* Configure PC.08, PC.09, PC.10, PC.11 pins: D0, D1, D2, D3 pins */

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

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_SDIO);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_SDIO);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SDIO);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_SDIO);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SDIO);

  /* Configure PD.02 CMD line */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

  GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_SDIO);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* Configure PC.12 pin: CLK pin */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

  

  /*!< Configure SD_SPI_DETECT_PIN pin: SD Card detect pin */

  GPIO_InitStructure.GPIO_Pin = SD_DETECT_PIN;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

  GPIO_Init(SD_DETECT_GPIO_PORT, &GPIO_InitStructure);

  /* Enable the SDIO APB2 Clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO, ENABLE);

  /* Enable the DMA2 Clock */

  RCC_AHB1PeriphClockCmd(SD_SDIO_DMA_CLK, ENABLE);

  SDIO_SetPowerState(SDIO_PowerState_ON);

  SDIO_ClockCmd(ENABLE);

}

/*******************************************/

SD_Error SD_PowerON(void) {

__IO SD_Error errorstatus = SD_OK;

uint32_t response = 0, count = 0, validvoltage = 0;

uint32_t SDType = SD_STD_CAPACITY;

/*!< Power ON Sequence -----------------------------------------------------*/

/*!< Configure the SDIO peripheral */

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

/*!< on STM32F4xx devices, SDIOCLK is fixed to 48MHz */

/*!< SDIO_CK for initialization should not exceed 400 KHz */

SDIO_InitStructure.SDIO_ClockDiv = 120; //SDIO_INIT_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_4b;

SDIO_InitStructure.SDIO_HardwareFlowControl =

SDIO_HardwareFlowControl_Disable;

SDIO_Init(&SDIO_InitStructure);

/*!< Set Power State to ON */

SDIO_SetPowerState(SDIO_PowerState_ON);

/*!< Enable SDIO Clock */

SDIO_ClockCmd(ENABLE);

/*!< CMD0: GO_IDLE_STATE ---------------------------------------------------*/

/*!< No CMD response required */

SDIO_CmdInitStructure.SDIO_Argument = 0x0;

SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_GO_IDLE_STATE;

SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_No;

SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

SDIO_SendCommand(&SDIO_CmdInitStructure);

errorstatus = CmdError();

if (errorstatus != SD_OK) {

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

return (errorstatus);

}

/*******************************************/

As you can see I only paste the parts of the code that my system execute.

Please, help me! 

#sdcard-stm32f4-sdio-fatfs
This topic has been closed for replies.

7 replies

Tesla DeLorean
Guru
March 4, 2013
Posted on March 04, 2013 at 18:46

The nonsense with PD12..15 causes you to misconfigure the clock pin.

Also setting the slew rate to 2 MHz probably isn't where you want to be when running the SDIO at 24 MHz.

I've previously posted working code to attach an MicroSD card to the STM32F4-Discovery and use FatFs
Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Palacios.Bruno
Associate III
March 4, 2013
Posted on March 04, 2013 at 19:08

Thanks for you reply!

Same Error with your example =/. And the clock pin still at 0v.

Any idea what's happening or what could be the error?

regards

Palacios.Bruno
Associate III
March 6, 2013
Posted on March 06, 2013 at 17:23

Solved!

I forgot to add SystemInit() before main() in Startup_stm32f4xx.c

Thanks!

jschmoetz
Visitor II
July 11, 2013
marwa2
Associate
September 12, 2013
Posted on September 12, 2013 at 12:01

I want to ask how I see results of sdio signals on logical analyzer.

I tried to make 2 groups of signal 

1st group: cmd and clock.

2nd group: data lines and clock.

But I don't know if this true or not? 

My code in while(1) is the following

   //CMD0 Go idle.

 //Structure.

            SDIO_CmdInitTypeDef SDIO_CmdInitStructure;                    

            SDIO_CmdInitStructure.SDIO_Argument = 0x0;

            SDIO_CmdInitStructure.SDIO_CmdIndex = 0x00;

            SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_No;

            SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;

            SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;

            SDIO_SendCommand(&SDIO_CmdInitStructure);

If you have another way to see this signals please tell me.

Thank.

I wait your help.

marwa2
Associate
September 14, 2013
Posted on September 14, 2013 at 14:03

I wait your reply. Where is your reply??

Tesla DeLorean
Guru
September 14, 2013
Posted on September 15, 2013 at 00:14

I wait your reply. Where is your reply??

Perhaps no one currently browsing the forum has a logic analyzer attached to the SDIO bus?

I guess if I wanted to observe SDIO bus traffic, I'd just use the example code from the firmware library and have it do block reads in a loop.
Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..