We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

20 posts • Page 1 of 1
pie_face
Posts: 171
Joined: Sun Aug 04, 2024 11:16 am

simplest way to shut down RP2040. [SOLVED]

Sat Nov 01, 2025 2:51 pm

Hi,
I'm looking for the simplest way to shut down RP2040.

I have run once and done data sampling application which runs for about 10s. I then need permanently go to sleep until I reboot it.
I have no need wake_on.... whatever, and don't want to mess with all that.

It currently ends with while(1); which obviously working as fast as it can.
Now the code is tested I'm running off a v. small LiPo and need to conserve charge.

I connect the LiPo to 3V3 with a diode to drop the cell voltage to a safe level for the RP2040.

I've read this chip does not have a really low power state but I'm not looking at leaving alone 6mo, it's just to stop burning watts in a stupid loop when the sampling stops.

TIA.
Last edited by pie_face on Sun Nov 02, 2025 2:15 pm, edited 1 time in total.

hippy
Posts: 19831
Joined: Fri Sep 09, 2011 10:34 pm

Re: simplest way to shut down RP2040.

Sat Nov 01, 2025 4:12 pm

pie_face wrote:
Sat Nov 01, 2025 2:51 pm
It currently ends with while(1); which obviously working as fast as it can.
Can't you just exit from 'main' or put a 'wfe' (or whatever is needed ) in the while loop ?

That appears to hang execution, terminate USB operation, but I don't know what the power consumption drops to. I presume you could power down on-chip peripherals, memory and clocks before exiting.

I am not sure what you could do, how far you can reduce consumption. I actually add a while loop at the end, or a wrapper around main, to prevent that because I don't care about consumption and it allows further 'no button uploads' during development. So no experience in this field.

gmx
Posts: 1845
Joined: Thu Aug 29, 2024 8:51 pm

Re: simplest way to shut down RP2040.

Sat Nov 01, 2025 8:16 pm

Look in RP2040 datasheet:
2.11.3. DORMANT State
2.11.4. Memory Power Down

https://github.com/raspberrypi/pico-pla ... ant_gpio.c

Or use a FET, or a circuit/module to power down completely.

Power switching RP2040 for low standby current applications
https://pip-assets.raspberrypi.com/cate ... ations.pdf

pie_face
Posts: 171
Joined: Sun Aug 04, 2024 11:16 am

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 2:19 am

Thanks , I was looking at pico-extras, which seems to be largely the same code in terms of this issue.


So I copied the repo and included it as suggested into my project file:

Code: Select all

include(pico_sdk_import.cmake)
# req PICO EXTRAS for DORMANT power state
include(pico_extras_import.cmake)
However, it fails to find any of the functions in that library.

Code: Select all

void halt(){
 processor_deep_sleep();
 _go_dormant();
 .... 

Code: Select all

hello_world.cpp:104:3: error: 'processor_deep_sleep' was not declared in this scope
I pulled out the essentials into my code. It compiled and ran but did not shut down the processor.

Code: Select all

 #define NO_AUX 0
 uint src_hz = XOSC_HZ;
 DEBUG_PRINTF ("XOSC_HZ = %d kHz\n",XOSC_HZ/kHz);
 uart_default_tx_wait_blocking();
 DEBUG_PRINTF ("Core 0 : Terminating Core 1\n");
 multicore_reset_core1(); 
 
 bool res;
 uint clk_ref_src = CLOCKS_CLK_REF_CTRL_SRC_VALUE_XOSC_CLKSRC;
 res = clock_configure(clk_ref, clk_ref_src, NO_AUX, src_hz, src_hz);
 if (res) DEBUG_PRINTF ("set ref clk %d failed\n",src_hz);
 uart_default_tx_wait_blocking();
 res = clock_configure(clk_sys, CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLK_REF, NO_AUX, src_hz, src_hz);
 if (res) DEBUG_PRINTF ("set sys clk %d failed\n",src_hz);
 uart_default_tx_wait_blocking();
 
 clock_stop(clk_adc);
 clock_stop(clk_usb);
 DEBUG_PRINTF ("stop USB \n");
 
 res = false;
 uint clk_rtc_src = CLOCKS_CLK_RTC_CTRL_AUXSRC_VALUE_XOSC_CLKSRC; // *AUXSRC*
 res |= clock_configure(clk_rtc, NO_AUX, clk_rtc_src, src_hz, src_hz); // 46875, src_hz why literal ???
 res |= clock_configure(clk_peri, NO_AUX, CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLK_SYS, src_hz, src_hz);
 if (res) DEBUG_PRINTF ("set peri clk failed\n");
 
 pll_deinit(pll_sys);
 pll_deinit(pll_usb);
 DEBUG_PRINTF ("PLLs off\n");
 
 setup_default_uart(); // def uart =1 in cmake
 DEBUG_PRINTF ("dormant..........\n");
 stdio_flush(); // flush serial ??
 scb_hw->scr |= ARM_CPU_PREFIXED(SCR_SLEEPDEEP_BITS);
 DEBUG_PRINTF ("didn't work ! Not dead. !! \n");
This outputs the following: it does not halt the RP2040

Code: Select all

clk_sys = 125000 kHz
clk_peri= 125000 kHz
pll_sys = 125000 kHz
pll_usb = 48000 kHz
clk_usb = 48000 kHz
clk_adc = 48000 kHz
shutting down now..........
XOSC_HZ = 12000 kHz
Core 0 : Terminating Core 1
ref clk set failed
sys clk set failed
stop USB 
dormant..........
didn't work ! Not dead. !! 

katak255
Posts: 916
Joined: Sun Apr 07, 2024 3:29 pm

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 3:53 am

There are a lot of threads and articles around. I studied this popular article for my own experiments:

Awaking the Raspberry Pico from deep sleep
https://ghubcoder.github.io/posts/awaking-the-pico/

Discussions about Dormant state:

Dormant mode in MicroPython
viewtopic.php?t=311732

Pi Pico - Sleep & Dormant states
https://forum.core-electronics.com.au/t ... ates/12584

If you just want to power cycle after going Dormant, then aiming for Dormant is probably fine. But if you aim to wake up on something, there are discussion about boards not waking up etc. The following github ticket is very useful:

Pico doesn't wake up properly from Dormant/Sleep #41
https://github.com/raspberrypi/pico-extras/issues/41

It's a complex chip, and proper Dormant state needs serious testing, though if just power-cycling, your use case is more simple since you forgo waking up. For my own casual hobby uses, I decided to stick to XOSC since I need crystal-clocked timing for scheduling sensor reads. I have done casual testing to run on XOSC divided down to 2MHz. No sleeping! Uses about 2.0 mA measured on VSYS 3V3. I did my testing with an OLED attached and no USB, so I took out all the USB stdio serial complexity out of the equation in testing -- a lot less of a headache.

[Edit] A nice older thread on some SLEEP and DORMANT measurements:

Current consumption on sleep modes
viewtopic.php?t=316458

Apparently powering lower the SRAMs doesn't help much for a Pico board. It does help at DVDD, but for a Pico board, it was reported in the thread that it went from 0.8 mA Dormant to about 0.75 mA. For a Pico board, it's quoted in the DS as 0.8 mA DORMANT and 1.3 mA SLEEP measured at VBUS. Scaled to VSYS 3V3, I am not doing too badly with running a Pico board at 2 MHz. But I should collect more data at some point.

gmx
Posts: 1845
Joined: Thu Aug 29, 2024 8:51 pm

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 9:34 am

pie_face wrote:

Code: Select all

setup_default_uart(); // def uart =1 in cmake
 DEBUG_PRINTF ("dormant..........\n");
 stdio_flush(); // flush serial ??
 scb_hw->scr |= ARM_CPU_PREFIXED(SCR_SLEEPDEEP_BITS);
 DEBUG_PRINTF ("didn't work ! Not dead. !! \n");
It looks like you didn't do _go_dormant(); https://github.com/raspberrypi/pico-ext ... eep.c#L220
Setting SCR_SLEEPDEEP_BITS only prepares the CPU to cut clocks during WFE/WFI instructions (sleep waiting for event/interrupt).
I've tested it, and the gain is marginal, around -10% (x0.9) compared to idle state.

Another way would be to stop the XOSC (and any other clock sources), basically that's a 'forever dormant mode'.
Can cut static power to main RAMs too.

pie_face
Posts: 171
Joined: Sun Aug 04, 2024 11:16 am

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 11:31 am

Ah, thanks for pointing out the obvious !
I'd misread that , I thought it was shutting down the unused osc. I must be working too late at night.
Now at least it is stopping. That's big step forwards. Many thanks.

Code: Select all

clk_sys = 125000 kHz
clk_peri= 125001 kHz
pll_sys = 125000 kHz
clk_usb = 48000 kHz
pll_usb = 48000 kHz
clk_adc = 48000 kHz
clk_rosc= 5134 kHz
shutting down now..........
XOSC_HZ = 12000 kHz
Core 0 : Terminating Core 1
stopping USB,ADC 
clk_ref = 48000 kHz
clk_sys = 12000 kHz
clk_usb = 0 kHz
clk_adc = 0 kHz
clk_peri= 12000 kHz
PLLs off
dormant..........
I should probably look into SRAM supply too and shut down peri_clk now I don't the UART any more. That should be good enough for this job.

I'll look wake-up problems when I need it.

I'm confused as to why I cannot access pico-extras. This would have at least given me a base line to work from.

As described here https://github.com/raspberrypi/pico-extras/tree/master ,I added pico_extras_import.cmake to my project file . I've added it to my CMakeFiles as shown above; I added the env var ; I cleared my build dir, ran cmake without problems but my main code cannot find any function definitions fro that lib.

Code: Select all

void halt(){
 processor_deep_sleep();
...

Code: Select all

 error: 'processor_deep_sleep' was not declared in this scope
Did I miss something again?

TIA

trejan
Posts: 7723
Joined: Tue Jul 02, 2019 2:28 pm

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 11:58 am

pie_face wrote:
Sun Nov 02, 2025 11:31 am
Did I miss something again?
Did you add pico_sleep to target_link_libraries() in CMakeLists.txt?

pie_face
Posts: 171
Joined: Sun Aug 04, 2024 11:16 am

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 12:34 pm

Thanks. That was indeed missing, I've been chopping so many things in and out to find out what's wrong, I must have tried that and it did not help so I removed it again.

I put it back in, did full clean out of the build dir, re-ran cmake but it did not help. :?

Code: Select all

error: 'processor_deep_sleep' was not declared in this scope

trejan
Posts: 7723
Joined: Tue Jul 02, 2019 2:28 pm

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 12:38 pm

pie_face wrote:
Sun Nov 02, 2025 12:34 pm

Code: Select all

error: 'processor_deep_sleep' was not declared in this scope
processor_deep_sleep() is only callable within sleep.c

gmx
Posts: 1845
Joined: Thu Aug 29, 2024 8:51 pm

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 12:40 pm

BTW, in your case I think you can shutdown the core voltage regulator, need to try it. :)

VREG_AND_CHIP_RESET: VREG Register
2.10.2.3. Shutdown Mode
In Shutdown mode, the voltage regulator is disabled, power consumption is minimized and the regulator’s output pin
(VREG_VOUT) is pulled to 0V.
Shutdown mode is only useful if the voltage regulator is not providing the RP2040’s digital core supply (DVDD). If the
regulator is supplying DVDD, and brown-out detection is enabled, entering shutdown mode will cause a reset event and
the voltage regulator will return to normal mode. If brown-out detection isn’t enabled, the voltage regulator will shut
down and will remain in shutdown mode until its input supply (VREG_VIN) is power cycled.
Ah, can also save some nanoamperes (jokinng) by putting the flash chip in sleep mode (not joking, I think a few tenths of mA).

pie_face
Posts: 171
Joined: Sun Aug 04, 2024 11:16 am

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 1:18 pm

trejan wrote:
Sun Nov 02, 2025 12:38 pm
processor_deep_sleep() is only callable within sleep.c
Ah, of course, I had not notice the static.
So that lib only exports the conditional sleep_until* / dormant_until*
There's nothing that actually shuts it down fully. LOL.

At least that all makes sense now. Thanks for the help.

pie_face
Posts: 171
Joined: Sun Aug 04, 2024 11:16 am

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 1:21 pm

Code: Select all

BTW, in your case I think you can shutdown the core voltage regulator, need to try it. :)
Thanks for the tip. I'm feeding a LiPO cell to 3V3 via a diode. Nothing on the regulator input.

I'm looking for wires to do some current measurements now to see how much I gained.

OK, it's 35mA while sampling 11mA in shutdown. That must be the sensor boards. It's better but I need to look at an electrical solution.
I should maybe feed the sensors via a FET, use a GPIO to power them them on when needed.
Last edited by pie_face on Sun Nov 02, 2025 11:57 pm, edited 2 times in total.

katak255
Posts: 916
Joined: Sun Apr 07, 2024 3:29 pm

Re: simplest way to shut down RP2040.

Sun Nov 02, 2025 2:00 pm

Just to add one tiny item on the "VREG to Off" idea. Found one thread (one post actually):

Disabling the VREG made the GPIO pin low impedance
viewtopic.php?t=355804

Any takers...? :)

gmx
Posts: 1845
Joined: Thu Aug 29, 2024 8:51 pm

Re: simplest way to shut down RP2040. [SOLVED]

Sun Nov 02, 2025 4:40 pm

Too late :)
That 'low impedance' I've just measured to be a leakage of about 150uA when shorted to 3.3V, roughly equivalent of 22k, not "around 14ohms" as stated.

But in MicroPython it went down from 22mA to 1.8mA (without turning off anything else) in an instant death, which is fun. :)
Not even the Reset button works anymore.

Code: Select all

from machine import mem32
VREG = 0x40064000
BOD = 0x40064004
mem32[BOD] = 0
mem32[VREG] = 2

katak255
Posts: 916
Joined: Sun Apr 07, 2024 3:29 pm

Re: simplest way to shut down RP2040. [SOLVED]

Sun Nov 02, 2025 5:12 pm

Interesting, I guess I might try it after all (edit: done). :) I just did collect some data for my own use, tried MEMPOWERDOWN too, so here is a mini data dump:

Data for one authentic Pico board (RP2040), not connected to anything. Power from AMS1117 regs was applied to the appropriate pins. Measured using an INA219 breakout board with a LSB of 20 uA. Due to the DC-DC etc, measurements are very noisy at small values, hence average values are presented. Take them as ballpark guesstimates. Turning down VREG would add a bit more savings.

Code: Select all

+----------------+----------+----------+----------+
| board state | VBUS 5V | VSYS 5V | VSYS 3V3 |
+----------------+----------+----------+----------+
| normal idle | 19.259 | 19.368 | 26.459 |
| called xosc | 3.001 | 2.855 | 3.510 |
| sleep xosc | 1.842 | 1.646 | 1.968 |
| dormant | 1.332 | 1.134 | 1.312 |
| memdown | 1.273 | 1.024 | 1.154 |
| vreg nope | 1.927 | 1.665 | 1.988 |
| psm frce_off | 1.542 | 1.317 | 1.585 |
+----------------+----------+----------+----------+
| xosc 6MHz | 2.366 | 2.200 | 2.666 |
| xosc 4MHz | 2.148 | 1.966 | 2.291 |
| xosc 3MHz | 2.035 | 1.840 | 2.229 |
| xosc 2MHz | 1.924 | 1.759 | 2.083 |
+----------------+----------+----------+----------+
(all values are in mA)
Where:
normal idle = running at 125MHz inside sleep_ms()
called xosc = after calling sleep_run_from_xosc() aka 12MHz
sleep xosc = hello_sleep.c code, xosc still running, can wake up
dormant = hello_dormant_gpio.c code, wake untested
memdown = dormant with MEMPOWERDOWN everything
vreg nope = MEMPOWERDOWN, then set bod=0 & vreg=2 before dormant
psm frce_off = MEMPOWERDOWN, then frce_off everything
and the rest is XOSC divided down

[Edit] Added measurements for the VREG case.
[Edit2] Added measurements for the PSM case.
Last edited by katak255 on Mon Nov 03, 2025 1:37 am, edited 1 time in total.

gmx
Posts: 1845
Joined: Thu Aug 29, 2024 8:51 pm

Re: simplest way to shut down RP2040. [SOLVED]

Mon Nov 03, 2025 12:50 am

I've got another one, faster, and better.
Hardware reset working, no GPIO leaking.
Got around 1.215 mA at 3.3V but the board I test has 16MB Flash, and some neopixel, could be leaking more, I've cut ADC and power led, still...

Code: Select all

PSM_FRCE_OFF = 0x40010004
mem32[PSM_FRCE_OFF] = 0xFFFFFFFF
P.S. Actually there is some GPIO "leaking" but it looks to be the default pull-down... blimey. :)

pie_face
Posts: 171
Joined: Sun Aug 04, 2024 11:16 am

Re: simplest way to shut down RP2040. [SOLVED]

Mon Nov 03, 2025 1:40 am

but the board I test has 16MB Flash, and some neopixel, could be leaking more,
Is that a chinese pseudo clone with a regular linear regulator instead of the LDO?

katak255
Posts: 916
Joined: Sun Apr 07, 2024 3:29 pm

Re: simplest way to shut down RP2040. [SOLVED]

Mon Nov 03, 2025 1:50 am

Nice, better than disabling VREG :D
Averages of current measurements with VREG disabled were moving about a bit more than the rest. PSM everything off gives stable average currents much like the rest. But "stable average current" is a bit misleading, because I am not measuring at DVDD with test equipment. At the lowest currents, the DC-DC pulse skipping is pretty impressive, for example, for dormant:

Code: Select all

VBUS 5.0V (overall min/avg/max)= 1.080 1.332 1.660 (mA)
VSYS 5.0V (overall min/avg/max)= 0.120 1.134 1.980 (mA)
VSYS 3.3V (overall min/avg/max)= 0.140 1.312 1.920 (mA)
[Edit] The VBUS schottky and R and C bits seems to be working like a filter, so VSYS mix/max look more 'raw'.

gmx
Posts: 1845
Joined: Thu Aug 29, 2024 8:51 pm

Re: simplest way to shut down RP2040. [SOLVED]

Mon Nov 03, 2025 3:47 pm

If you have high frequency noise/interference, you should use a LP filter between the shunt and INA219.
8.4.1 Filtering and Input Considerations
Measuring current is often noisy, and such noise can be difficult to define. The INA219 offers several options for
filtering by choosing resolution and averaging in the Configuration register. These filtering options can be set
independently for either voltage or current measurement.
The internal ADC is based on a delta-sigma (ΔΣ) front-end with a 500-kHz (±30%) typical sampling rate. This
architecture has good inherent noise rejection; however, transients that occur at or very close to the sampling
rate harmonics can cause problems. Because these signals are at 1 MHz and higher, they can be dealt with by
incorporating filtering at the input of the INA219. The high frequency enables the use of low-value series resistors
on the filter for negligible effects on measurement accuracy. In general, filtering the INA219 input is only
necessary if there are transients at exact harmonics of the 500-kHz (±30%) sampling rate (>1 MHz). Filter using
the lowest possible series resistance and ceramic capacitor. Recommended values are 0.1 to 1 μF. Figure 14
shows the INA219 with an additional filter added at the input.

20 posts • Page 1 of 1

Return to "SDK"

AltStyle によって変換されたページ (->オリジナル) /