This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

APPLICATION HANGS USING nrfx_timer AND nrf_drv_gpiote WITH ble_stack_init()

Hi,

I am carrying out a project that tries to collect the information from a sensor (sporadic activation), process it, and send it by BLE to a receiver to activate a relay. I have experience using uC/OS-II in Renesas uP; but because the application I need is simple, I prefer to use a foreground/background system instead of an RTOS or by events since I find the way of acting used in the examples that come with the nRF5 SDK is very complicated. My idea is to create a system of device control modules in both, the peripheral and the central (pushbuttons, LEDs, I2C bus, BLE, etc). The uP will be asleep and will wake up for example due to an external interruption (sensor, pushbutton, etc.) Of course, the BLE will have the highest priority. The BLE management module would act similarly to the compact modules that use AT commands; but here they would be function calls to configure, activate, deactivate, etc. For this, I need to create a periodic timer that will call each routine of each device to control it, and a main routine with task control. In the final application I will use nRF52810 I have tried the ble_app_blinky Client and Server examples with the PCA10040 board and they work fine. A simple application works well only with the timer, LEDs and buttons; but when starting the BLE stack, it hangs.
I use: - Windows 7 - nRF52 DK - nRF5 SDK v17.0.2 - SoftDevice S132 v7.2.0 - SEGGER Embedded Studio
Do you consider correct the way to manage the application? Could you tell me what I'm doing wrong and the possible solution?

Thanks in advance
Parents
  • Hi Jorgen,

    There are no errors in the compilation.

    This is a simple example:

    /****************************************************************
    * TIMER TAREAS
    ****************************************************************/
    const nrfx_timer_t timerTareas = NRFX_TIMER_INSTANCE(0);

    void timer_tareas_event_handler(nrf_timer_event_t event_type, void *p_context)
    {
    static INT32U i;
    INT32U led_to_invert = ((i++) % 2);

    switch (event_type) {
    case NRF_TIMER_EVENT_COMPARE3:
    cboard_led_toggle(led_to_invert);
    break;
    default:
    //Do nothing.
    break;
    }
    }

    void timer_init (void)
    {
    INT32U err_code = NRF_SUCCESS;
    INT32U time_ms = 500; //Time(in miliseconds) between consecutive compare events.
    INT32U time_ticks;

    //Configure timerTareas for generating simple light effect - leds on board will invert his state one after the other.
    nrf_drv_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_125kHz;
    err_code = nrfx_timer_init(&timerTareas, &timer_cfg, timer_tareas_event_handler);
    APP_ERROR_CHECK(err_code);

    time_ticks = nrfx_timer_ms_to_ticks(&timerTareas, time_ms);

    nrfx_timer_extended_compare(&timerTareas, NRF_TIMER_CC_CHANNEL3, time_ticks, NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK, true);

    nrfx_timer_clear(&timerTareas);
    nrfx_timer_enable(&timerTareas);
    }

    /****************************************************************
    * PIN_IN = input, PIN_OUT = output, GPIOTE = interrupt on pin change
    ****************************************************************/
    void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
    cboard_led_toggle(BLED3);
    }

    static void gpio_init(void)
    {
    INT32U err_code;

    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);

    err_code = nrf_drv_gpiote_out_init(cboard_led_tab(BLED3), &out_config);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(cboard_button_tab(BBUTT3), &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(cboard_button_tab(BBUTT3), true);
    }

    /****************************************************************
    * MAIN FUNCTION
    ****************************************************************/
    int main(void)
    {
    // Initialize.
    //log_init();
    //leds_init();

    cboard_init(); // Configure all leds on board
    timer_init(); // Configure timerTasks
    gpio_init(); // Configure IN-OUT pins

    //timers_init();
    //buttons_init();
    power_management_init();
    ble_stack_init();

    //gap_params_init();
    //gatt_init();
    //services_init();
    //advertising_init();
    //conn_params_init();

    // Start execution.
    NRF_LOG_INFO("Blinky example started.");
    //advertising_start();

    // Enter main loop.
    forever ()
    {
    //__WFI(); //Wait For Interrupt = suspends execution until one of a number of events occurs.
    //__WFE(); // Wait For Event = permits the processor to enter a low-power state until one of a number of events occurs.
    idle_state_handle();
    }
    }

    Thanks

Reply
  • Hi Jorgen,

    There are no errors in the compilation.

    This is a simple example:

    /****************************************************************
    * TIMER TAREAS
    ****************************************************************/
    const nrfx_timer_t timerTareas = NRFX_TIMER_INSTANCE(0);

    void timer_tareas_event_handler(nrf_timer_event_t event_type, void *p_context)
    {
    static INT32U i;
    INT32U led_to_invert = ((i++) % 2);

    switch (event_type) {
    case NRF_TIMER_EVENT_COMPARE3:
    cboard_led_toggle(led_to_invert);
    break;
    default:
    //Do nothing.
    break;
    }
    }

    void timer_init (void)
    {
    INT32U err_code = NRF_SUCCESS;
    INT32U time_ms = 500; //Time(in miliseconds) between consecutive compare events.
    INT32U time_ticks;

    //Configure timerTareas for generating simple light effect - leds on board will invert his state one after the other.
    nrf_drv_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG;
    timer_cfg.frequency = NRF_TIMER_FREQ_125kHz;
    err_code = nrfx_timer_init(&timerTareas, &timer_cfg, timer_tareas_event_handler);
    APP_ERROR_CHECK(err_code);

    time_ticks = nrfx_timer_ms_to_ticks(&timerTareas, time_ms);

    nrfx_timer_extended_compare(&timerTareas, NRF_TIMER_CC_CHANNEL3, time_ticks, NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK, true);

    nrfx_timer_clear(&timerTareas);
    nrfx_timer_enable(&timerTareas);
    }

    /****************************************************************
    * PIN_IN = input, PIN_OUT = output, GPIOTE = interrupt on pin change
    ****************************************************************/
    void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
    cboard_led_toggle(BLED3);
    }

    static void gpio_init(void)
    {
    INT32U err_code;

    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);

    err_code = nrf_drv_gpiote_out_init(cboard_led_tab(BLED3), &out_config);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(cboard_button_tab(BBUTT3), &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(cboard_button_tab(BBUTT3), true);
    }

    /****************************************************************
    * MAIN FUNCTION
    ****************************************************************/
    int main(void)
    {
    // Initialize.
    //log_init();
    //leds_init();

    cboard_init(); // Configure all leds on board
    timer_init(); // Configure timerTasks
    gpio_init(); // Configure IN-OUT pins

    //timers_init();
    //buttons_init();
    power_management_init();
    ble_stack_init();

    //gap_params_init();
    //gatt_init();
    //services_init();
    //advertising_init();
    //conn_params_init();

    // Start execution.
    NRF_LOG_INFO("Blinky example started.");
    //advertising_start();

    // Enter main loop.
    forever ()
    {
    //__WFI(); //Wait For Interrupt = suspends execution until one of a number of events occurs.
    //__WFE(); // Wait For Event = permits the processor to enter a low-power state until one of a number of events occurs.
    idle_state_handle();
    }
    }

    Thanks

Children
Related