nrf5340DK
NCS 3.0.0
if I use sample zephyr/samples/boards/nordic/system_off it works fine and i can wake from sw0 press. but if i move the sys_poweroff() call int a button_change() routine like this code.
void button_changed(uint32_t button_state, uint32_t has_changed)
{
uint32_t buttons = button_state & has_changed;
if (buttons & KEY_POWER_OFF) {
hwinfo_clear_reset_cause();
sys_poweroff();
}
};
static void configure_gpio(void)
{
int err;
err = dk_buttons_init(button_changed);
if (err) {
LOG_ERR("Cannot init buttons (err: %d)", err);
}
#if defined(CONFIG_GPIO_WAKEUP_ENABLE)
//After entering the system off by pressing SW0 you can wake on SW1
/* configure sw1 as input, interrupt as level active to allow wake-up */
err = gpio_pin_configure_dt(&sw1, GPIO_INPUT);
if (err < 0) {
printf("Could not configure sw1 GPIO (%d)\n", err);
return;
}
// Configure pin sense for wakeup
// nrf_gpio_cfg_sense_set(sw1.pin, NRF_GPIO_PIN_SENSE_LOW);
err = gpio_pin_interrupt_configure_dt(&sw1, GPIO_INT_LEVEL_ACTIVE);
if (err < 0) {
printf("Could not configure sw1 GPIO interrupt (%d)\n", err);
return;
}
#endif
}
The Code will go into system OFF and draw 1uA, but it will not wake from a button press.
curious on why moving the sys_poweroff() into that button_changed() routine changes the behavior.
How do i get it to wake on button press?
I have tried setting gpio with with the follow code
void poweroff_work_handler(struct k_work *work_item)
{
printf("configuring sw1 as wakebutton then going to bed\n");
// Configure pin sense for wakeup
gpio_pin_configure_dt(&wakebutton1, GPIO_INPUT | GPIO_PULL_UP);
gpio_add_callback(wakebutton1.port, &button_cb_data);
gpio_pin_interrupt_configure_dt(&wakebutton1, GPIO_INT_EDGE_TO_ACTIVE);
nrf_gpio_cfg_sense_set(wakebutton1.pin, NRF_GPIO_PIN_SENSE_LOW);
int rc = pm_device_action_run(cons, PM_DEVICE_ACTION_SUSPEND);
if (rc < 0)
{
printf("Could not suspend console (%d)\n", rc);
}
// Enter system off (deep sleep)
sys_poweroff();
}
this will work with the gpio as a wake source, but the idle current of my code goes from 5uA to 95uA.
so that code is causing other things to be active versus the dk_buttons_init() call.