nrf_reset_resetreas_get(NRF_RESET) determine which GPIO pin caused the wake?

I can read the button and see if it is being held.  I would like to know which GPIO pin caused the wake without having to hold the button down to signify the button that woke the device.

I don't see a way to do that.  Is that possible?

    reas = nrf_reset_resetreas_get(NRF_RESET);
    nrf_reset_resetreas_clear(NRF_RESET, reas);
    if (reas & NRF_RESET_RESETREAS_NFC_MASK) {
        LOG_DBG("Wake up by NFC field detect\n");
    } else if (reas & NRF_RESET_RESETREAS_RESETPIN_MASK) {
        LOG_DBG("Reset by pin-reset\n");
    } else if (reas & NRF_RESET_RESETREAS_SREQ_MASK) {
        LOG_DBG("Reset by soft-reset\n");
    } else if (reas) {
        LOG_DBG("Reset by a different source (0x%08X)\n", reas);
        int val=0;
#ifdef CONFIG_BOARD_NRF5340DK_NRF5340_CPUAPP
            val = gpio_pin_get_dt(&button2);
            if (val > 0) {
                LOG_DBG("button2 %d was held.",val);
            } else {
                LOG_DBG("button2 was NOT held.\n");
            }
            val = gpio_pin_get_dt(&button3);
            if (val > 0) {
                LOG_DBG("button3 %d was held.",val);
                }
            } else {
                LOG_DBG("button3 was NOT held.\n");
            }
#endif
Parents
  • Hello,

    You may try to read out the GPIO LATCH register on startup by doing something like this: 

    #include <hal/nrf_gpio.h>
    ...
        uint32_t latch_mask[GPIO_COUNT];
        nrf_gpio_latches_read_and_clear(0, GPIO_COUNT, latch_mask);
    
        for (int i=0; i < GPIO_COUNT; i++) {
            if (latch_mask[i] != 0) {
                printk("Latch for pin P%d.%d is set\n", i, NRF_CTZ(latch_mask[i]));
            }
        }

    You may also need to call nrf_gpio_latches_read_and_clear() before entering system OFF to ensure none of the latches are set.

    This approach assumes that the LATCH registers can't be set by other pins during boot. For instance, while the bootloader is running.

    Best regards,

    Vidar

Reply
  • Hello,

    You may try to read out the GPIO LATCH register on startup by doing something like this: 

    #include <hal/nrf_gpio.h>
    ...
        uint32_t latch_mask[GPIO_COUNT];
        nrf_gpio_latches_read_and_clear(0, GPIO_COUNT, latch_mask);
    
        for (int i=0; i < GPIO_COUNT; i++) {
            if (latch_mask[i] != 0) {
                printk("Latch for pin P%d.%d is set\n", i, NRF_CTZ(latch_mask[i]));
            }
        }

    You may also need to call nrf_gpio_latches_read_and_clear() before entering system OFF to ensure none of the latches are set.

    This approach assumes that the LATCH registers can't be set by other pins during boot. For instance, while the bootloader is running.

    Best regards,

    Vidar

Children
No Data
Related