nRF51822 and Zephyr: Use nrfx gpiote for GPIO interrupts

Hello,

We are using Zephyr v2.6 and nRF51822 SoC in our project.

Because we are porting the code from the SDK environment into the Zephyr environment, we decided to use nrfx gpiote drivers instead of Zephyr GPIO drivers. Consequently, our prj.conf file contains the following lines:

CONFIG_GPIO=n
CONFIG_NRFX_GPIOTE=y

There are two GPIOs that should be configured to interrupt CPU. To achieve that, the following lines of code are used:

// GPIO 1
nrf_gpio_cfg_input(PIN_ACCEL_INT1, NRF_GPIO_PIN_NOPULL);
nrfx_gpiote_in_config_t in_config_1 = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(false);
in_config_1.hi_accuracy = false;
in_config_1.pull = NRF_GPIO_PIN_PULLDOWN;
err_code = nrfx_gpiote_in_init(PIN_ACCEL_INT1, &in_config_1, gpiote_event_handler_1);

// GPIO 2
nrf_gpio_cfg_input(PIN_ACCEL_INT2, NRF_GPIO_PIN_NOPULL);
nrfx_gpiote_in_config_t in_config_2 = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
in_config_2.hi_accuracy = false;
in_config_2.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrfx_gpiote_in_init(PIN_ACCEL_INT2, &in_config_2, gpiote_event_handler_2);

//Enable interrupts
nrfx_gpiote_in_event_enable(PIN_ACCEL_INT1, true); 
nrfx_gpiote_in_event_enable(PIN_ACCEL_INT2, true); 

However, when I call the nrfx_gpiote_in_init() function for the second GPIO, this function returns 0xBAD0002 (NRFX_ERROR_NO_MEM).

Is there anything that I am missing here?

I've been told in some previous threads that nRF51822 contains 4 GPIOTE channels. Consequently, configuring two GPIOs to interrupt CPU should be feasible.

Thanks in advance for your time and efforts.

Sincerely,

Bojan.

Parents
  • For the second GPIO, I tried to allocate GPIOTE channel before initializing it with:

        uint8_t channel;
        err_code = nrfx_gpiote_channel_alloc(&channel);
        err_code = nrfx_gpiote_in_prealloc_init(PIN_ACCEL_INT2, &in_config_2, channel, gpiote_event_handler_2);

    nrfx_gpiote_channel_alloc() function properly allocates GPIOTE channel but the nrfx_gpiote_in_prealloc_init() returns 0xBAD0004 (NRFX_ERROR_INVALID_PARAM).

    According to the nrfx_gpiote_in_prealloc_init() brief description, this return code means that the pin is configured to not be controlled by the GPIOTE task and cannot be used with preallocated channel. It is also advised to use nrfx_gpiote_in_init() instead which, as I reported previously, returns 0xBAD0002 (NRFX_ERROR_NO_MEM).

Reply
  • For the second GPIO, I tried to allocate GPIOTE channel before initializing it with:

        uint8_t channel;
        err_code = nrfx_gpiote_channel_alloc(&channel);
        err_code = nrfx_gpiote_in_prealloc_init(PIN_ACCEL_INT2, &in_config_2, channel, gpiote_event_handler_2);

    nrfx_gpiote_channel_alloc() function properly allocates GPIOTE channel but the nrfx_gpiote_in_prealloc_init() returns 0xBAD0004 (NRFX_ERROR_INVALID_PARAM).

    According to the nrfx_gpiote_in_prealloc_init() brief description, this return code means that the pin is configured to not be controlled by the GPIOTE task and cannot be used with preallocated channel. It is also advised to use nrfx_gpiote_in_init() instead which, as I reported previously, returns 0xBAD0002 (NRFX_ERROR_NO_MEM).

Children
No Data
Related