sources/common/libs/STM32Cube_F4/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_mmc.c
/**
  * @brief  Update the power class of the device.
  * @param  hmmc MMC handle
  * @param  Wide Wide of MMC bus
  * @param  Speed Speed of the MMC bus
  * @retval MMC Card error state
  */
@brief  Update the power class of the device.
@param  hmmc MMC handle
@param  Wide Wide of MMC bus
@param  Speed Speed of the MMC bus
@retval MMC Card error state
@brief Update the power class of the device . @param hmmc MMC handle @param Wide Wide of MMC bus @param Speed Speed of the MMC bus @retval MMC Card error state
static uint32_t MMC_PwrClassUpdate(MMC_HandleTypeDef *hmmc, uint32_t Wide)
{
  uint32_t count;
  uint32_t response = 0U;
  uint32_t errorstate = HAL_MMC_ERROR_NONE;
  uint32_t power_class, supported_pwr_class;
  if((Wide == SDIO_BUS_WIDE_8B) || (Wide == SDIO_BUS_WIDE_4B))
  {
    power_class = 0U; 
    if(MMC_ReadExtCSD(hmmc, &power_class, 187, SDMMC_DATATIMEOUT) != HAL_OK) 
    {
      errorstate = SDMMC_ERROR_GENERAL_UNKNOWN_ERR;
    }
    else
    {
      power_class = ((power_class >> 24U) & 0x000000FFU);
    }
    supported_pwr_class = ((hmmc->Ext_CSD[(MMC_EXT_CSD_PWR_CL_26_INDEX/4)] >> MMC_EXT_CSD_PWR_CL_26_POS) & 0x000000FFU);
    if(errorstate == HAL_MMC_ERROR_NONE)
    {
      if(Wide == SDIO_BUS_WIDE_8B)
      {
        supported_pwr_class = (supported_pwr_class >> 4U);
      }
      if ((power_class & 0x0FU) != (supported_pwr_class & 0x0FU))
      {
        errorstate = SDMMC_CmdSwitch(hmmc->Instance, (0x03BB0000U | ((supported_pwr_class & 0x0FU) << 8U)));
        if(errorstate == HAL_MMC_ERROR_NONE)
        {
          count = SDMMC_MAX_TRIAL;
          do
          {
            errorstate = SDMMC_CmdSendStatus(hmmc->Instance, (uint32_t)(((uint32_t)hmmc->MmcCard.RelCardAdd) << 16U));
            if(errorstate != HAL_MMC_ERROR_NONE)
            {
              break;
            }
            response = SDIO_GetResponse(hmmc->Instance, SDIO_RESP1);
            count--;
          }while(((response & 0x100U) == 0U) && (count != 0U));
          if ((count != 0U) && (errorstate == HAL_MMC_ERROR_NONE))
          {
            if ((response & 0x80U) != 0U)
            {
              errorstate = SDMMC_ERROR_UNSUPPORTED_FEATURE;
            }
          }
          else if (count == 0U)
          {
            errorstate = SDMMC_ERROR_TIMEOUT;
          }
          else
          {
          }
        }
      }
    }
  }
  return errorstate;
}
static uint32_t MMC_PwrClassUpdate ( MMC_HandleTypeDef * hmmc , uint32_t Wide ) { uint32_t count ; uint32_t response = 0U ; uint32_t errorstate = HAL_MMC_ERROR_NONE ; uint32_t power_class , supported_pwr_class ; if ( ( Wide == SDIO_BUS_WIDE_8B ) || ( Wide == SDIO_BUS_WIDE_4B ) ) { power_class = 0U ; if ( MMC_ReadExtCSD ( hmmc , & power_class , 187 , SDMMC_DATATIMEOUT ) != HAL_OK ) { errorstate = SDMMC_ERROR_GENERAL_UNKNOWN_ERR ; } else { power_class = ( ( power_class >> 24U ) & 0x000000FFU ) ; } supported_pwr_class = ( ( hmmc -> Ext_CSD [ ( MMC_EXT_CSD_PWR_CL_26_INDEX / 4 ) ] >> MMC_EXT_CSD_PWR_CL_26_POS ) & 0x000000FFU ) ; if ( errorstate == HAL_MMC_ERROR_NONE ) { if ( Wide == SDIO_BUS_WIDE_8B ) { supported_pwr_class = ( supported_pwr_class >> 4U ) ; } if ( ( power_class & 0x0FU ) != ( supported_pwr_class & 0x0FU ) ) { errorstate = SDMMC_CmdSwitch ( hmmc -> Instance , ( 0x03BB0000U | ( ( supported_pwr_class & 0x0FU ) << 8U ) ) ) ; if ( errorstate == HAL_MMC_ERROR_NONE ) { count = SDMMC_MAX_TRIAL ; do { errorstate = SDMMC_CmdSendStatus ( hmmc -> Instance , ( uint32_t ) ( ( ( uint32_t ) hmmc -> MmcCard . RelCardAdd ) << 16U ) ) ; if ( errorstate != HAL_MMC_ERROR_NONE ) { break ; } response = SDIO_GetResponse ( hmmc -> Instance , SDIO_RESP1 ) ; count -- ; } while ( ( ( response & 0x100U ) == 0U ) && ( count != 0U ) ) ; if ( ( count != 0U ) && ( errorstate == HAL_MMC_ERROR_NONE ) ) { if ( ( response & 0x80U ) != 0U ) { errorstate = SDMMC_ERROR_UNSUPPORTED_FEATURE ; } } else if ( count == 0U ) { errorstate = SDMMC_ERROR_TIMEOUT ; } else { } } } } } return errorstate ; }
@brief  Update the power class of the device.
@brief Update the power class of the device .
/* Default value after power-on or software reset */ /* Read the PowerClass field of the Extended CSD register */ /* Field POWER_CLASS [187] */ /* Get the supported PowerClass field of the Extended CSD register */ /* Field PWR_CL_26_xxx [201 or 203] */ /* Bit [7:4] : power class for 8-bits bus configuration - Bit [3:0] : power class for 4-bits bus configuration */ /* Need to change current power class */ /* While card is not ready for data and trial number for sending CMD13 is not exceeded */ /* Get command response */ /* Check the status after the switch command execution */ /* Check the bit SWITCH_ERROR of the device status */ /* Nothing to do */