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

Setting up APP_TIMER results in hardware fault

I started with the ble_app_template example. This example uses the Button event and notifies it. I modified the project to send some other data as notification, instead of the button state. And for the data to be read an transmitted, I initialized a timer. My timer_init looks like this,

static void timers_init(void)
{
	uint32_t err_code;
    // Initialize timer module, making it use the scheduler
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS,     APP_TIMER_OP_QUEUE_SIZE, true);
	
	err_code = app_timer_create(&m_ldc_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                data_timeout_handler);
    APP_ERROR_CHECK(err_code);
}

where data_time_handler is the event handler for the timer.

My timer_start looks like this:

static void timers_start(void)
{
	  uint32_t err_code = app_timer_start(m_timer_id, HEART_RATE_MEAS_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);
}

Why would I be going in to a hard fault ?

Parents
  • What's err_code in the timers_start() function? If not zero then APP_ERROR_CHECK() is sending you into an error.

    Why is your variable called m_ldc_timer_id in the initialization and m_timer_id in the timers_start function? What is HEART_RATE_MEAS_INTERVAL?

  • "m_ldc_timer_id" and "m_timer_id" are the same, I made a typo there. Both should have been m_ldc_timer_id. HEART_RATE_MEAS_INTERVAL is set to 32767 (for 1 second).

    The device does not go into hard fault while initializing the timer. The device initializes and goes on to execute the main loop (verified through debugger)

    // Enter main loop
        for (;;)
        {
            app_sched_execute();
            power_manage();
        }
    

    On a BLE Scanner App I can see that it broadcasts and advertises in the beginning and then goes in to a hard fault.

    If I comment the timer initialization code, it seems to work fine. When I say works fine, I can see the device advertising and it appears on the BLE Scanner App. What is the best way to debug this ? Thank you.

Reply
  • "m_ldc_timer_id" and "m_timer_id" are the same, I made a typo there. Both should have been m_ldc_timer_id. HEART_RATE_MEAS_INTERVAL is set to 32767 (for 1 second).

    The device does not go into hard fault while initializing the timer. The device initializes and goes on to execute the main loop (verified through debugger)

    // Enter main loop
        for (;;)
        {
            app_sched_execute();
            power_manage();
        }
    

    On a BLE Scanner App I can see that it broadcasts and advertises in the beginning and then goes in to a hard fault.

    If I comment the timer initialization code, it seems to work fine. When I say works fine, I can see the device advertising and it appears on the BLE Scanner App. What is the best way to debug this ? Thank you.

Children
No Data
Related