nRF52840 does not wake up on GPIO interrupt

Hello

I have a very strange problem

A custom nRF52840 board has a charge detect pin, P1.6

A gpio callback is installed to wake it up on charger connect/disconnect

When the CPU is running this works like a charm

However if the CPU is powered off with  sys_poweroff() API, the gpio callback does not wake up the CPU.

To make things more interesting, this does not happen every time and on all devices.

The most common failure scenario is as follows

1. Flash the firmware on device ( nrfjprog is used )

2. Load configuration data to scratch partition ( JLink is used) and reboot the device

3. On boot the device detects configuration data, configures itself and reboots. Everything works as expected including charger detection

4. Power off device with sys_poweroff() API

5. Connect the charger . Device does not wake up.

6. Connect device to a JLink app  like RTT log viewer 

7. Device wakes up and functions properly 

8. Power off device with sys_poweroff() API

9. Attach the charger. - device wakes up. From this point on device can be powered off repeatedly and it wakes up every time

From the hardware standpoint  I confirmed that the pin receives the voltage when the charger is connected.
Here is how the pin is configured in dts.
custom_pins {
        compatible = "gpio-keys";
 
        charge_detect: charge_detect_1 {
            gpios =  <&gpio1 6 GPIO_ACTIVE_HIGH>;
            label = "Charger detect pin";
        };
... etc
};
Here is how the pin is initialized
gpio_pin_configure_dt(&_charge_pin,GPIO_ACTIVE_HIGH | GPIO_INPUT);
gpio_pin_interrupt_configure_dt(&_charge_pin, GPIO_INT_EDGE_BOTH);
gpio_init_callback(&_bat_detect_gpio_cb,charge_detect_gpio_handler, BIT(_charge_pin.pin));
pio_add_callback(_charge_pin.port, &_bat_detect_gpio_cb);
Does anything stand out as a potential source of the problem here?
Any pointers and ideas are much appreciated
Thank you
Andy
 
Related