low_power_go_pstate(): error returns leave interrupts disabled and USB deinitialised
Maintainers usually reply within 6 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 66/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c
- Domain
- embedded-iot
Research direction
Read src/rp2_common/pico_low_power/low_power.c, starting with low_power_go_pstate() and the preparation and error paths described in the issue. Trace what state each failing call changes and how it can be restored before returning. Done means both error paths leave interrupts, USB, and powman settings in a safe state; the issue does not name a test to run.
Written by the indexing model from the issue text.
Description
Summary
low_power_go_pstate(), behind low_power_pstate_until_aon_timer() and
low_power_pstate_until_gpio_pin_state(), first calls prepare_for_pstate_change() and then
has two error returns. Neither undoes the preparation. The caller gets an error code with
interrupts disabled, TinyUSB and USB stdio deinitialised, and the powman settings changed
(debug power request ignored, timer tick on LPOSC, VREG unlocked). Both functions are
documented as "0 on success, non-zero on error", so a caller would reasonably carry on after
an error.
Environment
pico-sdk 2.3.1, RP2350. The code is the same on master and develop as of today; #3192
changes this function but not these paths. Found by reading the code, not observed on
hardware.
Code (src/rp2_common/pico_low_power/low_power.c, 2.3.1)
- L715:
prepare_for_pstate_change(), which callsprepare_for_clock_switch()(L77-98):
tud_deinit()/tuh_deinit()if they were initialised,stdio_usb_deinit(), then
interrupt_flags = save_and_disable_interrupts();. After that come the powman changes
(L119-127). - L722:
return PICO_ERROR_INVALID_STATE;whenpowman_configure_wakeup_state()fails. - L738:
return rc;whenpowman_set_power_state()fails. post_pstate_change()(L129-130) is empty, so calling it on these paths would not undo
anything either.
https://github.com/raspberrypi/pico-sdk/blob/2.3.1/src/rp2_common/pico_low_power/low_power.c#L708-L748
https://github.com/raspberrypi/pico-sdk/blob/2.3.1/src/rp2_common/pico_low_power/low_power.c#L77-L130
Suggested fix
If possible, do the checks that can fail before prepare_for_pstate_change(). Otherwise give
both error paths an undo: post_clock_switch() (it restores the interrupts and re-initialises
TinyUSB and USB stdio) plus reverting the powman changes. post_pstate_change() would be the
natural place for that.
Minor
interrupt_flags (L67) and irq_mask_disabled_during_sleep (L199) are single static slots
shared by both cores. The saved state is only right while one core at a time uses the API,
which may be worth a note in the documentation.
Related
#3298: the same kind of fault in flash_safe_execute(), where a nested call returns with
interrupts disabled and no error.
- 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 76/100
raspberrypi/pico-sdk#3300 ·
Maintainers usually reply within 6 days
-
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
All issues in raspberrypi/pico-sdk
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
slice
Difficulty 2/5 Under an hour Newbie friendliness 72/100
Life-Framework/Life-Framework#3465 ·
Maintainers usually reply within 1 day