stm32/modmachine: Get machine.sleep working on L4 MCUs.
When waking from stop mode most of the system is still in the same state as before entering stop, so only minimal configuration is needed to bring the system clock back online.
This commit is contained in:
parent
c12348700f
commit
5482d84673
@ -483,35 +483,11 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 4, machine_freq);
|
|||||||
|
|
||||||
STATIC mp_obj_t machine_sleep(void) {
|
STATIC mp_obj_t machine_sleep(void) {
|
||||||
#if defined(STM32L4)
|
#if defined(STM32L4)
|
||||||
|
// Configure the MSI as the clock source after waking up
|
||||||
// Enter Stop 1 mode
|
|
||||||
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI);
|
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI);
|
||||||
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
|
#endif
|
||||||
|
|
||||||
// reconfigure system clock after wakeup
|
#if !defined(STM32F0) && !defined(STM32L4)
|
||||||
// Enable Power Control clock
|
|
||||||
__HAL_RCC_PWR_CLK_ENABLE();
|
|
||||||
|
|
||||||
// Get the Oscillators configuration according to the internal RCC registers
|
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
|
||||||
HAL_RCC_GetOscConfig(&RCC_OscInitStruct);
|
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
|
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
||||||
HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
|
||||||
|
|
||||||
// Get the Clocks configuration according to the internal RCC registers
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
|
||||||
uint32_t pFLatency = 0;
|
|
||||||
HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &pFLatency);
|
|
||||||
|
|
||||||
// Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clock dividers
|
|
||||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
|
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
||||||
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, pFLatency);
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#if !defined(STM32F0)
|
|
||||||
// takes longer to wake but reduces stop current
|
// takes longer to wake but reduces stop current
|
||||||
HAL_PWREx_EnableFlashPowerDown();
|
HAL_PWREx_EnableFlashPowerDown();
|
||||||
#endif
|
#endif
|
||||||
@ -538,10 +514,12 @@ STATIC mp_obj_t machine_sleep(void) {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#if !defined(STM32L4)
|
||||||
// enable HSE
|
// enable HSE
|
||||||
__HAL_RCC_HSE_CONFIG(MICROPY_HW_CLK_HSE_STATE);
|
__HAL_RCC_HSE_CONFIG(MICROPY_HW_CLK_HSE_STATE);
|
||||||
while (!__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY)) {
|
while (!__HAL_RCC_GET_FLAG(RCC_FLAG_HSERDY)) {
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// enable PLL
|
// enable PLL
|
||||||
__HAL_RCC_PLL_ENABLE();
|
__HAL_RCC_PLL_ENABLE();
|
||||||
@ -559,8 +537,6 @@ STATIC mp_obj_t machine_sleep(void) {
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
MP_DEFINE_CONST_FUN_OBJ_0(machine_sleep_obj, machine_sleep);
|
MP_DEFINE_CONST_FUN_OBJ_0(machine_sleep_obj, machine_sleep);
|
||||||
|
Loading…
Reference in New Issue
Block a user