sources/common/libs/STM32Cube_F4/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_mmc.c
/**
  * @brief  Initializes the MMC Card.
  * @param  hmmc: Pointer to MMC handle
  * @note   This function initializes the MMC card. It could be used when a card
            re-initialization is needed.
  * @retval HAL status
  */
@brief  Initializes the MMC Card.
@param  hmmc: Pointer to MMC handle
@note   This function initializes the MMC card. It could be used when a card
re-initialization is needed.
@retval HAL status
@brief Initializes the MMC Card . @param hmmc : Pointer to MMC handle @note This function initializes the MMC card . It could be used when a card re - initialization is needed . @retval HAL status
HAL_StatusTypeDef HAL_MMC_InitCard(MMC_HandleTypeDef *hmmc)
{
  uint32_t errorstate;
  MMC_InitTypeDef Init;
  HAL_StatusTypeDef status;
  Init.ClockEdge           = SDIO_CLOCK_EDGE_RISING;
  Init.ClockBypass         = SDIO_CLOCK_BYPASS_DISABLE;
  Init.ClockPowerSave      = SDIO_CLOCK_POWER_SAVE_DISABLE;
  Init.BusWide             = SDIO_BUS_WIDE_1B;
  Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
  Init.ClockDiv            = SDIO_INIT_CLK_DIV;
  status = SDIO_Init(hmmc->Instance, Init);
  if(status == HAL_ERROR)
  {
    return HAL_ERROR;
  }
  __HAL_MMC_DISABLE(hmmc); 
  status = SDIO_PowerState_ON(hmmc->Instance);
  if(status == HAL_ERROR)
  {
    return HAL_ERROR;
  }
  __HAL_MMC_ENABLE(hmmc);
  HAL_Delay(2);
  errorstate = MMC_PowerON(hmmc);
  if(errorstate != HAL_MMC_ERROR_NONE)
  {
    hmmc->State = HAL_MMC_STATE_READY;
    hmmc->ErrorCode |= errorstate;
    return HAL_ERROR;
  }
  errorstate = MMC_InitCard(hmmc);
  if(errorstate != HAL_MMC_ERROR_NONE)
  {
    hmmc->State = HAL_MMC_STATE_READY;
    hmmc->ErrorCode |= errorstate;
    return HAL_ERROR;
  }
  errorstate = SDMMC_CmdBlockLength(hmmc->Instance, MMC_BLOCKSIZE);
  if(errorstate != HAL_MMC_ERROR_NONE)
  {
    __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS);
    hmmc->ErrorCode |= errorstate;
    hmmc->State = HAL_MMC_STATE_READY;
    return HAL_ERROR;
  }
  return HAL_OK;
}
HAL_StatusTypeDef HAL_MMC_InitCard ( MMC_HandleTypeDef * hmmc ) { uint32_t errorstate ; MMC_InitTypeDef Init ; HAL_StatusTypeDef status ; Init . ClockEdge = SDIO_CLOCK_EDGE_RISING ; Init . ClockBypass = SDIO_CLOCK_BYPASS_DISABLE ; Init . ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE ; Init . BusWide = SDIO_BUS_WIDE_1B ; Init . HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE ; Init . ClockDiv = SDIO_INIT_CLK_DIV ; status = SDIO_Init ( hmmc -> Instance , Init ) ; if ( status == HAL_ERROR ) { return HAL_ERROR ; } __HAL_MMC_DISABLE ( hmmc ) ; status = SDIO_PowerState_ON ( hmmc -> Instance ) ; if ( status == HAL_ERROR ) { return HAL_ERROR ; } __HAL_MMC_ENABLE ( hmmc ) ; HAL_Delay ( 2 ) ; errorstate = MMC_PowerON ( hmmc ) ; if ( errorstate != HAL_MMC_ERROR_NONE ) { hmmc -> State = HAL_MMC_STATE_READY ; hmmc -> ErrorCode |= errorstate ; return HAL_ERROR ; } errorstate = MMC_InitCard ( hmmc ) ; if ( errorstate != HAL_MMC_ERROR_NONE ) { hmmc -> State = HAL_MMC_STATE_READY ; hmmc -> ErrorCode |= errorstate ; return HAL_ERROR ; } errorstate = SDMMC_CmdBlockLength ( hmmc -> Instance , MMC_BLOCKSIZE ) ; if ( errorstate != HAL_MMC_ERROR_NONE ) { __HAL_MMC_CLEAR_FLAG ( hmmc , SDIO_STATIC_FLAGS ) ; hmmc -> ErrorCode |= errorstate ; hmmc -> State = HAL_MMC_STATE_READY ; return HAL_ERROR ; } return HAL_OK ; }
@brief  Initializes the MMC Card.
@brief Initializes the MMC Card .
/* Default SDIO peripheral configuration for MMC card initialization */ /* Initialize SDIO peripheral interface with default configuration */ /* Disable SDIO Clock */ /* Set Power State to ON */ /* Enable MMC Clock */ /* Required power up waiting time before starting the MMC initialization  sequence */ /* Identify card operating voltage */ /* Card initialization */ /* Set Block Size for Card */ /* Clear all the static flags */