2.11. Power Control
RP2040 provides a range of options for reducing dynamic power:
- • Top-level clock gating of individual peripherals and functional blocks
- • Automatic control of top-level clock gates based on processor sleep state
- • On-the-fly changes to system clock frequency or system clock source (e.g. switch to internal ring oscillator, and disable PLLs and crystal oscillator)
- • Zero-dynamic-power DORMANT state, waking on GPIO event or RTC IRQ
All digital logic on RP2040 is in a single core power domain. The following options are available for static power reduction:
- • Placing memories into state-retaining power down state
- • Power gating on peripherals that support this, e.g. ADC, temperature sensor
2.11.1. Top-level Clock Gates
Each clock domain (for example, the system clock) may drive a large number of distinct hardware blocks, not all of which may be required at once. To avoid unnecessary power dissipation, each individual endpoint of each clock (for example, the UART system clock input) may be disabled at any time.
Enabling and disabling a clock gate is glitch-free. If a peripheral clock is temporarily disabled, and subsequently re-enabled, the peripheral will be in the same state as prior to the clock being disabled. No reset or reinitialisation should be required.
Clock gates are controlled by two sets of registers: the WAKE_ENx registers (starting at WAKE_EN0 ) and SLEEP_ENx registers (starting at SLEEP_EN0 ). These two sets of registers are identical at the bit level, each possessing a flag to control each clock endpoint. The WAKE_EN registers specify which clocks are enabled whilst the system is awake, and the SLEEP_ENx registers select which clocks are enabled while the processor is in the SLEEP state ( Section 2.11.2 ).
The two Cortex-M0+ processors do not have externally-controllable clock gates. Instead, the processors gate the clocks of their subsystems autonomously, based on execution of WFI / WFE instructions, and external Event and IRQ signals.
2.11.2. SLEEP State
RP2040 enters the SLEEP state when all of the following are true:
- • Both processors are asleep (e.g. in a WFE or WFI instruction)
- • The system DMA has no outstanding transfers on any channel
RP2040 exits the SLEEP state when either processor is awoken by an interrupt.
When in the SLEEP state, the top-level clock gates are masked by the SLEEP_ENx registers (starting at SLEEP_EN0 ), rather than the WAKE_ENx registers. This permits more aggressive pruning of the clock tree when the processors are asleep.
i NOTE
Though it is possible for a clock to be enabled during SLEEP and disabled outside of SLEEP, this is generally not useful
For example, if the system is sleeping until a character interrupt from a UART, the entire system except for the UART can be clock-gated (SLEEP_ENx = all-zeroes except for CLK_SYS_UART0 and CLK_PERI_UART0). This includes system infrastructure such as the bus fabric.
When the UART asserts its interrupt, and wakes a processor, RP2040 leaves SLEEP mode, and switches back to the WAKE_ENx clock mask. At the minimum this should include the bus fabric, and the memory devices containing the processor's stack and interrupt vectors.
A system-level clock request handshake holds the processors off the bus until the clocks are re-enabled.
2.11.3. DORMANT State
The DORMANT state is a true zero-dynamic-power sleep state, where all clocks (and all oscillators) are disabled. The system can awake from the DORMANT state upon a GPIO event (high/low level or rising/falling edge), or an RTC interrupt: this restarts one of the oscillators (either ring oscillator or crystal oscillator), and ungates the oscillator output once it is stable. System state is retained, so code execution resumes immediately upon leaving the DORMANT state.
Note that, if relying on the RTC ( Section 4.8 ) to wake from the DORMANT state, the RTC must have some external clock source. The RTC accepts clock frequencies as low as 1Hz.
Note also that DORMANT does not halt PLLs. To avoid unnecessary power dissipation, software should power down PLLs before entering the DORMANT state, and power up and reconfigure the PLLs again after exiting.
The DORMANT state is entered by writing a keyword to the DORMANT register in whichever oscillator is active: ring oscillator ( Section 2.17 ) or crystal oscillator ( Section 2.16 ). If both are active then the one providing the processor clock must be stopped last because it will stop software from executing.
2.11.4. Memory Power Down
The main system memories (SRAM0...5, mapped to bus addresses 0x20000000 to 0x20041fff ), as well as the USB DPRAM, can be powered down via the MEMPOWERDOWN register in the Syscfg registers (see Section 2.21 ). When powered down, memories retain their current contents, but cannot be accessed. Static power is reduced.
Image: Caution icon
CAUTIONMemories must not be accessed when powered down. Doing so can corrupt memory contents.
When powering a memory back up, a 20ns delay is required before accessing the memory again.
The XIP cache (see
Section 2.6.3
) can also be powered down, with
CTRL.POWER_DOWN. The XIP hardware will not generate cache accesses whilst the cache is powered down. Note that this is unlikely to produce a net power savings if code continues to execute from XIP, due to the comparatively high voltages and switching capacitances of the external QSPI bus.
2.11.5. Programmer's Model
2.11.5.1. Sleep
The
hello_sleep example,
https://github.com/raspberrypi/pico-playground/blob/master/sleep/hello_sleep/hello_sleep_aon.c
, demonstrates sleep mode. The
hello_sleep application (and underlying functions) takes the following steps:
- • Run all clocks in the system from XOSC
- • Configure an alarm in the RTC for 10 seconds in the future
- • Set
clk_rtcas the only clock running in sleep mode using theSLEEP_ENxregisters (see SLEEP_EN0 ) - • Enable deep sleep in the processor
- • Call
__wfion processor which will put the processor into deep sleep until woken by the RTC interrupt - • The RTC interrupt clears the alarm and then calls a user supplied callback function
- • The callback function ends the example application
Image: Note icon
NOTEIt is necessary to enable deep sleep on both
proc0 and
proc1 and call
__wfi, as well as ensure the DMA is stopped to enter sleep mode.
hello_sleep makes use of functions in
pico_sleep of the
Pico Extras
. In particular,
sleep_goto_sleep_until puts the processor to sleep until woken up by an RTC time assumed to be in the future.
Pico Extras: https://github.com/raspberrypi/pico-extras/blob/master/src/rp2_common/pico_sleep/sleep.c Lines 159 - 183
void sleep_goto_sleep_until(struct timespec *ts, aon_timer_alarm_handler_t callback)
{
// We should have already called the sleep_run_from_dormant_source function
// This is only needed for dormancy although it saves power running from xosc while sleeping
//assert(dormant_source_valid(_dormant_source));
clocks_hw->sleep_en0 = CLOCKS_SLEEP_EN0_CLK_RTC_RTC_BITS;
clocks_hw->sleep_en1 = 0x0;
aon_timer_enable_alarm(ts, callback, false);
stdio_flush();
// Enable deep sleep at the proc
processor_deep_sleep();
175 176 // Go to sleep 177 __wfi(); 178 }
2.11.5.2. Dormant
The
hello_dormant example,
https://github.com/raspberrypi/pico-playground/blob/master/sleep/hello_dormant/hello_dormant_gpio.c
, demonstrates dormant mode. The example takes the following steps:
- • Run all clocks in the system from XOSC
- • Configure a GPIO interrupt for the "dormant_wake" hardware which can wake both the ROSC and XOSC from dormant mode
- • Put the XOSC into dormant mode which stops all processor execution (and all other clocked logic on the chip) immediately
- • When GPIO 10 goes high, the XOSC is started again and execution of the program continues
hello_dormant uses
sleep_goto_dormant_until_pin under the hood:
Pico Extras: https://github.com/raspberrypi/pico-extras/blob/master/src/rp2_common/pico_sleep/sleep.c Lines 258 - 282
258 void sleep_goto_dormant_until_pin(uint gpio_pin, bool edge, bool high) {
259 bool low = !high;
260 bool level = !edge;
261
262 // Configure the appropriate IRQ at IO bank 0
263 assert(gpio_pin < NUM_BANK0_GPIOS);
264
265 uint32_t event = 0;
266
267 if (level && low) event = IO_BANK0_DORMANT_WAKE_INTE0_GPIO0_LEVEL_LOW_BITS;
268 if (level && high) event = IO_BANK0_DORMANT_WAKE_INTE0_GPIO0_LEVEL_HIGH_BITS;
269 if (edge && high) event = IO_BANK0_DORMANT_WAKE_INTE0_GPIO0_EDGE_HIGH_BITS;
270 if (edge && low) event = IO_BANK0_DORMANT_WAKE_INTE0_GPIO0_EDGE_LOW_BITS;
271
272 gpio_init(gpio_pin);
273 gpio_set_input_enabled(gpio_pin, true);
274 gpio_set_dormant_irq_enabled(gpio_pin, event, true);
275
276 _go_dormant();
277 // Execution stops here until woken up
278
279 // Clear the irq so we can go back to dormant mode again if we want
280 gpio_acknowledge_irq(gpio_pin, event);
281 gpio_set_input_enabled(gpio_pin, false);
282 }