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

app_timer crashes

Hi devzone-team,

my application (custom board with nrf52840, sdk 16.0.098) uses 12 timers and it's organize in the 3 parts: uart, a pwm-bus (proprietary) and ble-scan-advertising (no connections).

The application is based on the beacon-example and is expanded with uart-, scheduler, and io-functionality.

If only one of the program-component works, all is fine. If there are 2 or all 3 components works at the same time, after a few minutes the timer-module crashes. The most times the debugger show an error on line 299 in app_timer2

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
static void on_compare_evt(drv_rtc_t const * const p_instance)
{
if (mp_active_timer)
{
/* If assert fails it suggests that safe window should be increased. */
ASSERT(app_timer_cnt_diff_compute(drv_rtc_counter_get(p_instance),
--> line 299 --> mp_active_timer->end_val & RTC_COUNTER_COUNTER_Msk) < APP_TIMER_SAFE_WINDOW);
NRF_LOG_INST_DEBUG(mp_active_timer->p_log, "Compare EVT");
UNUSED_RETURN_VALUE(timer_expire(mp_active_timer));
mp_active_timer = NULL;
}
else
{
NRF_LOG_WARNING("Compare event but no active timer (already stopped?)");
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

sdk_config.h, the app_timer area

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// <e> APP_TIMER_ENABLED - app_timer - Application timer functionality
//==========================================================
#ifndef APP_TIMER_ENABLED
#define APP_TIMER_ENABLED 1
#endif
// <o> APP_TIMER_CONFIG_RTC_FREQUENCY - Configure RTC prescaler.
// <0=> 32768 Hz
// <1=> 16384 Hz
// <3=> 8192 Hz
// <7=> 4096 Hz
// <15=> 2048 Hz
// <31=> 1024 Hz
#ifndef APP_TIMER_CONFIG_RTC_FREQUENCY
#define APP_TIMER_CONFIG_RTC_FREQUENCY 1
#endif
// <o> APP_TIMER_CONFIG_IRQ_PRIORITY - Interrupt priority
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I test many things

* start only timers in scheduler (or normal functions), never in interrupt handlers

* makes timer in scheduler (what makes the error come faster)

* makes timer in interrupt

* works with global variables, works with scheduler-copy memory

But the final result is, thats the timer crashes the most times in minutes (sometimes after 1h or more).

My guess is that two or more timers overlap and the app_timer2 is pointing on a wrong timer and makes the assert.

Questions:

1) Can timer restarted in timer-handler (single shot timer)?

2) Can timer works with global variables (in interrupt and/or scheduler mode)?

3) I only make changes on sdk_config in APP_TIMER_CONFIG_OP_QUEUE_SIZE=32 but there is no possibility to change the MAX_TIMER value, perhaps the application cant work with 12 timer or more?

4) Is there a MAX-TIMER-counter, which have to be larger?

best regards

Bjoern