App Timer assert - APP_TIMER_SAFE_WINDOW

I have started getting an assert in my code while testing new functionality.

I am using SDK 17.1.0 and the nRF52840 DK

The assert is line 321 in app_timer2.c

        /* If assert fails it suggests that safe window should be increased. */
        ASSERT(app_timer_cnt_diff_compute(drv_rtc_counter_get(p_instance),
                                          drv_rtc_compare_get(p_instance, 0)) < APP_TIMER_SAFE_WINDOW);

Looking at the the description of APP_TIMER_SAFE_WINDOW_MS in sdk_config.h

// <o> APP_TIMER_SAFE_WINDOW_MS - Maximum possible latency (in milliseconds) of handling app_timer event.
// <i> Maximum possible timeout that can be set is reduced by safe window.
// <i> Example: RTC frequency 16384 Hz, maximum possible timeout 1024 seconds - APP_TIMER_SAFE_WINDOW_MS.
// <i> Since RTC is not stopped when processor is halted in debugging session, this value
// <i> must cover it if debugging is needed. It is possible to halt processor for APP_TIMER_SAFE_WINDOW_MS
// <i> without corrupting app_timer behavior.

#ifndef APP_TIMER_SAFE_WINDOW_MS
#define APP_TIMER_SAFE_WINDOW_MS 300000
#endif

Am I correct in thinking this means that this will assert if, for (1024-300) seconds, or ~12 minutes, the app_timer event is not handled?

If so, how do I go about debugging which timer isn't handled?

I initially saw this after leaving a board running for around 36hrs. I think I saw it again, didn't get the error log unforunately, after over 24 hours. I have tried to set up a test to replicate is and saw it withing 4-5 hours. It is still in sat in this state with the debugger attached but I don't know where to begin with working out the cause.

The debugger output is:

[03624616] <error> app: ERROR 3735928559 [Unknown error code] at nRF5_SDK_17.1.0_ddde560/components/libraries/timer/app_timer2.c:321
PC at: 0x000362B3
[03624623] <error> app: End of error report

I want to understand why this is occuring, why it isn't after a fixed period of time and whether increasing APP_TIMER_SAFE_WINDOW_MS is a fix or a bandaid.

Parents Reply Children
  • It is verified by the customer and not regression tested on our end. That is a workaround that is suggested by Nordic to be used at your own risk since we do not do any production release testing on that workaround and most likely will not be able to do it in the near future on the older SDK solutions.

  • Sorry guys, I assumed initially that's a joke, but I see that quite serious suggestion.

    Once a developer puts any kind of ASSERT, usually (not always) it protects from some more crucial conditions, generally protect one developer from another developer's stupidity, in common case it avoid many obvious errors in production. So smart developers try to insert such ASSERTs to show on early stage of code about wrong arguments, incorrect conditions, problems on runtime.

    I caught the same error today, that's why I've been writing the message right now.I don't know a reason why it happens in my code, but what should NOT be done absolutely: to comment the ASSERT in own SDK code while you haven't get deep understanding why the timer handling goes out of the range of expected lag window.

    Especially for people with such "easy fixes" approach in their head: just turn into Release mode from Debug, so you get no ASSERT macro anymore, but the assert call means you have got already an issue in your code.

  • Rost, 

    Good thoughts, I agree to most of it. But sometimes the developer puts an assert and figures out later when the assert is hitting in a condition when the use case is genuine, then their assumption of the state machine in a particular state is wrong. In this case, the actual developer thinks that the assert is catching a lot of false positives so probably that assert should not be there. 

    In General it is a good habit for a developer to put debug asserts in places where they know a condition should not occur, but sometimes (rarely), those asserts have bugs aswell. 

Related