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
  * @retval MMC Card error state
  */
@brief  Initializes the mmc card.
@param  hmmc: Pointer to MMC handle
@retval MMC Card error state
@brief Initializes the mmc card . @param hmmc : Pointer to MMC handle @retval MMC Card error state
static uint32_t MMC_InitCard(MMC_HandleTypeDef *hmmc)
{
  HAL_MMC_CardCSDTypeDef CSD;
  uint32_t errorstate;
  uint16_t mmc_rca = 2U;
  MMC_InitTypeDef Init;
  if(SDIO_GetPowerState(hmmc->Instance) == 0U)
  {
    return HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE;
  }
  errorstate = SDMMC_CmdSendCID(hmmc->Instance);
  if(errorstate != HAL_MMC_ERROR_NONE)
  {
    return errorstate;
  }
  else
  {
    hmmc->CID[0U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1);
    hmmc->CID[1U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP2);
    hmmc->CID[2U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP3);
    hmmc->CID[3U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP4);
  }
  errorstate = SDMMC_CmdSetRelAddMmc(hmmc->Instance, mmc_rca);
  if(errorstate != HAL_MMC_ERROR_NONE)
  {
    return errorstate;
  }
  hmmc->MmcCard.RelCardAdd = mmc_rca;
  errorstate = SDMMC_CmdSendCSD(hmmc->Instance, (uint32_t)(hmmc->MmcCard.RelCardAdd << 16U));
  if(errorstate != HAL_MMC_ERROR_NONE)
  {
    return errorstate;
  }
  else
  {
    hmmc->CSD[0U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1);
    hmmc->CSD[1U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP2);
    hmmc->CSD[2U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP3);
    hmmc->CSD[3U] = SDIO_GetResponse(hmmc->Instance, SDIO_RESP4);
  }
  hmmc->MmcCard.Class = (SDIO_GetResponse(hmmc->Instance, SDIO_RESP2) >> 20U);
  errorstate = SDMMC_CmdSelDesel(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
  if(errorstate != HAL_MMC_ERROR_NONE)
  {
    return errorstate;
  }
  if (HAL_MMC_GetCardCSD(hmmc, &CSD) != HAL_OK)
  {
    return hmmc->ErrorCode;
  }
  errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
  if(errorstate != HAL_MMC_ERROR_NONE)
  {
    hmmc->ErrorCode |= errorstate;
  }
  if (HAL_MMC_GetCardExtCSD(hmmc, hmmc->Ext_CSD, SDMMC_DATATIMEOUT) != HAL_OK)
  {
    return hmmc->ErrorCode;
  }
  errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
  if(errorstate != HAL_MMC_ERROR_NONE)
  {
    hmmc->ErrorCode |= errorstate;
  }
  Init = hmmc->Init;
  Init.BusWide = SDIO_BUS_WIDE_1B;
  (void)SDIO_Init(hmmc->Instance, Init);
  return HAL_MMC_ERROR_NONE;
}
static uint32_t MMC_InitCard ( MMC_HandleTypeDef * hmmc ) { HAL_MMC_CardCSDTypeDef CSD ; uint32_t errorstate ; uint16_t mmc_rca = 2U ; MMC_InitTypeDef Init ; if ( SDIO_GetPowerState ( hmmc -> Instance ) == 0U ) { return HAL_MMC_ERROR_REQUEST_NOT_APPLICABLE ; } errorstate = SDMMC_CmdSendCID ( hmmc -> Instance ) ; if ( errorstate != HAL_MMC_ERROR_NONE ) { return errorstate ; } else { hmmc -> CID [ 0U ] = SDIO_GetResponse ( hmmc -> Instance , SDIO_RESP1 ) ; hmmc -> CID [ 1U ] = SDIO_GetResponse ( hmmc -> Instance , SDIO_RESP2 ) ; hmmc -> CID [ 2U ] = SDIO_GetResponse ( hmmc -> Instance , SDIO_RESP3 ) ; hmmc -> CID [ 3U ] = SDIO_GetResponse ( hmmc -> Instance , SDIO_RESP4 ) ; } errorstate = SDMMC_CmdSetRelAddMmc ( hmmc -> Instance , mmc_rca ) ; if ( errorstate != HAL_MMC_ERROR_NONE ) { return errorstate ; } hmmc -> MmcCard . RelCardAdd = mmc_rca ; errorstate = SDMMC_CmdSendCSD ( hmmc -> Instance , ( uint32_t ) ( hmmc -> MmcCard . RelCardAdd << 16U ) ) ; if ( errorstate != HAL_MMC_ERROR_NONE ) { return errorstate ; } else { hmmc -> CSD [ 0U ] = SDIO_GetResponse ( hmmc -> Instance , SDIO_RESP1 ) ; hmmc -> CSD [ 1U ] = SDIO_GetResponse ( hmmc -> Instance , SDIO_RESP2 ) ; hmmc -> CSD [ 2U ] = SDIO_GetResponse ( hmmc -> Instance , SDIO_RESP3 ) ; hmmc -> CSD [ 3U ] = SDIO_GetResponse ( hmmc -> Instance , SDIO_RESP4 ) ; } hmmc -> MmcCard . Class = ( SDIO_GetResponse ( hmmc -> Instance , SDIO_RESP2 ) >> 20U ) ; errorstate = SDMMC_CmdSelDesel ( hmmc -> Instance , ( uint32_t ) ( ( ( uint32_t ) hmmc -> MmcCard . RelCardAdd ) << 16U ) ) ; if ( errorstate != HAL_MMC_ERROR_NONE ) { return errorstate ; } if ( HAL_MMC_GetCardCSD ( hmmc , & CSD ) != HAL_OK ) { return hmmc -> ErrorCode ; } errorstate = SDMMC_CmdSendStatus ( hmmc -> Instance , ( uint32_t ) ( ( ( uint32_t ) hmmc -> MmcCard . RelCardAdd ) << 16U ) ) ; if ( errorstate != HAL_MMC_ERROR_NONE ) { hmmc -> ErrorCode |= errorstate ; } if ( HAL_MMC_GetCardExtCSD ( hmmc , hmmc -> Ext_CSD , SDMMC_DATATIMEOUT ) != HAL_OK ) { return hmmc -> ErrorCode ; } errorstate = SDMMC_CmdSendStatus ( hmmc -> Instance , ( uint32_t ) ( ( ( uint32_t ) hmmc -> MmcCard . RelCardAdd ) << 16U ) ) ; if ( errorstate != HAL_MMC_ERROR_NONE ) { hmmc -> ErrorCode |= errorstate ; } Init = hmmc -> Init ; Init . BusWide = SDIO_BUS_WIDE_1B ; ( void ) SDIO_Init ( hmmc -> Instance , Init ) ; return HAL_MMC_ERROR_NONE ; }
@brief  Initializes the mmc card.
@brief Initializes the mmc card .
/* Check the power State */ /* Power off */ /* Send CMD2 ALL_SEND_CID */ /* Get Card identification number data */ /* Send CMD3 SET_REL_ADDR with RCA = 2 (should be greater than 1) */ /* MMC Card publishes its RCA. */ /* Get the MMC card RCA */ /* Send CMD9 SEND_CSD with argument as card's RCA */ /* Get Card Specific Data */ /* Get the Card Class */ /* Select the Card */ /* Get CSD parameters */ /* While card is not ready for data and trial number for sending CMD13 is not exceeded */ /* Get Extended CSD parameters */ /* While card is not ready for data and trial number for sending CMD13 is not exceeded */ /* Configure the SDIO peripheral */ /* All cards are initialized */