Skip to content

Add pico_low_power library#2852

Merged
will-v-pi merged 132 commits into
raspberrypi:developfrom
will-v-pi:low-power-new
May 6, 2026
Merged

Add pico_low_power library#2852
will-v-pi merged 132 commits into
raspberrypi:developfrom
will-v-pi:low-power-new

Conversation

@will-v-pi

@will-v-pi will-v-pi commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

This adds a pico_low_power library, which allows going to sleep, dormant, and powman pstates.

Also adds bitsets and hardware_rosc, to support the low power stuff.

Includes a possible fix for #2420 to get the bazel rp2040 clang build working

Also requires raspberrypi/picotool#298 when putting persistent data in XIP SRAM

See low_power.h for documentation

will-v-pi added 15 commits March 6, 2026 15:29
Allows for much simpler custom linker scripts
…ript_var variables

Means that CMake doesn't need to know the default memory addresses for different platforms
…l files easier

Restructured so that it includes the platform-specific files before common ones, so common ones can be overridden
Use new include_linker_script_dir and use_linker_script_file functions to add the linker arguments
Breaking change for Bazel builds using different binary types, instead of setting PICO_DEFAULT_LINKER_SCRIPT to eg `//src/rp2_common/pico_crt0:no_flash_linker_script` it is now `//src/rp2_common/pico_standard_link:no_flash_linker_script`
Treat rp2040 layout (boot2 instead of embedded blocks) as the outlier

static inline generic_bitset_t *bitset_write_word(generic_bitset_t *bitset, uint word_num, uint32_t value) {
check_bitset(bitset);
if (word_num < bitset_word_size(bitset)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this raise an error if word_num >= bitset_word_size(bitset) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a question for @kilograham, but given that the other functions don't throw any errors when you attempt to pass a value that is outside the range and just return 0/do nothing, I think this one should also not throw an error?

Comment thread src/common/pico_util/include/pico/util/bitset.h Outdated
Comment thread src/common/pico_util/include/pico/util/bitset.h Outdated
Comment thread src/common/pico_util/include/pico/util/bitset.h Outdated
Comment thread src/rp2_common/hardware_clocks/include/hardware/clocks.h Outdated
Comment thread src/rp2_common/hardware_irq/include/hardware/irq.h
Comment thread src/rp2_common/hardware_irq/irq.c Outdated
Comment thread src/rp2_common/hardware_powman/include/hardware/powman.h Outdated
Comment thread src/rp2_common/hardware_rosc/include/hardware/rosc.h Outdated
Comment thread src/rp2_common/hardware_rosc/include/hardware/rosc.h Outdated
Comment thread src/rp2_common/hardware_rosc/include/hardware/rosc.h Outdated
Comment thread src/rp2_common/hardware_rosc/include/hardware/rosc.h Outdated
Comment thread src/rp2_common/hardware_rosc/rosc.c Outdated
Comment thread src/rp2_common/hardware_rosc/rosc.c Outdated
Comment thread src/rp2_common/hardware_rosc/rosc.c Outdated
@peterharperuk

Copy link
Copy Markdown
Contributor

Are you happy this is correct now? I can retest if you are.

Also increase powman_set_power_state timeout when waiting for POWMAN_STATE_WAITING_BITS, as it was sometimes timing out
This writes the calibrated frequency for the LPOSC to improve the accuracy, and switches it back to the default XOSC when waking up
It is unreliable, see RP2040-E10
@will-v-pi

Copy link
Copy Markdown
Contributor Author

Are you happy this is correct now? I can retest if you are.

Yes, I think I'm happy it's ready for retesting now

Comment thread src/rp2_common/pico_low_power/include/pico/low_power.h
Comment thread src/rp2_common/pico_low_power/include/pico/low_power.h Outdated
Comment thread src/rp2_common/pico_low_power/include/pico/low_power.h
Comment thread src/rp2_common/pico_low_power/include/pico/low_power.h
Comment thread src/rp2_common/hardware_rtc/rtc.c Outdated
peterharperuk
peterharperuk previously approved these changes Apr 27, 2026

@peterharperuk peterharperuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good now. Some examples here if anyone wants them https://github.com/peterharperuk/pico-examples/tree/low_power_examples

Also use low_power_start_aon_timer_at_time_ms in low power tests
…placed between bss and heap

Default section_persistent_data.incl now goes into RAM, and you need to override the file to put it at a specific address, to ensure HEAP_LOC is always set correctly in that case
Use external_sleep_timer to check sleeps are actually 2s, and use that instead of rtc_clksrc
The aon_timer test had an infinite while loop
Passes --no-clear arg when not clearing, rather than --clear when clearing, as older picotool doesn't have a --clear flag

This will break the build of low_power_test_timers_encrypted unless you use the xip-sram branch of picotool
@will-v-pi will-v-pi marked this pull request as ready for review April 29, 2026 16:06
@will-v-pi will-v-pi merged commit bfaf3cc into raspberrypi:develop May 6, 2026
7 checks passed
@will-v-pi will-v-pi deleted the low-power-new branch May 15, 2026 09:47
@will-v-pi will-v-pi restored the low-power-new branch May 15, 2026 09:49
@will-v-pi will-v-pi deleted the low-power-new branch May 15, 2026 09:49
Comment on lines +56 to +58
* \subsection sleep_example Example
* \addtogroup pico_sleep
* \include hello_sleep.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@will-v-pi Is this section correct? I've just tried building the latest Pico-C-SDK PDF, and I'm getting "5.8. pico_low_power" followed by "5.8.1. Example" (which is empty) followed by "5.9. Pico_sleep" (which is also empty) 😕

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that section is wrong - there are currently no pico_low_power examples, although Peter is writing some

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to say - I already fixed this (by removing it) in #2992 🙂

@peterharperuk

Copy link
Copy Markdown
Contributor

I think hello_sleep is in pico_extras?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants