I am having a similar issue to the person in this post where the wake from deep sleep on an interrupt sometimes works and sometimes doesn't. But for me, it's very consistent.
I enter sleep in two cases:
Case 1 works every time when the debugger is running and fails every time when running standalone.
Case 2 works every time without the debugger running.
Case 1: Start scanning, set a timer to timeout in 5 seconds, when that event happens, set an event. In the event callback, go to deep sleep.
Case 2: Go to deep sleep in the disconnected call back function.
When it fails to wake up, it does not seem to fail to go to sleep as the next line of code is a call to printk which is never executed. It just won't wake up.
Device tree entry:
ints { compatible = "gpio-keys"; interrupt0: interrupt_0 { gpios = <&gpio0 27 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>; label = "Wakeup Interrupt"; }; };
GPIO configuration:
nrf_gpio_cfg_input(DT_GPIO_PIN(DT_NODELABEL(interrupt0), gpios), NRF_GPIO_PIN_PULLDOWN); nrf_gpio_cfg_sense_set(DT_GPIO_PIN(DT_NODELABEL(interrupt0), gpios), NRF_GPIO_PIN_SENSE_HIGH);
Sleep code:
pm_power_state_force((struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});
I've tried it both with and without the power management config items in prj.conf:
CONFIG_PM=y
CONFIG_PM_DEVICE=y
Hardware: nRF52-DK
nRF Connect SDK version 1.8.0.
I just tried upgrading to nRF Connect SDK version 1.9.0 to see if things would be different and it won't go to sleep at all (after adding 0 in for the new cpu parameter of pm_power_state_force, of course). I do see there are bugs filed against Zephyr a month ago reporting issues with this, but I'm not familiar enough the the SDK to know if it was using the problematic version of Zephyr or not. the subsys/pm/pm.c file doesn't quite match the commit that fixed the issue, but my attempt to make a similar change didn't work. So probably best to focus on this with SDK version 1.8.0 for now.