diff options
Diffstat (limited to 'chip/stm32/clock-stm32f4.c')
-rw-r--r-- | chip/stm32/clock-stm32f4.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/chip/stm32/clock-stm32f4.c b/chip/stm32/clock-stm32f4.c index 87e4fe061b..a50f5f51dd 100644 --- a/chip/stm32/clock-stm32f4.c +++ b/chip/stm32/clock-stm32f4.c @@ -435,6 +435,8 @@ static int dsleep_recovery_margin_us = 1000000; /* STOP_MODE_LATENCY: delay to wake up from STOP mode with main regulator off */ #define STOP_MODE_LATENCY 50 /* us */ +/* PLL_LOCK_LATENCY: delay to switch from HSI to PLL */ +#define PLL_LOCK_LATENCY 150 /* us */ /* * SET_RTC_MATCH_DELAY: max time to set RTC match alarm. If we set the alarm * in the past, it will never wake up and cause a watchdog. @@ -466,7 +468,8 @@ void __idle(void) next_delay = __hw_clock_event_get() - t0.le.lo; if (DEEP_SLEEP_ALLOWED && - (next_delay > (STOP_MODE_LATENCY + SET_RTC_MATCH_DELAY))) { + (next_delay > (STOP_MODE_LATENCY + PLL_LOCK_LATENCY + + SET_RTC_MATCH_DELAY))) { /* Deep-sleep in STOP mode */ idle_dsleep_cnt++; @@ -478,8 +481,15 @@ void __idle(void) /* Set deep sleep bit */ CPU_SCB_SYSCTRL |= 0x4; - set_rtc_alarm(0, next_delay - STOP_MODE_LATENCY, + set_rtc_alarm(0, next_delay - STOP_MODE_LATENCY + - PLL_LOCK_LATENCY, &rtc0, 0); + + /* Switch to HSI */ + clock_switch_osc(OSC_HSI); + /* Turn off the PLL1 to save power */ + clock_enable_osc(OSC_PLL, false); + /* ensure outstanding memory transactions complete */ asm volatile("dsb"); @@ -487,6 +497,11 @@ void __idle(void) CPU_SCB_SYSCTRL &= ~0x4; + /* turn on PLL and wait until it's ready */ + clock_enable_osc(OSC_PLL, true); + /* Switch to PLL */ + clock_switch_osc(OSC_PLL); + /*uart_enable_wakeup(0);*/ /* Fast forward timer according to RTC counter */ |