Failure of GPIOTE configuration when multiple GPIOTEs are used in NRF Connect SDK

Hello,

I am trying to use GPIOTE for executing certain sections based on the trigger conditions. I am using 2 GPIOTEs. Below is the behavior I am seeing:

When I initialize the GPIOTEs, the first GPIOTE (GPIOTE1) is configured well, and the handler function gets executed when the trigger condition is met. 

However, the second GPIOTE (GPIOTE2) initialization won't happen properly. I confirmed this with return value of " err_code = nrfx_gpiote_input_configure(GPIO_PIN2, &in_config_gpiote2" . It's not NRFX_SUCCESS . I also set led to high state if the configuration fails. 

Because of this, the handler function for the second GPIOTE doesn't get executed even when the trigger condition is met.

If I interchange the order of GPIOTEs in the function (ie, initialize GPIOTE2 first and then GPIOTE1), GPIOTE2 would work and configuration of GPIOTE1 would fail. I have used different channels for both GPIOTEs.

I am not really understanding why this is happening. 

Below is my code

void gpio_setting_init(void)
{
    nrfx_err_t err_code;
    static uint8_t channel1;
    static uint8_t channel2;

 #if defined(__ZEPHYR__)
    IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_GPIOTE), IRQ_PRIO_LOWEST, nrfx_gpiote_irq_handler, 0);
 #endif

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

    err_code = nrfx_gpiote_channel_alloc(&channel1);
    NRFX_ASSERT(status == NRFX_SUCCESS);
    err_code = nrfx_gpiote_channel_alloc(&channel2);
    NRFX_ASSERT(status == NRFX_SUCCESS);


   static const nrfx_gpiote_input_config_t in_config_gpiote1=
    {
        .pull = NRF_GPIO_PIN_NOPULL,
    };

   // Finds rising edge instead of just toggling
    static const nrfx_gpiote_trigger_config_t trigger_config_gpiote1 = {
		.trigger = NRFX_GPIOTE_TRIGGER_LOTOHI,
        .p_in_channel = &channel1,
	};

	static const nrfx_gpiote_handler_config_t handler_config_gpiote1 = {
		.handler = in_pin_handler_gpiote1,
	};

    // gpiote initialization has been done in clock and timer initialization, no need to do it again
    err_code = nrfx_gpiote_input_configure(GPIO_PIN1, &in_config_gpiote1, &trigger_config_gpiote1, &handler_config_gpiote1);
    NRFX_ASSERT(status == NRFX_SUCCESS);

    nrfx_gpiote_trigger_enable(GPIO_PIN1, true);
  //if (err_code != NRFX_SUCCESS)
   //     gpio_pin_set(gpio0, TEST_PIN, 1);
        
        
    if (!nrfx_gpiote_is_init())
    {
        err_code = nrfx_gpiote_init(NRFX_GPIOTE_DEFAULT_CONFIG_IRQ_PRIORITY);
    }
    
    static const nrfx_gpiote_input_config_t in_config_gpiote2 = {
        .pull = NRF_GPIO_PIN_NOPULL,
    };

  // Finds rising edge instead of just toggling
    static const nrfx_gpiote_trigger_config_t trigger_config_gpiote2 = {
		.trigger = NRFX_GPIOTE_TRIGGER_HITOLO,
        .p_in_channel = &channel2,
	};

	static const nrfx_gpiote_handler_config_t handler_config_gpiote2 = {
		.handler = in_pin_handler_gpiote2,
	};

    // gpiote initialization has been done in clock and timer initialization, no need to do it again
    err_code = nrfx_gpiote_input_configure(GPIO_PIN2, &in_config_gpiote2, &trigger_config_gpiote2, &handler_config_gpiote2);
    NRFX_ASSERT(status == NRFX_SUCCESS);
    if (err_code != NRFX_SUCCESS)
        gpio_pin_set(gpio0, TEST_PIN, 1);


    nrfx_gpiote_trigger_enable(GPIO_PIN2, true);


    LOG_INF("nrfx_gpiote initialized");

}

I tried writing  2 sets of GPIOTEs in 2 different functions. But the behavior is the same. The first GPIOTE function called is executed based on the trigger condition. The second one doesnt get configured well. 

I am not sure what exactly is happening. I have a similar implementation with NRF52 in NRF5 SDK. I was trying to migrate the code to NRF Connect SDK with updated commands. However, this is a new scenario that I am observing. 

I would need some help in making this work.

Related