Skip to content

Commit ea6c886

Browse files
STM32L4: Use HAL layer functions for sleep implementation
1 parent 97fef11 commit ea6c886

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

targets/TARGET_STM/sleep.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static void wait_loop(uint32_t timeout)
5252

5353

5454
// On L4 platforms we've seen unstable PLL CLK configuraiton
55-
// when DEEP SLEEP exits just few µs after being entered
55+
// when DEEP SLEEP exits just few µs after being entered
5656
// So we need to force MSI usage before setting clocks again
5757
static void ForcePeriphOutofDeepSleep(void)
5858
{
@@ -162,19 +162,10 @@ void hal_sleep(void)
162162
// [5.4.1 Power control register 1 (PWR_CR1)]
163163
// LPR: When this bit is set, the regulator is switched from main mode (MR) to low-power mode (LPR).
164164
int lowPowerMode = PWR->CR1 & PWR_CR1_LPR;
165-
166-
// LPR -> Run
167165
if (lowPowerMode) {
168-
HAL_PWREx_DisableLowPowerRunMode();
169-
}
170-
171-
// Entering Sleep mode [5.3.4 Sleep mode]
172-
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); // SLEEPDEEP = 0
173-
__WFI();
174-
175-
// Run -> LPR
176-
if (lowPowerMode) {
177-
HAL_PWREx_EnableLowPowerRunMode();
166+
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
167+
} else {
168+
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
178169
}
179170
#else
180171
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);

0 commit comments

Comments
 (0)