nRF SDK v2.9.1 GPIO interrupt not working after wake up from long sleep

Hi everyone,

I'm working on a project using nrf52832 with SDK v2.9.1. I build my application on top of the nrf Desktop framework (https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/applications/nrf_desktop/README.html).

The GPIO interrupt stopped working after wake up from a long (few hours) sleep. The application stopped response to GPIO events. I can see the GPIO LATCH register is not cleared (therefore may not be a hardware issue). The GPIO configuration registers have expected value as well. The device still can connect to the host using bluetooth.

Logging didn't show any explicit error. The application is still running and connected to bluetooth. Most likely the irq_handler (nrfx_gpiote.c) is not called anymore. If I attach the debugger, the device will be restarted and the issue is gone. Even the debugger is attached, setting a breakpoint to the isr usually crashes the application.

Any suggestion how can I further debug this issue?

Thank you

  • Hello,

    After deep sleep (System OFF), GPIO pin configuration can be lost, especially if the device is in debug interface mode. There is common errata [81] GPIO: PIN_CNF is not retained when in debug interface mode about pin_cnf is not retained in debug mode after reset. Have you tried without RTT or debugger attached to check if the error occurs?

    After waking up from sleep it is recommended to reconfigure GPIO and interrupt which necessary because configuration maybe lost after a long sleep. You can add the following code after entering sleep mode in the main() function.

    configure_button_interrupt();

    If you see the LATCH register is set but your handler is not called, it means the hardware event occurred, but the software did not respond—often due to missed or misconfigured interrupts or not clearing the LATCH/event after handling.

    We need to clear the LATCH register because, once a pin's SENSE condition is met, the corresponding bit in the LATCH register is set to 1 and remains set until it is explicitly cleared by the CPU. If the LATCH bit is not cleared, it will continue to indicate that the event has occurred, even if the pin no longer meets the SENSE condition. This can prevent new events from being detected and may block further interrupts or event handling for that pin. 

    So, we need to clear the LATCH bit in your handler to allow new events to be detected. So in the main function, the following should be present.

    Check LATCH register (if using nrf_gpio directly)
            if (NRF_P0->LATCH & (1 << BUTTON_PIN)) {
                LOG_INF("LATCH set: event occurred but interrupt may not have fired");
                // Clear LATCH
                NRF_P0->LATCH = (1 << BUTTON_PIN);
            }

Related