示例#1
0
/**
  * @brief  Activates the Over-Drive mode.
  * @note   This mode allows the CPU and the core logic to operate at a higher frequency
  *         than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).   
  * @note   It is recommended to enter or exit Over-drive mode when the application is not running 
  *         critical tasks and when the system clock source is either HSI or HSE. 
  *         During the Over-drive switch activation, no peripheral clocks should be enabled.   
  *         The peripheral clocks must be enabled once the Over-drive mode is activated.   
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_PWREx_EnableOverDrive(void)
{
  uint32_t tickstart = 0;

  __HAL_RCC_PWR_CLK_ENABLE();
  
  /* Enable the Over-drive to extend the clock frequency to 216 MHz */
  __HAL_PWR_OVERDRIVE_ENABLE();

  /* Get tick */
  tickstart = HAL_GetTick();

  while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
  {
    if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
    {
      return HAL_TIMEOUT;
    }
  }
  
  /* Enable the Over-drive switch */
  __HAL_PWR_OVERDRIVESWITCHING_ENABLE();

  /* Get tick */
  tickstart = HAL_GetTick();

  while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
  {
    if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE)
    {
      return HAL_TIMEOUT;
    }
  } 
  return HAL_OK;
}
/**
 * @brief  Activates the Over-Drive mode.
 * @note   These macros can be used only for STM32F42xx/STM32F43xx devices.
 *         This mode allows the CPU and the core logic to operate at a higher frequency
 *         than the normal mode for a given voltage scaling (scale 1, scale 2 or scale 3).   
 * @note   It is recommended to enter or exit Over-drive mode when the application is not running 
 *         critical tasks and when the system clock source is either HSI or HSE. 
 *         During the Over-drive switch activation, no peripheral clocks should be enabled.   
 *         The peripheral clocks must be enabled once the Over-drive mode is activated.   
 * @param  None
 * @retval HAL status
 */
HAL_StatusTypeDef HAL_PWREx_ActivateOverDrive(void)
{
	uint32_t timeout = 0;

	__PWR_CLK_ENABLE();

	/* Enable the Over-drive to extend the clock frequency to 180 Mhz */
	__HAL_PWR_OVERDRIVE_ENABLE();

	/* Get timeout */
	timeout = HAL_GetTick() + PWR_OVERDRIVE_TIMEOUT_VALUE;
	while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
	{
		if(HAL_GetTick() >= timeout)
		{
			return HAL_TIMEOUT;
		}
	}

	/* Enable the Over-drive switch */
	__HAL_PWR_OVERDRIVESWITCHING_ENABLE();

	/* Get timeout */
	timeout = HAL_GetTick() + PWR_OVERDRIVE_TIMEOUT_VALUE;
	while(!__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
	{
		if(HAL_GetTick() >= timeout)
		{
			return HAL_TIMEOUT;
		}
	}
	return HAL_OK;
}