<?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>Assert in FreeRTOS task.c: configASSERT( ( xTickCount + xTicksToJump ) &amp;lt;= xNextTaskUnblockTime )</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67434/assert-in-freertos-task-c-configassert-xtickcount-xtickstojump-xnexttaskunblocktime</link><description>Hello, 
 I am using configUSE_TICKLESS_IDLE with RTC2 setup for FreeRTOS tick, occasionally I am seeing the asserting in task.c at line configASSERT( ( xTickCount + xTicksToJump ) &amp;lt;= xNextTaskUnblockTime ). Looking at the tickless idle code, I am wondering</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 04 Jun 2025 13:50:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67434/assert-in-freertos-task-c-configassert-xtickcount-xtickstojump-xnexttaskunblocktime" /><item><title>RE: Assert in FreeRTOS task.c: configASSERT( ( xTickCount + xTicksToJump ) &lt;= xNextTaskUnblockTime )</title><link>https://devzone.nordicsemi.com/thread/538084?ContentTypeID=1</link><pubDate>Wed, 04 Jun 2025 13:50:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d691257a-c36a-4143-a3db-17f7daaebb3f</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;This ticket is more than 4 years old at this point. Please create a new ticket where you explain your issue in detail and possibly link to this one if you find it relevant.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assert in FreeRTOS task.c: configASSERT( ( xTickCount + xTicksToJump ) &lt;= xNextTaskUnblockTime )</title><link>https://devzone.nordicsemi.com/thread/537941?ContentTypeID=1</link><pubDate>Tue, 03 Jun 2025 19:21:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c3b2cf8-2aa8-473a-8aec-72b233af5396</guid><dc:creator>jthmp</dc:creator><description>&lt;p&gt;Any update on a fix for this? we are having the same problem and it&amp;#39;s preventing us from using the low power features of nrf52840 with freertos.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assert in FreeRTOS task.c: configASSERT( ( xTickCount + xTicksToJump ) &lt;= xNextTaskUnblockTime )</title><link>https://devzone.nordicsemi.com/thread/313930?ContentTypeID=1</link><pubDate>Mon, 07 Jun 2021 12:51:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63472639-c82d-4cb5-9c6c-e3de7df4ec0e</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Ray,&lt;/p&gt;
&lt;p&gt;You found a bug in the FreeRTOS tickless sleep handler. Thank you for very clear info. But I do not think there is a clear way to fix this completely without masking all interrupts for very small time (which we have been trying our best not to do when using softdevice)&lt;/p&gt;
&lt;p&gt;The issue here is that any higher priority (sodtdevice specific) context preempting the&amp;nbsp;&lt;span&gt;&lt;span&gt;vPortSuppressTicksAndSleep function just after wakeup (from __WFE/&lt;/span&gt;&lt;/span&gt;sd_app_evt_wait) and calculating the diff and if that higher context has not yielded control back to this&amp;nbsp;&lt;span&gt;vPortSuppressTicksAndSleep&amp;nbsp; before the compare register gets incremented, then the FreeRTOS kernel is not happy about it because of the way it increments ticks&amp;nbsp;&lt;/span&gt;vTaskStepTick in one go.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Try increasing configEXPECTED_IDLE_TIME_BEFORE_SLEEP to 3&amp;nbsp;which reduces the chances of this happening (not a fix, just a workaround)&lt;/li&gt;
&lt;li&gt;To have this fix properly, we need to disable all interrupts (Even softdevice) so that nothing preempts the clocks correction mechanism after tickless wakeup inside vPortSuppressTicksAndSleep. right now we use&amp;nbsp; sd_nvic_critical_region_enter when using softdevice which only disables application specific interrupts. So softdevice activity can still preempt the tickless update after wakeup&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assert in FreeRTOS task.c: configASSERT( ( xTickCount + xTicksToJump ) &lt;= xNextTaskUnblockTime )</title><link>https://devzone.nordicsemi.com/thread/313763?ContentTypeID=1</link><pubDate>Fri, 04 Jun 2021 22:12:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ed949f6-9d1a-4342-ba96-71a39a516f75</guid><dc:creator>Ray Ma</dc:creator><description>&lt;p&gt;Hey Simonr,&lt;/p&gt;
&lt;p&gt;I want to bring up this issue again, it doesn&amp;#39;t happen all the time but now I found a way to repro it reliably. So I tried the patch you suggested above and still have this issue. By atttaching GDB I have some better understanding now:&lt;/p&gt;
&lt;p&gt;Here we expect it sleeps for 2 tick but coming back from WFE we are seeing 3 tick difference on the RTC counter, so it assert in task.c 2505&lt;pre class="ui-code" data-mode="c_cpp"&gt;#if ( configUSE_TICKLESS_IDLE != 0 )

	void vTaskStepTick( const TickType_t xTicksToJump )
	{
		/* Correct the tick count value after a period during which the tick
		was suppressed.  Note this does *not* call the tick hook function for
		each stepped tick. */
		configASSERT( ( xTickCount + xTicksToJump ) &amp;lt;= xNextTaskUnblockTime );
		xTickCount += xTicksToJump;
		traceINCREASE_TICK_COUNT( xTicksToJump );
	}

#endif /* configUSE_TICKLESS_IDLE */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-weight:400;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#1&amp;#160; 0x0004287a in vTaskStepTick (xTicksToJump=3) at FreeRTOS/Source/tasks.c:2505

#2&amp;#160; 0x00044bb4 in vPortSuppressTicksAndSleep (xExpectedIdleTime=2) at nrf_sdk/nRF5_SDK_16.0.0_98a08e2/external/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c:281

#3&amp;#160; 0x00042b62 in prvIdleTask (pvParameters=&amp;lt;optimized out&amp;gt;) at&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I tried to disable the software device and the same repro steps doesn&amp;#39;t cause the issue any more. I am wondering if it&amp;#39;s the SD event handing causing the delay.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;-Ray&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assert in FreeRTOS task.c: configASSERT( ( xTickCount + xTicksToJump ) &lt;= xNextTaskUnblockTime )</title><link>https://devzone.nordicsemi.com/thread/277303?ContentTypeID=1</link><pubDate>Wed, 28 Oct 2020 09:07:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0fde3a3-6ea0-4acb-b623-1f0b887d7f45</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;sd_app_evt_wait() is a function intended to let the SoftDevice disable the necessary peripherals, etc. before going to sleep if the SoftDevice is used in an application.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assert in FreeRTOS task.c: configASSERT( ( xTickCount + xTicksToJump ) &lt;= xNextTaskUnblockTime )</title><link>https://devzone.nordicsemi.com/thread/277260?ContentTypeID=1</link><pubDate>Tue, 27 Oct 2020 23:27:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72ee43a6-8a82-424e-b5ed-199f9ab3795f</guid><dc:creator>Ray Ma</dc:creator><description>&lt;p&gt;Hey Simon, I&amp;#39;ll give that a try. What&amp;#39;s the difference between&amp;nbsp;sd_app_evt_wait() and WFE()?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;-Ray&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assert in FreeRTOS task.c: configASSERT( ( xTickCount + xTicksToJump ) &lt;= xNextTaskUnblockTime )</title><link>https://devzone.nordicsemi.com/thread/276378?ContentTypeID=1</link><pubDate>Thu, 22 Oct 2020 08:47:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d02f81b3-38f4-4e2f-bf8d-39c3eb78e260</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Ray&lt;/p&gt;
&lt;p&gt;What SDK version are you using for development? Can you try replacing the #ifdef statement (line 238-254) in port_cmsis_systick.c with the following snippet?&amp;nbsp;I&amp;#39;m not sure if it&amp;#39;s related but it&amp;#39;s been the fix for surprisingly many FreeRTOS projects having issues with the tickless mode.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#if 0  // With FreeRTOS sd_app_evt_wait increases power consumption with FreeRTOS compared to _WFE (NRFFOSDK-11174)
#ifdef SOFTDEVICE_PRESENT
            if (nrf_sdh_is_enabled())
            {
                uint32_t err_code = sd_app_evt_wait();
                APP_ERROR_CHECK(err_code);
            }
            else
#endif
#endif // (NRFFOSDK-11174)
            {
                /* No SD -  we would just block interrupts globally.
                * BASEPRI cannot be used for that because it would prevent WFE from wake up.
                */
                do{
                    __WFE();
                } while (0 == (NVIC-&amp;gt;ISPR[0] | NVIC-&amp;gt;ISPR[1]));
            }
        }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;SImon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assert in FreeRTOS task.c: configASSERT( ( xTickCount + xTicksToJump ) &lt;= xNextTaskUnblockTime )</title><link>https://devzone.nordicsemi.com/thread/276302?ContentTypeID=1</link><pubDate>Wed, 21 Oct 2020 18:09:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:981dbd45-648f-4518-b0dc-78eb638d6d0e</guid><dc:creator>Ray Ma</dc:creator><description>&lt;p&gt;Hey Simon,&lt;/p&gt;
&lt;p&gt;Thanks for replying!&lt;/p&gt;
&lt;p&gt;As I understand the diff here should always be equal or less than the&amp;nbsp;xExpectedIdleTime, because before entering WFE() we set the RTC to generate interrupt at&amp;nbsp;&lt;span&gt;xExpectedIdleTime, if there are other interrupts wakes up the CPU early than the RTC it would have a diff less than&amp;nbsp;xExpectedIdleTime which is fine. However the assert shows it end up with a diff larger than&amp;nbsp;xExpectedIdleTime which makes me suspect either the RTC is a bit off or the RTC interrupt was preempted by other high priority interrupt.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;-Ray&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assert in FreeRTOS task.c: configASSERT( ( xTickCount + xTicksToJump ) &lt;= xNextTaskUnblockTime )</title><link>https://devzone.nordicsemi.com/thread/276181?ContentTypeID=1</link><pubDate>Wed, 21 Oct 2020 12:23:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e551481-bcb8-480b-909b-06c0c6784d4f</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Ray&lt;/p&gt;
&lt;p&gt;The configASSERT is a sanity check. When tickless mode is entered, an expected maximum idle time is provided. The actual idle time may be shorter than the expected maximum&amp;nbsp; (for example an interrupt), but it should never be greater than the expected maximum. If the assert is hit it means that the code is asking to step over the tick past the time at which a task would otherwise have left the blocked state due to a timeout, which means it is being stepped past what was otherwise the expected maximum idle time. The code should be called before the scheduler is resumed, so that shouldn&amp;#39;t happen. Please see &lt;a href="https://www.freertos.org/low-power-tickless-rtos.html"&gt;this link&lt;/a&gt; for more information.&lt;/p&gt;
&lt;p&gt;Please note that this reply is derived from an earlier reply by a FreeRTOS user here on the DevZone. I have not seen an issue like this before. Our FreeRTOS expert is out of office until Monday I&amp;#39;m afraid, but I&amp;#39;ll try to assist you to the best of my abilities until then.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>