<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>app_timer2 assert by APP_TIMER_SAFE_WINDOW</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/66183/app_timer2-assert-by-app_timer_safe_window</link><description>Hi, 
 
 There was an app timer immediate expiration issue with my project which is using nrf52840 + S DK 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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 30 Sep 2020 13:41:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/66183/app_timer2-assert-by-app_timer_safe_window" /><item><title>RE: app_timer2 assert by APP_TIMER_SAFE_WINDOW</title><link>https://devzone.nordicsemi.com/thread/272342?ContentTypeID=1</link><pubDate>Wed, 30 Sep 2020 13:41:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc7b245c-53d3-482f-91a6-98797696225d</guid><dc:creator>eleven-x_devteam</dc:creator><description>&lt;p&gt;Thank you for your answer.&lt;/p&gt;
&lt;p&gt;So I fixed this with&amp;nbsp;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt;&amp;nbsp;APP_TIMER_SAFE_WINDOW_MS&amp;nbsp;&lt;/span&gt;&lt;span&gt;512000 to avoid the assert.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: app_timer2 assert by APP_TIMER_SAFE_WINDOW</title><link>https://devzone.nordicsemi.com/thread/272292?ContentTypeID=1</link><pubDate>Wed, 30 Sep 2020 12:08:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab094224-fb35-4f04-848a-fafbd87a52c9</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;Sorry for my late reply.&lt;br /&gt;&lt;br /&gt;I seems I have made a mistake here, my apologies - I provided the wrong link and inaccurate information in my initial reply.&lt;br /&gt;I&amp;nbsp;will update the initial reply with the correct reference and information.&lt;br /&gt;&lt;br /&gt;In essence, the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fgroup__app__timer__config.html&amp;amp;anchor=ga105771199c89ad6477bb9ae69efd8018"&gt;APP_TIMER_SAFE_WINDOW_MS&lt;/a&gt;&amp;nbsp;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.&lt;br /&gt;Sorry for the inaccurate information earlier, I must have misread which define you were asking about.&lt;br /&gt;&lt;br /&gt;An exempt from the APP_TIMER_SAFE_WINDOW_MS documentation reads:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;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.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The exempt above also explains the assert you are seeing.&lt;br /&gt;There is a note attached to the assert states that the safe window should be increased if this assert fails.&lt;/p&gt;
[quote user="eleven-x_devteam"]&lt;p&gt;I am using system_on since I&amp;#39;ve check power mode at the beginning of this project that it&amp;#39;s not available to use rtc wake up with system off mode.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;[/quote]
&lt;p&gt;Thank you for clarifying.&lt;br /&gt;You are correct; you may not use the RTC to wake up from SYSTEM OFF - that would require an external interrupt.&lt;br /&gt;&lt;br /&gt;Again, I am sorry for any confusion this might have caused.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: app_timer2 assert by APP_TIMER_SAFE_WINDOW</title><link>https://devzone.nordicsemi.com/thread/271397?ContentTypeID=1</link><pubDate>Thu, 24 Sep 2020 18:00:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6cb16cfa-d1be-471c-9d27-01c7452dd5f9</guid><dc:creator>eleven-x_devteam</dc:creator><description>&lt;p&gt;One more thing, I think this assert can happen even with a small timeout if you use 32k because the app timer2 supports 64 bit rtc counter and the end_val is 64 bit and&amp;nbsp;it will be bit masked&amp;nbsp;of 24 bit in&amp;nbsp;&lt;span&gt;app_timer_cnt_diff_compute and the diff could be larger than&amp;nbsp;APP_TIMER_SAFE_WINDOW. But I guess the reason why apptimer2 supports 64 bits rtc counter is to&amp;nbsp;be able to calculate&amp;nbsp;the counter even with 32K. Then the assert code seems not so meaningful in this case.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: app_timer2 assert by APP_TIMER_SAFE_WINDOW</title><link>https://devzone.nordicsemi.com/thread/271394?ContentTypeID=1</link><pubDate>Thu, 24 Sep 2020 17:00:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d109013-ea94-460c-b657-b582e0a99211</guid><dc:creator>eleven-x_devteam</dc:creator><description>&lt;p&gt;Thank you for your answer.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/66183/app_timer2-assert-by-app_timer_safe_window/271243"]If possible, I would highly recommend this, if your device is only going to wake up every 48 Hour - it would save&amp;nbsp;&lt;em&gt;a lot&amp;nbsp;&lt;/em&gt;of power, to stay in SYSTEM_OFF for those 48 hours, rather than a low power SYSTEM ON state ( with timers running ).[/quote]
&lt;p&gt;I am using system_on since I&amp;#39;ve check power mode at the beginning of this project that it&amp;#39;s not available to use rtc wake up with system off mode.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/66183/app_timer2-assert-by-app_timer_safe_window/271243"]I do not quite understand this question, you have not shown me any code in which you use app_timer_cnt_diff_compute.[/quote]
&lt;p&gt;I meant the code in my&amp;nbsp;original post.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In &amp;quot;components/libraries/timer/app_timer2.c&amp;quot;:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;ASSERT&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;app_timer_cnt_diff_compute&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;drv_rtc_counter_get&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;p_instance&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;mp_active_timer&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;end_val&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;amp;&amp;nbsp;RTC_COUNTER_COUNTER_Msk)&amp;nbsp;&amp;lt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;APP_TIMER_SAFE_WINDOW&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;[quote userid="87869" url="~/f/nordic-q-a/66183/app_timer2-assert-by-app_timer_safe_window/271243"]I would advise against it if you plan on using any app_timer for any other purpose.[/quote]&lt;span&gt;-&amp;gt; Do you mean multiple uses of the app timer? I am using the app timer for device wakeup and sensor response timeout also nrf_serial driver also using but I haven&amp;#39;t got any issue.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;I guess ignoring the assert probably should be fine but you are just not sure 100% if it&amp;#39;ll be OK in any case, am I correct?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: app_timer2 assert by APP_TIMER_SAFE_WINDOW</title><link>https://devzone.nordicsemi.com/thread/271243?ContentTypeID=1</link><pubDate>Thu, 24 Sep 2020 07:54:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca77821a-d1f0-4b5c-9a55-592dda16fda9</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="eleven-x_devteam"]Thank you for supporting[/quote]
&lt;p&gt;No problem at all, I am happy to help!&lt;/p&gt;
[quote user="eleven-x_devteam"]-&amp;gt; It doesn&amp;#39;t need to be so accurate but I am using the apptimer rtc counter as the OS system tick as well so it should be high resolution.[/quote][quote user="eleven-x_devteam"]-&amp;gt; it&amp;#39;s for system tick.[/quote]
&lt;p&gt;Thank you for clarifying.&lt;/p&gt;
[quote user="eleven-x_devteam"]so if possible, I want to keep using apptimer for both sleep/wakeup timer and rtc counter as system tick.[/quote]
&lt;p&gt;Well, this depends on what sleep mode you are intending to use. If you are in SYSTEM_OFF mode ( lowest possible power consumption ) then you will need an external interrupt to wake up.&lt;br /&gt;If possible, I would highly recommend this, if your device is only going to wake up every 48 Hour - it would save&amp;nbsp;&lt;em&gt;a lot&amp;nbsp;&lt;/em&gt;of power, to stay in SYSTEM_OFF for those 48 hours, rather than a low power SYSTEM ON state ( with timers running ).&lt;/p&gt;
[quote user="eleven-x_devteam"]so still I need the&amp;nbsp;&lt;span&gt;app_timer_cnt_diff_compute code for any other reasons?&lt;/span&gt;[/quote]
&lt;p&gt;I do not quite understand this question, you have not shown me any code in which you use app_timer_cnt_diff_compute.&lt;br /&gt;If you are asking if you can ignore the assert for the size of&amp;nbsp;&lt;span&gt;APP_TIMER_SAFE_WINDOW, then I must say that you&amp;nbsp;&lt;em&gt;can&lt;/em&gt;, but I would advise against it if you plan on using any app_timer for any other purpose.&lt;br /&gt;Altering of any driver might break it in unforeseen&amp;nbsp;ways.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: app_timer2 assert by APP_TIMER_SAFE_WINDOW</title><link>https://devzone.nordicsemi.com/thread/270903?ContentTypeID=1</link><pubDate>Tue, 22 Sep 2020 14:51:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff9ecea9-bbe2-48e1-90e5-33c973a7670d</guid><dc:creator>eleven-x_devteam</dc:creator><description>&lt;p&gt;Thank you for supporting&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/66183/app_timer2-assert-by-app_timer_safe_window/270732"]How high resolution do you need on this 48 hour wakeup?[/quote]
&lt;p&gt;-&amp;gt; It doesn&amp;#39;t need to be so accurate but I am using the apptimer rtc counter as the OS system tick as well so it should be high resolution.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/66183/app_timer2-assert-by-app_timer_safe_window/270732"]Is there a particular reason for having the app timer configured to 32 kHz?[/quote]
&lt;p&gt;-&amp;gt; it&amp;#39;s for system tick.&lt;/p&gt;
&lt;p&gt;I know I can use apptimer for sleep/wakeup and other rtc for system tick&amp;nbsp;and I&amp;#39;ve tried that but there was&amp;nbsp;another issue by using apptimer for sleep/wakeup and using other rtc for system tick. so if possible, I want to keep using apptimer for both sleep/wakeup timer and rtc counter as system tick.&lt;/p&gt;
&lt;p&gt;so still I need the&amp;nbsp;&lt;span&gt;app_timer_cnt_diff_compute code for any other reasons?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: app_timer2 assert by APP_TIMER_SAFE_WINDOW</title><link>https://devzone.nordicsemi.com/thread/270732?ContentTypeID=1</link><pubDate>Tue, 22 Sep 2020 07:07:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39945de4-4dd9-4a87-a10a-62beb2406be9</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]&lt;p&gt;&lt;/p&gt;
&lt;div&gt;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.&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;I guess&amp;nbsp;&lt;span&gt;app_timer_cnt_diff_compute with 24-bit mask seems not to fit this long time timer.&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&lt;br /&gt;Yes, this is correct - as can be seen in the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fgroup__app__timer__config.html&amp;amp;anchor=ga105771199c89ad6477bb9ae69efd8018"&gt;APP_TIMER_SAFE_WINDOW_MS documentation&lt;/a&gt;&amp;nbsp;- &lt;s&gt;the APP_TIMER_SAFE_WINDOW_MS is the maximum value that the app_timer_cnt_diff_compute is allowed to return. With your 24 bit counter width and 32768 Hz frequency you have a potential maximum of 512000 ms. Since this is &amp;gt; your APP_TIMER_SAFE_WINDOW_MS, it asserts.&lt;/s&gt;&lt;/p&gt;
&lt;p&gt;How high resolution do you need on this 48 hour wakeup? If you reduce your RTC frequency you can avoid waking up so often as every 9th minute.&lt;/p&gt;
&lt;p&gt;Is there a particular reason for having the app timer configured to 32 kHz?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>