Skip to main content
kadir ustun1
Associate III
July 11, 2018
Question

How to use SDIO interface?

  • July 11, 2018
  • 9 replies
  • 4146 views
Posted on July 11, 2018 at 07:37

Hello, I want to use micro SD card with SDI0 interface. but I don't find document. Could you help me? Thanks.

    This topic has been closed for replies.

    9 replies

    Tesla DeLorean
    Guru
    July 11, 2018
    Posted on July 11, 2018 at 08:10

    Probably covered by multiple documents. The card spec can't be published by ST, but you can review the SDIO peripheral description in the Reference Manual, and review the assorted examples. If you dig a little you should be able to find the SD Card Association docs.

    This talks about the SPI interface, but the cards at a command level function the same, just you can push data over wider buses.

    http://elm-chan.org/docs/mmc/mmc_e.html

     

    STM32Cube_FW_F4_V1.21.0\Drivers\BSP\STM324x9I_EVAL\stm324x9i_eval_sd.c

    STM32Cube_FW_F4_V1.21.0\Projects\STM324x9I_EVAL\Applications\FatFs\FatFs_uSD

    STM32Cube_FW_F4_V1.21.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_sd.c

    STM32Cube_FW_F4_V1.21.0\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_ll_sdmmc.c

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    kadir ustun1
    Associate III
    July 11, 2018
    Posted on July 11, 2018 at 08:31

    Thank you for answered. I try to work with stm32f429zı. I configured, but this did not work.

    Tesla DeLorean
    Guru
    July 11, 2018
    Posted on July 11, 2018 at 08:45

    That's the chip, but what board? The STM32F429I-DISCO isn't really designed to interface an SD Card, one of the pins is used by the LCD RED bus. The NUCLEO-F429ZI has all the required pins on the 16-pin header.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    kadir ustun1
    Associate III
    July 11, 2018
    Posted on July 11, 2018 at 13:30

    Hello, my configuration code is : 

    __HAL_RCC_SDIO_CLK_ENABLE();

    //GPIOD : 2 (SDIO_CMD),

    //GPIOC : 12(SDIO_CLK), 8(SDIO_DO)

    //GPIOA : 8(CARD)

    __HAL_RCC_GPIOA_CLK_ENABLE();

    __HAL_RCC_GPIOC_CLK_ENABLE();

    __HAL_RCC_GPIOD_CLK_ENABLE();

    GPIO_InitStruct.Pin = GPIO_PIN_8;

    GPIO_InitStruct.Pull = GPIO_PULLUP;

    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_8;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_PULLUP;

    GPIO_InitStruct.Speed = GPIO_SPEED_FAST;

    GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;

    HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_2;

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_PULLUP;

    GPIO_InitStruct.Speed = GPIO_SPEED_FAST;

    GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;

    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

    hsd.Instance = SDIO;

    hsd.Init.BusWide = SDIO_BUS_WIDE_1B;

    hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;

    hsd.Init.ClockDiv = 0;

    hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;

    hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;

    hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;

    HAL_SD_ConfigWideBusOperation(&hsd,SDIO_BUS_WIDE_1B);

    if((HAL_SD_InitCard(&hsd))!=0)

    {

    Error_Handler();

    }

    it stays 

    Error_Handler();  please help me ?

    Tesla DeLorean
    Guru
    July 11, 2018
    Posted on July 11, 2018 at 15:49

    You should be able to initialize the SD in 1-bit mode, and then not reconfigure it.

    It would probably take me a hour or two to port some working code to the F429I-DISCO, if you want to pick up the billable hours?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    kadir ustun1
    Associate III
    July 12, 2018
    Posted on July 12, 2018 at 09:25

    So, sould I wait ? 

    kadir ustun1
    Associate III
    July 16, 2018
    Posted on July 16, 2018 at 08:50

    Hello, Thank you for answered. I solved this problem. I fixed this code below:

    in stm32f4xx_it.c : 

    void DMA2_Stream3_IRQHandler(void)

    {

    /* USER CODE BEGIN DMA2_Stream3_IRQn 0 */

    /* USER CODE END DMA2_Stream3_IRQn 0 */

    HAL_DMA_IRQHandler(&hdma_sdio_rx);

    /* USER CODE BEGIN DMA2_Stream3_IRQn 1 */

    /* USER CODE END DMA2_Stream3_IRQn 1 */

    }

    /**

    * @brief This function handles DMA2 stream6 global interrupt.

    */

    void DMA2_Stream6_IRQHandler(void)

    {

    /* USER CODE BEGIN DMA2_Stream6_IRQn 0 */

    /* USER CODE END DMA2_Stream6_IRQn 0 */

    HAL_DMA_IRQHandler(&hdma_sdio_tx);

    /* USER CODE BEGIN DMA2_Stream6_IRQn 1 */

    /* USER CODE END DMA2_Stream6_IRQn 1 */

    }

    void SDIO_IRQHandler(void)

    {

    //BSP_SD_ReadCpltCallback();

    HAL_SD_IRQHandler(&hsd);

    //__HAL_SD_CLEAR_IT(&hsd,SDIO_IT_SDIOIT);

    }

    then, in HAL_SD_RxCpltCallback(hsd);  in  

    HAL_SD_IRQHandler(&hsd) 

    __weak void HAL_SD_RxCpltCallback(SD_HandleTypeDef *hsd)

    {

    /* Prevent unused argument(s) compilation warning */

    BSP_SD_ReadCpltCallback();

    //UNUSED(hsd);

    /* NOTE : This function should not be modified, when the callback is needed,

    the HAL_SD_RxCpltCallback can be implemented in the user file

    */

    }

    and same in 

    HAL_SD_TxCpltCallback(hsd);  in  

    HAL_SD_IRQHandler(&hsd) 

    __weak void HAL_SD_TxCpltCallback(SD_HandleTypeDef *hsd)

    {

    /* Prevent unused argument(s) compilation warning */

    BSP_SD_WriteCpltCallback();

    // UNUSED(hsd);

    /* NOTE : This function should not be modified, when the callback is needed,

    the HAL_SD_TxCpltCallback can be implemented in the user file

    */

    }