3.4. How to improve the wake-up from Stop sequences without relying on the global SystemClock_Config() ¶
The
SystemClock_Config
provided in the HAL examples is intended to be used to configure the system clock at startup. It is not recommended to use it to restore the clock settings after a Stop mode.
To keep the wake-up as quick as possible, it is highly recommended to restore only what has been changed by the hardware to enter the Low-power mode. This is typically the case for the oscillators and system clock sources. The RCC configuration registers are unchanged, and there is no need to restore them.
Typically, after a Stop mode, it is recommended to call a separate
SystemClockConfig_STOP
after the wake-up that enables the LSE and PLL, and selects PLL as system clock source (LSE and PLL are disabled in Stop mode). Find below an example of
SystemClockConfig_STOP
(provided in the HID_Standalone_LPM application):
static void SystemClockConfig_STOP(void)
{
#if defined (USB_USE_LSE_MSI_CLOCK)
/* Configures system clock after wake-up from STOP: enable LSE,
PLL and select PLL as system clock source (LSE and PLL are disabled in Stop mode) */
__HAL_RCC_LSE_CONFIG(RCC_LSE_ON);
/* Wait till HSE is ready */
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
{}
/* Enable the main PLL. */
__HAL_RCC_PLL_ENABLE();
/* Wait till PLL is ready */
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
{}
/* Select PLL as SYSCLK */
MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_SYSCLKSOURCE_PLLCLK);
/* Wait till system clock switch to PLL */
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
{}
#elif defined (USB_USE_HSE_CLOCK)
/* Configures system clock after wake-up from STOP: enable HSE,
PLL and select PLL as system clock source (HSE and PLL are disabled in Stop mode) */
__HAL_RCC_HSE_CONFIG(RCC_HSE_ON);
/* Wait till HSE is ready */
while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY) == RESET)
{}
/* Enable the main PLL. */
__HAL_RCC_PLL_ENABLE();
/* Wait till PLL is ready */
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
{}
/* Select PLL as SYSCLK */
MODIFY_REG(RCC->CFGR, RCC_CFGR_SW, RCC_SYSCLKSOURCE_PLLCLK);
/* Wait till system clock switch to PLL */
while (__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_CFGR_SWS_PLL)
{}
#endif /* USB_USE_LSE_MSI_CLOCK */
}