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

app_timer_mesh, app_button, FreeRTOS and Mesh

Hi there!

Okay, we're back again... I'm using ARMGCC in combination with Make, nRF5 SDK, nRF SDK for Mesh, FreeRTOS and C++. This time I wanted to use the APP_BUTTON library to get notified when a pin changes value. This works fine. The problem, however, is that it doesn't work when compiled with Mesh.

So, to be more clear; the APP_BUTTON library works fine in combination with FreeRTOS and the app_timer_freertos.c but doesn't work at all when the app_timer_freertos.c is replaced with app_timer_mesh.c. App_button.init then returns ERROR 8 [NRF_ERROR_INVALID_STATE]. I can't figure out how to resolve it... The code underneath results in the error.

void battery_c::gpiote_init(){
    APP_ERROR_CHECK(nrf_drv_gpiote_init());

    app_button_cfg_t charge_pin_config;
    charge_pin_config.pin_no = CHARGE_PIN;
    charge_pin_config.active_state = APP_BUTTON_ACTIVE_LOW;
    charge_pin_config.pull_cfg = NRF_GPIO_PIN_PULLUP;
    charge_pin_config.button_handler = pin_event_handler;

    app_button_cfg_t standby_pin_config;
    standby_pin_config.pin_no = STANDBY_PIN;
    standby_pin_config.active_state = APP_BUTTON_ACTIVE_LOW;
    standby_pin_config.pull_cfg = NRF_GPIO_PIN_PULLUP;
    standby_pin_config.button_handler = pin_event_handler;

    static app_button_cfg_t pin_configs[] = {charge_pin_config, standby_pin_config};

    APP_ERROR_CHECK(app_button_init(pin_configs, 2, 500));
    APP_ERROR_CHECK(app_button_enable());
}

The question boils down to the following; is it possible to use the APP_BUTTON library while the Mesh SDK is running? If so; how? Thanks in advance!

Kind regards,

Jochem

  • Hi, 

    Have you tried to step into the code and check which function actually returning NRF_ERROR_INVALID_STATE ? 
    If it's app_timer_create() call inside the app_button_init() returned error 8 then it's because app_timer_init() should be called prior to the call to app_timer_create(). 
    Please refer to our example in the SDK, we usually call timer_init() before any call to the app_button. 
    Btw, we have this example for mesh+ free RTOS, it may be useful for you: https://github.com/NordicPlayground/nrf-mesh-freeRTOS-example

  • Hi Hung,

    Well, now that you're saying it i'm starting to doubt wether or not I've tried adding app_timer_init() in front of it. I don't think it made a difference, but it indeed is the app_timer_create() call that's returning the error.

    I've got a hard deadline for tomorrow so don't really have time to look into it, but I definetely will in the future. I'll keep you updated.

    Oh and btw, I'm aware of the example. I took it as a guideline for the changes but am not using CMake. Thanks anyway.

    Kind regards,

    Jochem

Related