Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions targets/TARGET_STM/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,22 @@ void hal_deepsleep(void)

// Request to enter STOP mode with regulator in low power mode
#if TARGET_STM32L4
if (__HAL_RCC_PWR_IS_CLK_ENABLED()) {
HAL_PWREx_EnableLowPowerRunMode();
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
HAL_PWREx_DisableLowPowerRunMode();
} else {
int pwrClockEnabled = __HAL_RCC_PWR_IS_CLK_ENABLED();
int lowPowerModeEnabled = PWR->CR1 & PWR_CR1_LPR;

if (!pwrClockEnabled) {
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWREx_EnableLowPowerRunMode();
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
}
if (lowPowerModeEnabled) {
HAL_PWREx_DisableLowPowerRunMode();
}

HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

if (lowPowerModeEnabled) {
HAL_PWREx_EnableLowPowerRunMode();
}
if (!pwrClockEnabled) {
__HAL_RCC_PWR_CLK_DISABLE();
}
#else /* TARGET_STM32L4 */
Expand Down