This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

app_gpiote_user_register doesn't work with nRF52 SDK

My code is as follows:

APP_GPIOTE_INIT(4); retcode = app_gpiote_user_register(&gpioID, 0, (1 << INT_PIN_MAXIM), interrupt);

The latter function call seems to fail with retcode == NRF_ERROR_NO_MEM. When I look at the documentation, it says:

"NRF_ERROR_NO_MEM  Returned if the application tries to register more users than defined when the GPIOTE module was initialized in app_gpiote_init."

What could be wrong with this? Similar code seems to work with nRF51. I am using nRF5_SDK_11.0.0-2.alpha_bc3f6a0. There's also s132 soft device running (alpha version).

EDIT: I am using freeRTOS and it looks like xCreateTask() has something to do with this. Somehow creating a task allocates gpiote channels and that is why the call fails. I debugged a bit and the code fails here:

ret_code_t nrf_drv_gpiote_in_init(nrf_drv_gpiote_pin_t pin,
                                  nrf_drv_gpiote_in_config_t const * p_config,
                                  nrf_drv_gpiote_evt_handler_t evt_handler)
{
    ASSERT(pin < NUMBER_OF_PINS);
    ret_code_t result = NRF_SUCCESS;
    /* Only one GPIOTE channel can be assigned to one physical pin. */
    if (pin_in_use_by_gpiote(pin))
    {
        result = NRF_ERROR_INVALID_STATE;
    }
    else
    {
        int8_t channel = channel_port_alloc(pin, evt_handler, p_config->hi_accuracy);
        if (channel != NO_CHANNELS)
        {
            if (p_config->is_watcher)
            {
                nrf_gpio_cfg_watcher(pin);
            }
            else
            {
                nrf_gpio_cfg_input(pin,p_config->pull);
            }

            if (p_config->hi_accuracy)
            {
                nrf_gpiote_event_configure(channel, pin,p_config->sense);
            }
            else
            {
                m_cb.port_handlers_pins[channel-NUMBER_OF_GPIO_TE] |= (p_config->sense)<< SENSE_FIELD_POS;
            }
        }
        else
        {
            result = NRF_ERROR_NO_MEM; // THIS IS FROM WHERE THE ERROR COMES
        }
    }
    return result;
}
Related