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
  • Hi,

    This sounds fine.

    Which timer instance are you using? The Softdevice uses TIMER0 and RTC0, which means that these are not available to the application. Do you get any errors when you run the application?

    Note that the nRF52810 is very limited in available Flash/RAM space. If you plan to use s132 softdevice together with this chip, there will not be much space left for the application. If you are building a peripheral-only application, you should consider using s112 softdevice.

    Best regards,
    Jørgen

  • 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

  • Try changing this line:

    const nrfx_timer_t timerTareas = NRFX_TIMER_INSTANCE(0);

    to:

    const nrfx_timer_t timerTareas = NRFX_TIMER_INSTANCE(1);

    You may then have to enable TIMER1 in your sdk_config.h file by setting:

    #define NRFX_TIMER1_ENABLED 1

  • Hi Jorgen,

    Problem resolved. It was the instance.

    As far as RAM is concerned, I'll keep that in mind.

    I guess the functions in S132 will be equivalent in S112?

    Another question. Can you tell me if there is any documentation about the processes to follow and the functions to use to,

    for example, iniciate a connection, disconnection, data exchange, etc?. A block diagram or something similar that clearly indicates

    the processes to follow when we want to initiate an action.

    Thanks in advance

  • Hi,

    Juan said:
    I guess the functions in S132 will be equivalent in S112?

    The basic functionality is available in both, but s112 only support peripheral mode, no central mode. It also lacks support for features like Data Packet Length Extension (DLE) and L2CAP Connection-Oriented-Channels. You can see a full overview of the features on the softdevices respective product pages:

    Message Sequence Charts are available in the softdevice API documentations.

    Best regards,
    Jørgen

Related