Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8035

SDK • Re: Anyone have a worked example of sleep_goto_sleep_until() that works?

$
0
0
It can run directly from XOSC at MHz 12 (getting lower doesn't spectacularly cuts current draw down):

Code:

#include "pico/stdlib.h"#include "pico/bootrom.h"#include "pico/sync.h"#include "hardware/pll.h"#include "hardware/rosc.h"#include "hardware/vreg.h"#include "hardware/xosc.h"#include "hardware/clocks.h"#if PICO_RP2040#include "hardware/structs/ssi.h"#endif#include "hardware/structs/xip_ctrl.h"#include "hardware/structs/syscfg.h"#include "hardware/structs/scb.h"int main(void) {...#if !PICO_RP2350A    for (uint8_t i = 0; i < 48; i++) {#else    for (uint8_t i = 0; i < 30; i++) {#endif        gpio_disable_pulls(i);        gpio_set_input_enabled(i, 0);        gpio_set_input_hysteresis_enabled(i, 0);        gpio_set_drive_strength(i, GPIO_DRIVE_STRENGTH_2MA);    }        clock_configure(clk_ref, CLOCKS_CLK_REF_CTRL_SRC_VALUE_XOSC_CLKSRC, 0, 12 * MHZ, 12 * MHZ);    clock_configure(clk_sys, CLOCKS_CLK_SYS_CTRL_SRC_VALUE_CLK_REF, 0, 12 * MHZ, 12 * MHZ);    #if PICO_RP2040    vreg_set_voltage(VREG_VOLTAGE_0_95);#else    vreg_set_voltage(VREG_VOLTAGE_1_00);#endif    clock_stop(clk_adc);    clock_stop(clk_usb);#if PICO_RP2040    clock_stop(clk_rtc);#else    clock_stop(clk_hstx);#endif    clock_stop(clk_peri);    pll_deinit(pll_usb);    pll_deinit(pll_sys);    rosc_disable();    #if PICO_RP2040    xip_ctrl_hw->ctrl    = 0b1010;    ssi_hw->ssienr       = 0;    scb_hw->scr         |= M0PLUS_SCR_SLEEPDEEP_BITS;    clocks_hw->wake_en0    = 0b11110000100010000000100100011001;    clocks_hw->wake_en1    = 0b000000000100011;    clocks_hw->sleep_en0    = 0b00000000000000000000000100000001;    clocks_hw->sleep_en1    = 0b000000000100000;#else    scb_hw->scr          |= M33_SCR_SLEEPDEEP_BITS;    xip_ctrl_hw->ctrl        |= 0b00000000000000000000000000001000;    clocks_hw->sleep_en0     =    0b00000000100000000000000000000000;    clocks_hw->sleep_en1     =    0b00000000000000000000000000000000;    clocks_hw->wake_en0     = 0b10001001100000000000000000000000;    clocks_hw->wake_en1     = 0b00000000001010000011000011110000;#endif...}
Above can blink an LED for example. So turning off input buffers (on pads not used as an input), rosc (it is not from SDK, but rather that playground or extras thing) and plls, turning down peripherals and clocks for unused stuff like memory banks etc and SSI controller if there is an option to run from flash.

About RTC and stuff, there is an official document called Power-switching-RP2040-for-low-standby-current-applications.pdf. Removing Pico's (2)(W) SMPS enable pull and you can control power IC externally and having it pulled from GPIO. But requires hacking hardware obviously.

PS. Awww, katak255 was first with that :D

Statistics: Posted by MatSOBDev2 — Sun Dec 14, 2025 2:21 pm



Viewing all articles
Browse latest Browse all 8035

Trending Articles