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

Hard fault on the timer interrupt with Softdevice project included

I am using nRF SDK 16,0 and ble_app_template for pca10040 with Softdevice 132.

The example works fine, on my DK board but I need to utilize timers for my application.

Since TIMER0 is reserved for SoftDevice, I tried to initialize TIMER1,2,3 or 4 using the following implementation:

static nrf_drv_timer_t timer = \
{ \
    .p_reg = NRFX_CONCAT_2(NRF_TIMER, 1), \
    .instance_id = 1, \
    .cc_channel_count = NRF_TIMER_CC_CHANNEL_COUNT(1), \
};

static void ims_us_timer_init(void)
{
    ret_code_t err_code;
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&us_timer, &timer_cfg, timer_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_compare(&us_timer, (nrf_timer_cc_channel_t)0,
    200 * 1000UL, true);
    nrf_drv_timer_enable(&us_timer);
}

However, if this code sticks to HardFault handler after enabling the timer. It doesn't crash only if, in nrf_drv_timer_compare function, the last parameter is set to false (disabled interrupt).

In any case, the callback (timer_handler) is not executed at all.

This code works well in the project that doesn't contain the SoftDevice.

Is there anything wrong I am doing or some constraints or collision between SoftDevice and Timers ?

Related