sources/common/libs/STM32Cube_F4/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_mmc.c
/**
  * @brief  Returns information the information of the card which are stored on
  *         the Extended CSD register.
  * @param  hmmc Pointer to MMC handle
  * @param  pExtCSD Pointer to a memory area (512 bytes) that contains all 
  *         Extended CSD register parameters
  * @param  Timeout Specify timeout value
  * @retval HAL status
  */
@brief  Returns information the information of the card which are stored on
the Extended CSD register.
@param  hmmc Pointer to MMC handle
@param  pExtCSD Pointer to a memory area (512 bytes) that contains all
Extended CSD register parameters
@param  Timeout Specify timeout value
@retval HAL status
@brief Returns information the information of the card which are stored on the Extended CSD register . @param hmmc Pointer to MMC handle @param pExtCSD Pointer to a memory area ( 512 bytes ) that contains all Extended CSD register parameters @param Timeout Specify timeout value @retval HAL status
HAL_StatusTypeDef HAL_MMC_GetCardExtCSD(MMC_HandleTypeDef *hmmc, uint32_t *pExtCSD, uint32_t Timeout)
{
  SDIO_DataInitTypeDef config;
  uint32_t errorstate;
  uint32_t tickstart = HAL_GetTick();
  uint32_t count;
  uint32_t *tmp_buf;
  if(NULL == pExtCSD)
  {
    hmmc->ErrorCode |= HAL_MMC_ERROR_PARAM;
    return HAL_ERROR;
  }
  if(hmmc->State == HAL_MMC_STATE_READY)
  {
    hmmc->ErrorCode = HAL_MMC_ERROR_NONE;
    hmmc->State = HAL_MMC_STATE_BUSY;
    hmmc->Instance->DCTRL = 0;
    tmp_buf = pExtCSD;
    config.DataTimeOut   = SDMMC_DATATIMEOUT;
    config.DataLength    = 512;
    config.DataBlockSize = SDIO_DATABLOCK_SIZE_512B;
    config.TransferDir   = SDIO_TRANSFER_DIR_TO_SDIO;
    config.TransferMode  = SDIO_TRANSFER_MODE_BLOCK;
    config.DPSM          = SDIO_DPSM_ENABLE;
    (void)SDIO_ConfigData(hmmc->Instance, &config);
    errorstate = SDMMC_CmdSendEXTCSD(hmmc->Instance, 0);
    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;
    }
    while(!__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DATAEND))
    {
      if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXFIFOHF))
      {
        for(count = 0U; count < 8U; count++)
        {
          *tmp_buf = SDIO_ReadFIFO(hmmc->Instance);
          tmp_buf++;
        }
      }
      if(((HAL_GetTick()-tickstart) >=  Timeout) || (Timeout == 0U))
      {
        __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS);
        hmmc->ErrorCode |= HAL_MMC_ERROR_TIMEOUT;
        hmmc->State= HAL_MMC_STATE_READY;
        return HAL_TIMEOUT;
      }
    }
    if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DTIMEOUT))
    {
      __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS);
      hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_TIMEOUT;
      hmmc->State = HAL_MMC_STATE_READY;
      return HAL_ERROR;
    }
    else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_DCRCFAIL))
    {
      __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS);
      hmmc->ErrorCode |= HAL_MMC_ERROR_DATA_CRC_FAIL;
      hmmc->State = HAL_MMC_STATE_READY;
      return HAL_ERROR;
    }
    else if(__HAL_MMC_GET_FLAG(hmmc, SDIO_FLAG_RXOVERR))
    {
      __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_FLAGS);
      hmmc->ErrorCode |= HAL_MMC_ERROR_RX_OVERRUN;
      hmmc->State = HAL_MMC_STATE_READY;
      return HAL_ERROR;
    }
    else
    {
    }
    __HAL_MMC_CLEAR_FLAG(hmmc, SDIO_STATIC_DATA_FLAGS);
    hmmc->State = HAL_MMC_STATE_READY;
  }
  return HAL_OK;
}
HAL_StatusTypeDef HAL_MMC_GetCardExtCSD ( MMC_HandleTypeDef * hmmc , uint32_t * pExtCSD , uint32_t Timeout ) { SDIO_DataInitTypeDef config ; uint32_t errorstate ; uint32_t tickstart = HAL_GetTick ( ) ; uint32_t count ; uint32_t * tmp_buf ; if ( NULL == pExtCSD ) { hmmc -> ErrorCode |= HAL_MMC_ERROR_PARAM ; return HAL_ERROR ; } if ( hmmc -> State == HAL_MMC_STATE_READY ) { hmmc -> ErrorCode = HAL_MMC_ERROR_NONE ; hmmc -> State = HAL_MMC_STATE_BUSY ; hmmc -> Instance -> DCTRL = 0 ; tmp_buf = pExtCSD ; config . DataTimeOut = SDMMC_DATATIMEOUT ; config . DataLength = 512 ; config . DataBlockSize = SDIO_DATABLOCK_SIZE_512B ; config . TransferDir = SDIO_TRANSFER_DIR_TO_SDIO ; config . TransferMode = SDIO_TRANSFER_MODE_BLOCK ; config . DPSM = SDIO_DPSM_ENABLE ; ( void ) SDIO_ConfigData ( hmmc -> Instance , & config ) ; errorstate = SDMMC_CmdSendEXTCSD ( hmmc -> Instance , 0 ) ; 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 ; } while ( ! __HAL_MMC_GET_FLAG ( hmmc , SDIO_FLAG_RXOVERR | SDIO_FLAG_DCRCFAIL | SDIO_FLAG_DTIMEOUT | SDIO_FLAG_DATAEND ) ) { if ( __HAL_MMC_GET_FLAG ( hmmc , SDIO_FLAG_RXFIFOHF ) ) { for ( count = 0U ; count < 8U ; count ++ ) { * tmp_buf = SDIO_ReadFIFO ( hmmc -> Instance ) ; tmp_buf ++ ; } } if ( ( ( HAL_GetTick ( ) - tickstart ) >= Timeout ) || ( Timeout == 0U ) ) { __HAL_MMC_CLEAR_FLAG ( hmmc , SDIO_STATIC_FLAGS ) ; hmmc -> ErrorCode |= HAL_MMC_ERROR_TIMEOUT ; hmmc -> State = HAL_MMC_STATE_READY ; return HAL_TIMEOUT ; } } if ( __HAL_MMC_GET_FLAG ( hmmc , SDIO_FLAG_DTIMEOUT ) ) { __HAL_MMC_CLEAR_FLAG ( hmmc , SDIO_STATIC_FLAGS ) ; hmmc -> ErrorCode |= HAL_MMC_ERROR_DATA_TIMEOUT ; hmmc -> State = HAL_MMC_STATE_READY ; return HAL_ERROR ; } else if ( __HAL_MMC_GET_FLAG ( hmmc , SDIO_FLAG_DCRCFAIL ) ) { __HAL_MMC_CLEAR_FLAG ( hmmc , SDIO_STATIC_FLAGS ) ; hmmc -> ErrorCode |= HAL_MMC_ERROR_DATA_CRC_FAIL ; hmmc -> State = HAL_MMC_STATE_READY ; return HAL_ERROR ; } else if ( __HAL_MMC_GET_FLAG ( hmmc , SDIO_FLAG_RXOVERR ) ) { __HAL_MMC_CLEAR_FLAG ( hmmc , SDIO_STATIC_FLAGS ) ; hmmc -> ErrorCode |= HAL_MMC_ERROR_RX_OVERRUN ; hmmc -> State = HAL_MMC_STATE_READY ; return HAL_ERROR ; } else { } __HAL_MMC_CLEAR_FLAG ( hmmc , SDIO_STATIC_DATA_FLAGS ) ; hmmc -> State = HAL_MMC_STATE_READY ; } return HAL_OK ; }
@brief  Returns information the information of the card which are stored on
         the Extended CSD register.
@brief Returns information the information of the card which are stored on the Extended CSD register .
/* Initialize data control register */ /* Initiaize the destination pointer */ /* Configure the MMC DPSM (Data Path State Machine) */ /* Send ExtCSD Read command to Card */ /* Clear all the static flags */ /* Poll on SDMMC flags */ /* Read data from SDMMC Rx FIFO */ /* Clear all the static flags */ /* Get error state */ /* Clear all the static flags */ /* Clear all the static flags */ /* Clear all the static flags */ /* Nothing to do */ /* Clear all the static flags */