diff --git a/libraries/SrcWrapper/src/stm32/low_power.c b/libraries/SrcWrapper/src/stm32/low_power.c index bb0de4af93..d353148551 100644 --- a/libraries/SrcWrapper/src/stm32/low_power.c +++ b/libraries/SrcWrapper/src/stm32/low_power.c @@ -223,12 +223,24 @@ void LowPower_stop(serial_t *obj) HAL_PWREx_EnableFastWakeUp(); #endif #ifdef __HAL_RCC_WAKEUPSTOP_CLK_CONFIG - /* Select HSI as system clock source after Wake Up from Stop mode */ + /* Select MSI or HSI as system clock source after Wake Up from Stop mode */ +#ifdef RCC_STOP_WAKEUPCLOCK_MSI + __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI); +#else __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI); +#endif #endif /* Enter Stop mode */ - HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); +#if defined(STM32L4xx) + if ((WakeUpUart == NULL) || (WakeUpUart->Instance == (USART_TypeDef *)LPUART1_BASE)) { + // STM32L4xx supports STOP2 mode which halves consumption + HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI); + } else +#endif + { + HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); + } /* Exit Stop mode reset clocks */ SystemClock_ConfigFromStop();