pico_low_power: low_power_dormant_* return with SCR.SLEEPDEEP still set (later WFI/WFE is a deep sleep, SysTick stops)
Maintainers usually reply within 6 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c
- Domain
- embedded-iot
Research direction
Start by reading low_power_wake_from_dormant() and the dormant and sleep paths in the low power implementation; the issue identifies the missing deep sleep disable call and notes that the sleep path already clears it. Check how the helper handles Arm and RISC-V, then verify that dormant wake clears the deep sleep state and later sleeps retain normal behavior. The issue provides a minimal RP2350 Arm repro and expected SCR and SysTick readings.
Written by the indexing model from the issue text.
Description
What
low_power_dormant_until_aon_timer() and low_power_dormant_until_gpio_pin_state() call low_power_enable_processor_deep_sleep() (sets SCR.SLEEPDEEP; RISC-V: MSLEEP.DEEPSLEEP / POWERDOWN) before going dormant, and low_power_wake_from_dormant() restores the oscillator, the clock sleep-enables (post_clock_gating()) and the clocks (runtime_init_clocks()), but nothing calls low_power_disable_processor_deep_sleep(). The low_power_sleep_* functions do (right after their __wfi()), so only the dormant paths leave the bit set. After a dormant call returns, SCR.SLEEPDEEP is still 1 until the next reset, so every later WFI / WFE on that core is a deep sleep.
Why it matters
On the RP2350 (Arm) the core stops the clock SysTick counts during such a sleep, so SysTick stops whenever the core sleeps. Measured on a Pico 2 W: a free-running SysTick (processor clock, 24 bit) counted 10 us during a 50 ms sleep_ms(50) after low_power_dormant_for_ms() / low_power_dormant_until_gpio_pin_state(), against 50000 us before any dormant call (about 204 us in a USB build); sleep_ms(), a __wfi() loop on a repeating timer and blocking multicore queue pops still wake on time, so a plain sketch usually does not notice. Anything that uses SysTick as a time base does: FreeRTOS (the idle task sleeps with WFI, the kernel tick never runs again after a dormant wake: vTaskDelay() never returns), or user code. SCR reads 0x4 after the dormant calls and 0x0 after the sleep calls.
Minimal repro (SDK only, RP2350 Arm; not built as written, the same checks were measured in an Arduino sketch)
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/low_power.h"
#include "hardware/structs/scb.h"
#define SYST_CSR (*(volatile uint32_t *)0xe000e010)
#define SYST_RVR (*(volatile uint32_t *)0xe000e014)
#define SYST_CVR (*(volatile uint32_t *)0xe000e018)
// microseconds a free-running SysTick counts during sleep_ms(50): about 50000 if it runs through the sleep
static uint32_t systick_us_in_sleep(void) {
SYST_CSR = 0; SYST_RVR = 0xFFFFFF; SYST_CVR = 0; SYST_CSR = 5; // enable, processor clock, no interrupt
uint32_t c0 = SYST_CVR;
sleep_ms(50);
uint32_t c1 = SYST_CVR;
SYST_CSR = 0;
return ((c0 - c1) & 0xFFFFFF) / (clock_get_hz(clk_sys) / 1000000);
}
int main(void) {
stdio_init_all();
sleep_ms(3000);
printf("before: SCR=0x%x, SysTick during sleep_ms(50): %u us\n", (unsigned)scb_hw->scr, (unsigned)systick_us_in_sleep());
low_power_dormant_for_ms(1000, DORMANT_CLOCK_SOURCE_LPOSC, NULL); // RP2040: low_power_dormant_until_gpio_pin_state(pin, ...) instead
sleep_ms(3000); // USB stdio comes back
printf("after: SCR=0x%x, SysTick during sleep_ms(50): %u us\n", (unsigned)scb_hw->scr, (unsigned)systick_us_in_sleep());
}
Expected: SCR = 0x0 and about 50000 us both times. Observed (measured with the equivalent Arduino sketch, NO_USB): SCR 0x0 / 49999 us before, SCR 0x4 / 10 us after.
Suggested fix
One line in the dormant wake path, low_power_wake_from_dormant() (or after the low_power_go_dormant() call in both dormant functions): low_power_disable_processor_deep_sleep(); (it is defined above, and already handles RISC-V).
Notes
arduino-pico's LowPower library (a wrapper over pico_low_power) works around it by clearing the bit in its own wake path (https://github.com/earlephilhower/arduino-pico/pull/3633, merged); the report is so the SDK itself does not leave the core in deep-sleep mode. Not tested: RP2040 hardware (same SDK code and bit), the RISC-V cores beyond reading the code.
Disclosure: this issue was written with the help of Claude (Anthropic's AI assistant), which found the leftover while making LowPower work under FreeRTOS and ran the measurements on my bench under my direction; I'll answer for it.
- Dominant language
- C
- Stars
- 5k
- Forks
- 1.3k
- Avg merge
- 12d 19h
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from raspberrypi/pico-sdk
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
raspberrypi/pico-sdk#3292 ·
Maintainers usually reply within 6 days
-
Add masked GPIO pull configuration APIsPossibly taken A pull request linked to this issue is open or already merged. Openhardware_gpio
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
raspberrypi/pico-sdk#3279 ·
Maintainers usually reply within 6 days
-
hardware_pll doxygen doesn't mention RP2350Possibly taken A pull request linked to this issue is open or already merged. Opendocumentation
Difficulty 1/5 Under an hour Newbie friendliness 91/100
raspberrypi/pico-sdk#3277 ·
Maintainers usually reply within 6 days
-
multicore_lockout_handler calling non-inlined multicore_fifo_push_blocking_inlinePossibly taken @Wooohaaa claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
raspberrypi/pico-sdk#3225 · 2 comments ·
Maintainers usually reply within 6 days
-
pioasm: support set x -1Possibly taken A pull request linked to this issue is open or already merged. Openpioasm
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
raspberrypi/pico-sdk#3205 · 2 comments ·
Maintainers usually reply within 6 days
All issues in raspberrypi/pico-sdk
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
LedgerHQ/app-bitcoin-legacy#306 ·
-
[issue]: Ventoy2Disk.sh can leave the end of VTOYEFI unwritten (xzcat | dd without iflag=fullblock)Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
prusa3d/Prusa-Firmware-Buddy#5629 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 3 days
-
Issue PRL on WindowsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day