<?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>Background DFU causes problem on FreeRTOS tasks</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59468/background-dfu-causes-problem-on-freertos-tasks</link><description>Env setup: 
 nrf52840 on PCA10056, SDK 16.0.0, S140, FreeRTOS, secure bootloader 
 
 Description: 
 I&amp;#39;m trying BLE background DFU in the application. 
 Had reference iot/background dfu code. But the final impl is porting dfu/ and ble_dfu/ under sdk/components</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 31 Mar 2020 11:41:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59468/background-dfu-causes-problem-on-freertos-tasks" /><item><title>RE: Background DFU causes problem on FreeRTOS tasks</title><link>https://devzone.nordicsemi.com/thread/242673?ContentTypeID=1</link><pubDate>Tue, 31 Mar 2020 11:41:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0d202fed-cece-494e-a36c-29b60fd3a9b4</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Monza,&lt;/p&gt;
&lt;p&gt;app scheduler is just a context changing API. app_sched_put will put the context into the queue and app_sched_execute will execute the context.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The most important thing is the context in which you are calling app_sched_execute. In your case, you are calling it inside the dfu_thread. This should work fine in terms of API usage. The app_scheduler is not probably the best API in terms of stack usage, you could probably reduce the queue buffers of the app_scheduler if you think that fits your design.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Second, we have not tested the usage of FreeRTOS and app_scheduler. app_scheduler is designed for someone who does not have the fancy features of the FreeRTOS. Inside FreeRTOS, normally you communicate between tasks using inter task communications like message queues or notifications. These inter-task communications are very stack friendly and use smaller stack for inter-task communication only as compared to app_scheduler.&lt;/p&gt;
&lt;p&gt;Lastly, what you are doing is something we have not tested, that said, it should work. the stack overflow problem is something understandable, please increase the stack size more, to get around the problem. You could phase out app_scheduler and try to port it to use FreeRTOS message queues instead.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Background DFU causes problem on FreeRTOS tasks</title><link>https://devzone.nordicsemi.com/thread/242266?ContentTypeID=1</link><pubDate>Mon, 30 Mar 2020 01:31:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9645ea3-bea4-4c48-a810-59bdce8ee768</guid><dc:creator>monza.wu</dc:creator><description>&lt;p&gt;It&amp;#39;s is FreeRTOS stack overflow.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m also worry about the FreeRTOS compatibility with app_scheduler, fstorage queues, nrf_balloc, and softdevice task.&lt;/p&gt;
&lt;p&gt;So I did more to debug&lt;/p&gt;
&lt;p&gt;1. disable fstorage api, and its internal queues, always return success immediately&lt;/p&gt;
&lt;p&gt;2. modify the dfu, allocate 4k buffer in bss instead of nrf_balloc on every 244 bytes. and only call fstorage write every 4k data&lt;/p&gt;
&lt;p&gt;I still see task issues happen with both changes.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Then I did more test,&lt;/p&gt;
&lt;p&gt;3. disable or re-arrange the FreeRTOS task create&lt;/p&gt;
&lt;p&gt;After this, sometimes device crash during dfu. This leads to the obvious reason that stack is overflow.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;With&amp;nbsp;uxTaskGetStackHighWaterMark and&amp;nbsp;configCHECK_FOR_STACK_OVERFLOW, I can confirm the issue, and fix it by increase the stack size.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;One thing needs to mention,&lt;/p&gt;
&lt;p&gt;The task to run&amp;nbsp;&lt;span&gt;app_sched_execute took over 310 (x 4 bytes) units from task stack, even&amp;nbsp; larger than the softdevice task (256).&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Background DFU causes problem on FreeRTOS tasks</title><link>https://devzone.nordicsemi.com/thread/241779?ContentTypeID=1</link><pubDate>Thu, 26 Mar 2020 10:29:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ad7d145-423c-4fa7-80ca-a7dbd194b0da</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Things executing inside the app_scheduler could be doing something not compatible with FreeRTOS. FreeRTOS expects everything to be run in tasks and the app_scheduler is running outside the FreeRTOS control.&lt;/p&gt;
&lt;p&gt;I think we will need more information if you want help to debug this and probably it will be best if you open a private case and share your whole project with us so one of our FreeRTOS experts in tech support can take a look at it.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>