Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRFX GPIOTE API and sensing with multiple pins recovering from system off

Hi there,

I've configured the NRFX API of GPIOTE to sense four pins to go from low to high. This works well while the device is on. When the device is off (via having called sd_power_system_off) then the sensing no longer appears to work. However, if I sense just one or two pins then it does work... I'm using nRF5_SDK_17.0.2_d674dde with an s140 soft device on the nRF52840 DK.

I'm wondering if I'm experiencing some race conditions as discussed in other threads.

Here's how my main calls up the GPIOTE initialisation function:

static void gpio_init()
{
    ret_code_t err_code;
    nrfx_gpiote_in_config_t pir_pin_config = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(false);

    if (!nrfx_gpiote_is_init())
    {
        err_code = nrfx_gpiote_init();
        APP_ERROR_CHECK(err_code);
    }

    err_code = nrfx_gpiote_in_init(m_left_entry_exit_outside_pir_pin, &pir_pin_config, on_gpio_in_evt);
    APP_ERROR_CHECK(err_code);
    nrfx_gpiote_in_event_enable(m_left_entry_exit_outside_pir_pin, true);

    err_code = nrfx_gpiote_in_init(m_left_entry_exit_inside_pir_pin, &pir_pin_config, on_gpio_in_evt);
    APP_ERROR_CHECK(err_code);
    nrfx_gpiote_in_event_enable(m_left_entry_exit_inside_pir_pin, true);

    err_code = nrfx_gpiote_in_init(m_right_entry_exit_outside_pir_pin, &pir_pin_config, on_gpio_in_evt);
    APP_ERROR_CHECK(err_code);
    nrfx_gpiote_in_event_enable(m_right_entry_exit_outside_pir_pin, true);

    err_code = nrfx_gpiote_in_init(m_right_entry_exit_inside_pir_pin, &pir_pin_config, on_gpio_in_evt);
    APP_ERROR_CHECK(err_code);
    nrfx_gpiote_in_event_enable(m_right_entry_exit_inside_pir_pin, true);
}

This function is called each time the device wakes up from sleep. I'm assuming that the NRFX GPIOTE API is built to handle the situation where GPIO events exist on entry otherwise the one/two sensing scenario wouldn't work.

Thanks for any pointers. This behaviour has been troubling me for a few days.

Parents Reply Children
  • Hi 

    Sorry for the slow response. 

    I have done some more testing, and it seems the library is not able to handle the situation where more than one pin is already activated when you enter sleep. 

    If two or more pins are activated by the time you enter system OFF then the device will reset immediately, configure the driver again in the same configuration, try to go to sleep again, and then reset again, going into an infinite reset loop until one or less pins are activated. 

    I have forwarded these findings to the developer, and he will also look into it to see if this is an issue in the driver. 

    As a workaround I expect this should work if you check the state of the pins before entering sleep, and configure the pins accordingly. 

    IE: Any pin that is currently high should be configured as HITOLO, and any pin that is currently low should be configured as LOTOHI. 

    Best regards
    Torbjørn

  • Hi again

    The developer looked into this, and found some potential issues in the driver that might explain the issues you are seeing. 

    I can describe the specifics in detail if you are interested, but first it would be helpful if you can try his proposed workaround and see if it solves it. 

    Essentially, at the start of main(), before you initialize the GPIOTE driver, you need to run the following two commands for every GPIO pin that you use for wakeup:

    nrf_gpio_cfg_default(PIN);
    nrf_gpio_pin_latch_clear(PIN);
    Can you try this and see if it works better?

    Best regards
    Torbjørn

  • No problem, just let me know when you have been able to test it. 

Related