cancel
Showing results for 
Search instead for 
Did you mean: 

STM32- Can not initialize eMMC, CMDTIMEOUT

Trahery
Associate

I have problem with using stm32 drivers for connection to eMMC.https://datasheet.lcsc.com/lcsc/2205071500_Zetta-ZDEMMC04GA_C3010207.pdf

Problem is that the initialization pop up error, because timeout occures in function static uint32_t SDMMC_GetCmdError(SDIO_TypeDef *SDIOx). I'm using sdio MMC 4bus connection. With default configuration generated with cube MX. Whole CubeIDE project: https://drive.google.com/file/d/17Y-EmB60kiUhar9B0o4DANVTT_GUKXUu/view?usp=drive_link

INITIALIZATION FUNCTION:

static void SDIO_MMC_Init(void){
      hmmc.Instance = SDIO;
      hmmc.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
      hmmc.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
      hmmc.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
      hmmc.Init.BusWide = SDIO_BUS_WIDE_4B;
      hmmc.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
      hmmc.Init.ClockDiv = 0;
      if (HAL_MMC_Init(&hmmc) != HAL_OK){
        Error_Handler();
      }
      if (HAL_MMC_ConfigWideBusOperation(&hmmc, SDIO_BUS_WIDE_4B) != HAL_OK){
        Error_Handler();
      }
    
    }

MSP_INITIALIZATION

void HAL_MMC_MspInit(MMC_HandleTypeDef* hmmc)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(hmmc->Instance==SDIO)
  {
  /* USER CODE BEGIN SDIO_MspInit 0 */

  /* USER CODE END SDIO_MspInit 0 */
    /* Peripheral clock enable */
    __HAL_RCC_SDIO_CLK_ENABLE();

    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOD_CLK_ENABLE();
    /**SDIO GPIO Configuration
    PC8     ------> SDIO_D0
    PC9     ------> SDIO_D1
    PC10     ------> SDIO_D2
    PC11     ------> SDIO_D3
    PC12     ------> SDIO_CK
    PD2     ------> SDIO_CMD
    */
    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
                          |GPIO_PIN_12;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    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_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  /* USER CODE BEGIN SDIO_MspInit 1 */

  /* USER CODE END SDIO_MspInit 1 */
  }
}

 

1 REPLY 1
Ghofrane GSOURI
ST Employee

Hello @Trahery 

First let me thank you for reporting.

The function SDMMC_GetCmdError() is used to get the command error flags from the SDIO peripheral after a command has been sent to the eMMC card. The function returns a 32-bit value that represents the error flags for the last command that was sent.

If a pop-up error occurs in this function, it usually indicates that there was an error during the command transmission or response processing. This could be due to a variety of reasons, such as incorrect command parameters, improper initialization of the SDIO peripheral, or communication errors with the eMMC card itself.

To resolve the issue, you can try the following:

  1. Check the command parameters and ensure that they are correct for the eMMC card being used.

  2. Verify that the SDIO peripheral is properly initialized and configured for the eMMC card.

  3. Check the communication lines between the MCU and the eMMC card to ensure that there are no issues with the physical connection.

  4. Try using a different eMMC card to see if the issue is related to the card itself.

  5. Increase the timeout value for the command response to see if that resolves the issue.

  6. Check the SDIO interrupt status registers to see if there are any errors or interrupts that are being generated during the command transmission.

Thx

Ghofrane