Skip to content

Commit 232543a

Browse files
authored
Merge pull request ARMmbed#7813 from MSiglreithmaierRB/os_sleep_stm32l4
STM32L4: Fix sleep implementation
2 parents 6f338f8 + ea6c886 commit 232543a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

targets/TARGET_STM/sleep.c

Lines changed: 19 additions & 1 deletion
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
{
@@ -151,7 +151,25 @@ void hal_sleep(void)
151151
core_util_critical_section_enter();
152152

153153
// Request to enter SLEEP mode
154+
#if TARGET_STM32L4
155+
// State Transitions (see 5.3 Low-power modes, Fig. 13):
156+
// * (opt): Low Power Run (LPR) Mode -> Run Mode
157+
// * Run Mode -> Sleep
158+
// --- Wait for Interrupt --
159+
// * Sleep -> Run Mode
160+
// * (opt): Run Mode -> Low Power Run Mode
161+
162+
// [5.4.1 Power control register 1 (PWR_CR1)]
163+
// LPR: When this bit is set, the regulator is switched from main mode (MR) to low-power mode (LPR).
164+
int lowPowerMode = PWR->CR1 & PWR_CR1_LPR;
165+
if (lowPowerMode) {
166+
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
167+
} else {
168+
HAL_PWR_EnterSLEEPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFI);
169+
}
170+
#else
154171
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
172+
#endif
155173

156174
// Enable IRQs
157175
core_util_critical_section_exit();

0 commit comments

Comments
 (0)