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

app_timer2 assert by APP_TIMER_SAFE_WINDOW

Hi,

There was an app timer immediate expiration issue with my project which is using nrf52840 + SDK 15.3.0 on custom board.

So I changed apptimer code to app timer2 like the issue post below.

https://devzone.nordicsemi.com/f/nordic-q-a/62406/app-timer-sometimes-expires-immediately

Recently, I've enbled nrf assert to catch unknow issues and then an assert happens like below. (booting -> leave the device for a while)

In "components/libraries/timer/app_timer2.c":

        ASSERT(app_timer_cnt_diff_compute(drv_rtc_counter_get(p_instance),

                                          mp_active_timer->end_val & RTC_COUNTER_COUNTER_Msk) < APP_TIMER_SAFE_WINDOW);

The settings I am using :
#define APP_TIMER_SAFE_WINDOW_MS 300000
#define APP_TIMER_CONFIG_RTC_FREQUENCY 0  // <0=> 32768 Hz 
The device sleep time could be maximum 48 hours but usually, 1 hour but 24bit counter just have around 8~9 minutes and it will be reset.
I guess app_timer_cnt_diff_compute with 24-bit mask seems not to fit this long time timer.
Can I ignore that assert or any other suggestions?
Thank you.
  • Hello,

    Sorry for my late reply.

    I seems I have made a mistake here, my apologies - I provided the wrong link and inaccurate information in my initial reply.
    I will update the initial reply with the correct reference and information.

    In essence, the APP_TIMER_SAFE_WINDOW_MS is actually used to set the maximum latency for handling of app_timer events. Since the RTC will keep ticking regardless of the events tied to it, there might be tasks that require handling within a certain time to ensure proper operation.
    Sorry for the inaccurate information earlier, I must have misread which define you were asking about.

    An exempt from the APP_TIMER_SAFE_WINDOW_MS documentation reads:

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

    The exempt above also explains the assert you are seeing.
    There is a note attached to the assert states that the safe window should be increased if this assert fails.

    eleven-x_devteam said:

    I am using system_on since I've check power mode at the beginning of this project that it's not available to use rtc wake up with system off mode.

    And the 48 hours is just a maximum case. For example, the device wakes up hourly checking significant data and it wakes up every 24 or 48 hours for non-significant data. Also, it can wake up any interrupt of some sensors any time. so the timeout for the app timer is various.

    Thank you for clarifying.
    You are correct; you may not use the RTC to wake up from SYSTEM OFF - that would require an external interrupt.

    Again, I am sorry for any confusion this might have caused.

    Best regards,
    Karl

  • Thank you for your answer.

    So I fixed this with #define APP_TIMER_SAFE_WINDOW_MS 512000 to avoid the assert.

Related