/**
  * @brief  Deactivates 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_DisableOverDrive(void)
{
    uint32_t tickstart = 0;

    __HAL_RCC_PWR_CLK_ENABLE();

    /* Disable the Over-drive switch */
    __HAL_PWR_OVERDRIVESWITCHING_DISABLE();

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

    while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY)) {
        if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE) {
            return HAL_TIMEOUT;
        }
    }

    /* Disable the Over-drive */
    __HAL_PWR_OVERDRIVE_DISABLE();

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

    while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY)) {
        if((HAL_GetTick() - tickstart ) > PWR_OVERDRIVE_TIMEOUT_VALUE) {
            return HAL_TIMEOUT;
        }
    }

    return HAL_OK;
}
/**
 * @brief  Deactivates 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_DeactivateOverDrive(void)
{
	uint32_t timeout = 0;

	__PWR_CLK_ENABLE();

	/* Disable the Over-drive switch */
	__HAL_PWR_OVERDRIVESWITCHING_DISABLE();

	/* Get timeout */
	timeout = HAL_GetTick() + PWR_OVERDRIVE_TIMEOUT_VALUE;

	while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODSWRDY))
	{
		if(HAL_GetTick() >= timeout)
		{
			return HAL_TIMEOUT;
		}
	}

	/* Disable the Over-drive */
	__HAL_PWR_OVERDRIVE_DISABLE();

	/* Get timeout */
	timeout = HAL_GetTick() + PWR_OVERDRIVE_TIMEOUT_VALUE;

	while(__HAL_PWR_GET_FLAG(PWR_FLAG_ODRDY))
	{
		if(HAL_GetTick() >= timeout)
		{
			return HAL_TIMEOUT;
		}
	}

	return HAL_OK;
}