sources/common/libs/STM32Cube_F4/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_mmc.c
/**
  * @brief  Enables wide bus operation for the requested card if supported by
  *         card.
  * @param  hmmc: Pointer to MMC handle
  * @param  WideMode: Specifies the MMC card wide bus mode
  *          This parameter can be one of the following values:
  *            @arg SDIO_BUS_WIDE_8B: 8-bit data transfer
  *            @arg SDIO_BUS_WIDE_4B: 4-bit data transfer
  *            @arg SDIO_BUS_WIDE_1B: 1-bit data transfer
  * @retval HAL status
  */
@brief  Enables wide bus operation for the requested card if supported by
card.
@brief Enables wide bus operation for the requested card if supported by card .
HAL_StatusTypeDef HAL_MMC_ConfigWideBusOperation(MMC_HandleTypeDef *hmmc, uint32_t WideMode)
{
  uint32_t count;
  SDIO_InitTypeDef Init;
  uint32_t errorstate;
  uint32_t response = 0U;
  assert_param(IS_SDIO_BUS_WIDE(WideMode));
  hmmc->State = HAL_MMC_STATE_BUSY;
  errorstate = MMC_PwrClassUpdate(hmmc, WideMode);
  if(errorstate == HAL_MMC_ERROR_NONE)
  {
    if(WideMode == SDIO_BUS_WIDE_8B)
    {
      errorstate = SDMMC_CmdSwitch(hmmc->Instance, 0x03B70200U);
    }
    else if(WideMode == SDIO_BUS_WIDE_4B)
    {
      errorstate = SDMMC_CmdSwitch(hmmc->Instance, 0x03B70100U);
    }
    else if(WideMode == SDIO_BUS_WIDE_1B)
    {
      errorstate = SDMMC_CmdSwitch(hmmc->Instance, 0x03B70000U);
    }
    else
    {
      errorstate = HAL_MMC_ERROR_PARAM;
    }
    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_GENERAL_UNKNOWN_ERR;
        }
        else
        {
          Init = hmmc->Init;
          Init.BusWide = WideMode;
          (void)SDIO_Init(hmmc->Instance, Init);
        }
      }
      else if (count == 0U)
      {
        errorstate = SDMMC_ERROR_TIMEOUT;
      }
      else
      {
      }
    }
  }
  hmmc->State = HAL_MMC_STATE_READY;
  if(errorstate != HAL_MMC_ERROR_NONE)
  {
    __HAL_MMC_CLEAR_FLAG(hmmc, SDMMC_STATIC_FLAGS);
    hmmc->ErrorCode |= errorstate;
    return HAL_ERROR;
  }
  return HAL_OK;
}
HAL_StatusTypeDef HAL_MMC_ConfigWideBusOperation ( MMC_HandleTypeDef * hmmc , uint32_t WideMode ) { uint32_t count ; SDIO_InitTypeDef Init ; uint32_t errorstate ; uint32_t response = 0U ; assert_param ( IS_SDIO_BUS_WIDE ( WideMode ) ) ; hmmc -> State = HAL_MMC_STATE_BUSY ; errorstate = MMC_PwrClassUpdate ( hmmc , WideMode ) ; if ( errorstate == HAL_MMC_ERROR_NONE ) { if ( WideMode == SDIO_BUS_WIDE_8B ) { errorstate = SDMMC_CmdSwitch ( hmmc -> Instance , 0x03B70200U ) ; } else if ( WideMode == SDIO_BUS_WIDE_4B ) { errorstate = SDMMC_CmdSwitch ( hmmc -> Instance , 0x03B70100U ) ; } else if ( WideMode == SDIO_BUS_WIDE_1B ) { errorstate = SDMMC_CmdSwitch ( hmmc -> Instance , 0x03B70000U ) ; } else { errorstate = HAL_MMC_ERROR_PARAM ; } 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_GENERAL_UNKNOWN_ERR ; } else { Init = hmmc -> Init ; Init . BusWide = WideMode ; ( void ) SDIO_Init ( hmmc -> Instance , Init ) ; } } else if ( count == 0U ) { errorstate = SDMMC_ERROR_TIMEOUT ; } else { } } } hmmc -> State = HAL_MMC_STATE_READY ; if ( errorstate != HAL_MMC_ERROR_NONE ) { __HAL_MMC_CLEAR_FLAG ( hmmc , SDMMC_STATIC_FLAGS ) ; hmmc -> ErrorCode |= errorstate ; return HAL_ERROR ; } return HAL_OK ; }
@brief  Enables wide bus operation for the requested card if supported by
         card.
@brief Enables wide bus operation for the requested card if supported by card .
/* Check the parameters */ /* Change State */ /* WideMode is not a valid argument*/ /* Check for switch error and violation of the trial number of sending CMD 13 */ /* 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 */ /* Configure the SDIO peripheral */ /* Nothing to do */ /* Change State */ /* Clear all the static flags */