kopia lustrzana https://github.com/raspberrypi/pico-extras
Fixes hanging on sleep_ms() after deep sleep
As documented in this repo for example: https://github.com/ghubcoder/PicoSleepDemopull/83/head
rodzic
2267457e26
commit
98cca31ed1
|
@ -107,18 +107,27 @@ void sleep_goto_sleep_until(datetime_t *t, rtc_callback_t callback) {
|
|||
// We should have already called the sleep_run_from_dormant_source function
|
||||
assert(dormant_source_valid(_dormant_source));
|
||||
|
||||
// Save these register states to be able to restore afer waking up:
|
||||
uint clock0_orig = clocks_hw->sleep_en0;
|
||||
uint clock1_orig = clocks_hw->sleep_en1;
|
||||
uint save = scb_hw->scr;
|
||||
|
||||
// Turn off all clocks when in sleep mode except for RTC
|
||||
clocks_hw->sleep_en0 = CLOCKS_SLEEP_EN0_CLK_RTC_RTC_BITS;
|
||||
clocks_hw->sleep_en1 = 0x0;
|
||||
|
||||
rtc_set_alarm(t, callback);
|
||||
|
||||
uint save = scb_hw->scr;
|
||||
// Enable deep sleep at the proc
|
||||
scb_hw->scr = save | M0PLUS_SCR_SLEEPDEEP_BITS;
|
||||
|
||||
// Go to sleep
|
||||
__wfi();
|
||||
|
||||
// If these registers are not restored, any __wfi() will take the proc to deep sleep! (Any sleep_ms() for example.)
|
||||
clocks_hw->sleep_en0 = clock0_orig;
|
||||
clocks_hw->sleep_en1 = clock1_orig;
|
||||
scb_hw->scr = save;
|
||||
}
|
||||
|
||||
static void _go_dormant(void) {
|
||||
|
|
Ładowanie…
Reference in New Issue