AnsweredAssumed Answered

Help with SDIO

Question asked by B3rsui on Mar 4, 2013
Latest reply on Sep 15, 2013 by Clive One
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! 

Outcomes