nrf connect sdk 2.7.0 using gpiote interrupt - no callback trigger

I'm using the code below to trigger a callback on pin rising edge. 

Unfortunately, the counter is not being increased at all. Any reason why? 

I used multiple sources already to find out what could be missing in my application, for example:
GPIOTE not working in NRF Connect SDK 

https://docs.nordicsemi.com/bundle/ncs-2.7.0/page/nrfx/drivers/gpiote/driver.html


using pin p0.10 as input pin.

Devkit: nrf9161

#include <zephyr/kernel.h>
#include <nrfx_gpiote.h>
#include "test_gpiote_m.h"
#include <zephyr/irq.h>

#define INTERRUPT_PIN 10

const nrfx_gpiote_t my_gpiote = NRFX_GPIOTE_INSTANCE(0);
uint32_t counter = 0;
void callback(nrfx_gpiote_pin_t pin, nrfx_gpiote_trigger_t trigger, void *p_context) {
    counter++;
}

TEST_GPIOTE_M::TEST_GPIOTE_M() {}
TEST_GPIOTE_M::~TEST_GPIOTE_M() {}



bool TEST_GPIOTE_M::init() {
    uint8_t in_channel;
    if(nrfx_gpiote_in_is_set(INTERRUPT_PIN)) {
        printk("Pin is already set!\n");
        return false;
    }
    if(nrfx_gpiote_init_check(&my_gpiote)) {
        printk("Already initialized!\n");
        return false;
    }

    IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_GPIOTE), IRQ_PRIO_LOWEST, nrfx_gpiote_0_irq_handler,0);

    nrfx_err_t err = nrfx_gpiote_init(&my_gpiote, (uint8_t) 0);
    if(err != NRFX_SUCCESS) {
        printk("Failed to init GPIOTE: %d\n", err);
        return false;
    }

    err = nrfx_gpiote_channel_alloc(&my_gpiote, &in_channel);
	if (err != NRFX_SUCCESS) {
		printk("Failed to allocate in_channel, error: 0x%08X", err);
		return false;
	}

    nrf_gpio_pin_pull_t p_pull_config = NRF_GPIO_PIN_NOPULL;

    nrfx_gpiote_trigger_config_t p_trigger_config = {
        .trigger = NRFX_GPIOTE_TRIGGER_LOTOHI,   // Rising edge
        .p_in_channel = &in_channel
    };

    nrfx_gpiote_handler_config_t p_handler_config = {
        .handler = callback,
        .p_context = NULL
    };

    nrfx_gpiote_input_pin_config_t input_cfg = {
        .p_pull_config = &p_pull_config,
        .p_trigger_config = &p_trigger_config,
        .p_handler_config = &p_handler_config
    };

    //  NRF_GPIO_PIN_PULLDOWN
    //  NRF_GPIO_PIN_PULlUP
    //  NRF_GPIO_PIN_NOPULL
    nrf_gpio_cfg_input(INTERRUPT_PIN, NRF_GPIO_PIN_NOPULL);

    

    err = nrfx_gpiote_input_configure(&my_gpiote, INTERRUPT_PIN, &input_cfg);
    if(err != NRFX_SUCCESS) {
        printk("Failed to config GPIOTE: %d\n", err);
        return false;
    }

    nrfx_gpiote_global_callback_set(&my_gpiote, callback, NULL);

    if(nrfx_gpiote_in_is_set(INTERRUPT_PIN)) {
        printk("Pin is used 2!\n");
    }
    return true;
}

void TEST_GPIOTE_M::stop() {
    nrfx_gpiote_trigger_disable(&my_gpiote, INTERRUPT_PIN);
}

void TEST_GPIOTE_M::start() {
    nrfx_gpiote_trigger_enable(&my_gpiote, INTERRUPT_PIN, true);
}

void TEST_GPIOTE_M::results() {
    printk("result: %i\n", counter);
}

My main.cpp:

#include <zephyr/kernel.h>
#include "test_gpiote_m.h"


int main(void)
{
    TEST_GPIOTE_M t = TEST_GPIOTE_M();
    if(!t.init()) {
        printk("Failed to initialize!");
    }
    
    t.start();
    while(true) {
        k_msleep(1000);
        t.results();
    }
    return 0;
}

prj.conf:

# CONFIG_GPIO=y
CONFIG_LOG=y
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_MODE_DEFERRED=n
CONFIG_INIT_STACKS=y
CONFIG_ASSERT=y

#   root cause of i2c explained here: https://devzone.nordicsemi.com/f/nordic-q-a/117139/bus-fault-on-just-enabling-config_i2c-y-on-nrf5340dk
#   solution is to disable secure uart or something
CONFIG_TFM_SECURE_UART=n
CONFIG_TFM_LOG_LEVEL_SILENCE=y

CONFIG_GPIO_NRFX=y
CONFIG_NRFX_GPIOTE0=y
CONFIG_NRFX_GPIOTE_NUM_OF_EVT_HANDLERS=1

Related