I was able to get the Pico 2 W to enter full power down mode (P1.7), and wake up either from GPIO going high or using the timer. It runs from flash. It flashes an LED on startup.The code shown below is from pico-examples with these changes. This has all the stdio stuff taken out completely and does not enable the USB at all. It also has the powman_set_debug_power_request_ignored(true) call taken out. I put the powman_enable calls in main and then call the powman_example_off(). I guess the takeaway for me from this so far is that stdio_init_all() followed by stdio_deinit() is not enough to completely shut down USB.
It does appear to do a complete power down (0.000 A on the ammeter) and does a complete power on reset on wakeup. I found an error in the SDK documentation that I'll post separately.
It does appear to do a complete power down (0.000 A on the ammeter) and does a complete power on reset on wakeup. I found an error in the SDK documentation that I'll post separately.
Code:
#include <stdio.h>#include <inttypes.h>#include "pico/stdio.h"#include "pico/sync.h"#include "hardware/gpio.h"#include "hardware/powman.h"#include "powman_example.h"#define LED_GPIO 14static powman_power_state off_state;static powman_power_state on_state;// Initialise everythingvoid powman_example_init(uint64_t abs_time_ms) { // start powman and set the time powman_timer_start(); powman_timer_set_ms(abs_time_ms); powman_timer_set_1khz_tick_source_lposc(); // use LPOSC so timer survives low power // Allow power down when debugger connected //powman_set_debug_power_request_ignored(true); // Power states powman_power_state P1_7 = POWMAN_POWER_STATE_NONE; powman_power_state P0_3 = POWMAN_POWER_STATE_NONE; P0_3 = powman_power_state_with_domain_on(P0_3, POWMAN_POWER_DOMAIN_SWITCHED_CORE); P0_3 = powman_power_state_with_domain_on(P0_3, POWMAN_POWER_DOMAIN_XIP_CACHE); P0_3 = powman_power_state_with_domain_on(P0_3, POWMAN_POWER_DOMAIN_SRAM_BANK0); P0_3 = powman_power_state_with_domain_on(P0_3, POWMAN_POWER_DOMAIN_SRAM_BANK1); off_state = P1_7; on_state = P0_3; gpio_init(LED_GPIO); gpio_set_dir(LED_GPIO, true); sleep_ms(500);}// Initiate power offstatic int powman_example_off(void) { // Get ready to power off //stdio_flush(); //stdio_deinit_all(); // turn off USB before sleep // Set power states bool valid_state = powman_configure_wakeup_state(off_state, on_state); if (!valid_state) { return PICO_ERROR_INVALID_STATE; } // reboot to main powman_hw->boot[0] = 0; powman_hw->boot[1] = 0; powman_hw->boot[2] = 0; powman_hw->boot[3] = 0; // Switch to required power state int rc = powman_set_power_state(off_state); if (rc != PICO_OK) { return rc; } // Power down while (true) __wfi();}// Power off until a gpio goes highint powman_example_off_until_gpio_high(int gpio) { gpio_init(gpio); gpio_set_dir(gpio, false); if (gpio_get(gpio)) { //printf("Waiting for gpio %d to go low\n", gpio); while(gpio_get(gpio)) { sleep_ms(100); } } //printf("Powering off until GPIO %d goes high\n", gpio); powman_enable_gpio_wakeup(1, gpio, false, true); return powman_example_off();}// Power off until a gpio goes lowint powman_example_off_until_gpio_low(int gpio) { gpio_init(gpio); gpio_set_dir(gpio, false); if (!gpio_get(gpio)) { //printf("Waiting for gpio %d to go high\n", gpio); while(!gpio_get(gpio)) { sleep_ms(100); } } //printf("Powering off until GPIO %d goes low\n", gpio); powman_enable_gpio_wakeup(1, gpio, false, false); return powman_example_off();}// Power off until an absolute timeint powman_example_off_until_time(uint64_t abs_time_ms) { // Start powman timer and turn off //printf("Powering off for %"PRIu64"ms\n", abs_time_ms - powman_timer_get_ms()); powman_enable_alarm_wakeup_at_ms(abs_time_ms); return powman_example_off();}// Power off for a number of millisecondsint powman_example_off_for_ms(uint64_t duration_ms) { uint64_t ms = powman_timer_get_ms(); return powman_example_off_until_time(ms + duration_ms);}#ifndef WAKEUP_GPIO#define WAKEUP_GPIO 15#endif// How long to wait#define PAUSE_TIME_MS 1000// Got to sleep and wakeup when a GPIO goes high// The example will repeatedly wait until GPIO 15 is low then switch off until GPIO 15 goes high// To test this you can connect the GPIO to ground and then 3V3(OUT)// The debugger will appear to be unresponsive while the device is offint main() { //stdio_init_all(); //sleep_ms(2000); // Allow USB CDC to settle // Initialise the example powman_example_init(1704067200000); // Scratch register survives power down //printf("Wake up, test run: %u\n", powman_hw->scratch[0]++); // Stay awake for a few seconds //printf("Awake for %dms\n", PAUSE_TIME_MS); gpio_put(LED_GPIO, 1); sleep_ms(PAUSE_TIME_MS); gpio_put(LED_GPIO, 0); sleep_ms(PAUSE_TIME_MS); gpio_put(LED_GPIO, 1); sleep_ms(PAUSE_TIME_MS); gpio_put(LED_GPIO, 0); // power off// int rc = powman_example_off_until_gpio_low(WAKEUP_GPIO);// int rc = powman_example_off_until_gpio_high(WAKEUP_GPIO);// int rc = powman_example_off_for_ms(10000); int gpio = WAKEUP_GPIO; gpio_init(gpio); gpio_set_dir(gpio, false); if (!gpio_get(gpio)) { //printf("Waiting for gpio %d to go high\n", gpio); while(!gpio_get(gpio)) { sleep_ms(100); } } //printf("Powering off until GPIO %d goes low\n", gpio); powman_enable_gpio_wakeup(1, gpio, false, false); uint64_t ms = powman_timer_get_ms(); //power off and sleep for 5 seconds powman_enable_alarm_wakeup_at_ms(ms + 5000); int rc = powman_example_off(); hard_assert(rc == PICO_OK); hard_assert(false); // should never get here! return 0;}Statistics: Posted by jderickson — Wed Sep 10, 2025 9:13 pm