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

General • Trouble using SDK powman to enter low power

$
0
0
Hello,
New poster here, and also new to Pico 2 W programming using SDK. Forgive the ignorance. I have been using the following sequence to enter full low power mode on the RP2350. This includes debug outputs. I want to wake up on a positive going edge on GPIO 2 or an AON alarm. When the int rc = powman_set_power_state(sleep_state) call happens, the sleep state is rejected. There is no pending power up request as I do not have the debugger connected, I am running from flash. Any help with this would be appreciated.
Thanks.

Code:

static void dump_pwrup(const char* tag) {    uint32_t cur = powman_hw->current_pwrup_req;    printf("%s: pwrup_req=0x%08x%s%s%s%s%s%s\n", tag, cur,        (cur&(1u<<0))?" pwrup0":"",        (cur&(1u<<1))?" pwrup1":"",        (cur&(1u<<2))?" pwrup2":"",        (cur&(1u<<3))?" pwrup3":"",        (cur&(1u<<5))?" coresight":"",        (cur&(1u<<6))?" alarm":"");}static int enter_ultra_low_power_mode(uint32_t hours) {    printf("Entering low power mode for %u hours...\n", hours);    save_meter_data();    // 0) AON timer must tick from LPOSC if XOSC/PLLs go off    powman_timer_set_1khz_tick_source_lposc();    uint64_t now_ms  = powman_timer_get_ms();    uint64_t wake_ms = now_ms + (uint64_t)hours * 3600ULL * 1000ULL;    // 1) Disarm EVERYTHING and clear latched alarm    powman_disable_all_wakeups();    aon_timer_disable_alarm();         // clears alarm_pwrup request    dump_pwrup("after-disarm");    // 2) If CORESIGHT is asserted, you cannot sleep -> return error    if (powman_hw->current_pwrup_req & (1u<<5)) {        printf("CORESIGHT active; detach SWD/debugger.\n");        return PICO_ERROR_PRECONDITION_NOT_MET;    }    // 3) Make sure the pulse pin is idle (LOW) before arming rising-edge wake    while (gpio_get(PULSE_GPIO)) {        // If your reed can rest HIGH, switch to falling-edge wake instead        tight_loop_contents();    }    // 4) Arm exactly the wakes we want NEXT    powman_enable_alarm_wakeup_at_ms(wake_ms);    // edge=true, high=true -> rising edge; safe because we verified LOW above    powman_enable_gpio_wakeup(/*pwrup line*/ 0, PULSE_GPIO, /*edge*/true, /*high*/true);    dump_pwrup("after-arm");    // 5) Build states    powman_power_state sleep_state = POWMAN_POWER_STATE_NONE; // P1.0    powman_power_state wake_state  = POWMAN_POWER_STATE_NONE;    wake_state = powman_power_state_with_domain_on(wake_state, POWMAN_POWER_DOMAIN_SWITCHED_CORE);    wake_state = powman_power_state_with_domain_on(wake_state, POWMAN_POWER_DOMAIN_XIP_CACHE);    wake_state = powman_power_state_with_domain_on(wake_state, POWMAN_POWER_DOMAIN_SRAM_BANK0);    wake_state = powman_power_state_with_domain_on(wake_state, POWMAN_POWER_DOMAIN_SRAM_BANK1);    powman_configure_wakeup_state(sleep_state, wake_state);    printf("Sleep state: 0x%08x, Wake state: 0x%08x, Hours: %u\n",           (unsigned)sleep_state, (unsigned)wake_state, (unsigned)hours);    // 6) Try to go down; if a request is pending you'll see the rc and reason    int rc = powman_set_power_state(sleep_state);    if (rc != PICO_OK) {        dump_pwrup("set_power_state FAILED");        printf("powman_set_power_state rc=%d (pending request blocks sleep)\n", rc);    }    return rc; // On success, CPU+RAM power off and we don't return.}

Statistics: Posted by jderickson — Tue Sep 02, 2025 8:43 pm



Viewing all articles
Browse latest Browse all 8082

Trending Articles