<?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>FreeRTOS and SoftDevice events: hard fault</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/13829/freertos-and-softdevice-events-hard-fault</link><description>We have used FreeRTOS a lot, also on nRF51 and nRF52. Now I&amp;#39;m trying to migrate our nRF52 code form SDK11-alpha and SoftDevice 2.0.0-7-alpha (?) to the most recent versions. Most of things are working but one problem remains. We use s132_nrf52_2.0.1_softdevice</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 20 May 2016 06:59:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/13829/freertos-and-softdevice-events-hard-fault" /><item><title>RE: FreeRTOS and SoftDevice events: hard fault</title><link>https://devzone.nordicsemi.com/thread/52844?ContentTypeID=1</link><pubDate>Fri, 20 May 2016 06:59:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:677670aa-246d-4169-8932-94cfa3dd8248</guid><dc:creator>Pertti Kasanen</dc:creator><description>&lt;p&gt;Now I&amp;#39;m still getting errors like this &lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/skitch.png" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;If the reason is similar, causes for this should be possible to find. Even though the stack seems to be garbled.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS and SoftDevice events: hard fault</title><link>https://devzone.nordicsemi.com/thread/52843?ContentTypeID=1</link><pubDate>Fri, 20 May 2016 06:59:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5004714-2d07-4b32-a6ee-6292d12bab6e</guid><dc:creator>Pertti Kasanen</dc:creator><description>&lt;p&gt;Edit: The problem was configLIBRARY_LOWEST_INTERRUPT_PRIORITY. Got it working earlier, but took this long :( to do all the testing and removing my workarounds etc. I did &amp;quot;check&amp;quot; that priority setting already earlier, but due to mixed up #ifdef:s the line with 0x0f was not in use...&lt;/p&gt;
&lt;p&gt;That fixed the all the issues with portYIELD() and ble_new_event_handler()&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;I may have found part of the problem. Every couple of minutes there used to be hard faults with stack trace like this.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/fault_5F00_hardfault_5F00_implementation_5F00_c_5F005F00_seed_5F005F002D005F00_Code_5F005F00_Blocks_5F00_13_5F00_12.png" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;It seems to me that there is a flaw on the FreeRTOS port and it&amp;#39;s integration to SoftDevice event handling. It (probably only) appears when ble_new_event_handler causes a FreeRTOS task to yield AND there are multiple events in the soft device queue.&lt;/p&gt;
&lt;p&gt;The ble_new_event_handler (as copied from the SDK examples) enables soft device interrupts when yielding with portYIELD(). But it should not - before all the queued events have been processed in intern_softdevice_events_execute() in softdevice_handler.c&lt;/p&gt;
&lt;p&gt;Wrote a workaround and this error with SWI2_EGU2_IRQHandler has not appeared since. I think there is no way doing this without modifying the intern_softdevice_events_execute() code. Need to do some more experimenting, but I&amp;#39;ll open a support ticket on this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS and SoftDevice events: hard fault</title><link>https://devzone.nordicsemi.com/thread/52842?ContentTypeID=1</link><pubDate>Mon, 16 May 2016 17:19:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:245e2681-cc78-4d84-9fc1-aa4f438b05ba</guid><dc:creator>Pertti Kasanen</dc:creator><description>&lt;p&gt;Edited the link to &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s132.sds%2Fdita%2Fsoftdevices%2Fs130%2Fprocessor_avail_interrupt_latency%2Fexception_mgmt_sd.html&amp;amp;cp=2_3_0_0_15_1"&gt;infocenter.nordicsemi.com/index.jsp&lt;/a&gt; , that was the page ment.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS and SoftDevice events: hard fault</title><link>https://devzone.nordicsemi.com/thread/52841?ContentTypeID=1</link><pubDate>Fri, 13 May 2016 10:26:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03ef9b56-177a-4ddf-8996-a5e12401cd1d</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;They&amp;#39;re just my musings at this point- I&amp;#39;m still thinking it through and need to spend some time doing a FreeRTOS deep dive until I really feel comfortable with it.&lt;/p&gt;
&lt;p&gt;I just looked at a few more of the examples and actually it seems the kernel priority is 0x0f, the lowest level (and this port doesn&amp;#39;t seem to follow the documented convention that it should be the fully-shifted, lowest bits set to 1 version, ie 0xff). The highest available interrupt which can use FreeRTOS ISR calls is set to 1, which is lower than the softdevice critical priority, which makes sense. With that the case, you shouldn&amp;#39;t have to protect SVC calls as the kernel can never interrupt one and task switch you. That would be the case with the kernel interrupt level anywhere between 0x4 and 0xf.&lt;/p&gt;
&lt;p&gt;interrupt priority 3 should be fine, you can even call RTOS functions from it. So your actual problem must lie elsewhere.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS and SoftDevice events: hard fault</title><link>https://devzone.nordicsemi.com/thread/52840?ContentTypeID=1</link><pubDate>Fri, 13 May 2016 08:50:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:caa23fc9-637b-4183-bcac-9891fb951649</guid><dc:creator>Pertti Kasanen</dc:creator><description>&lt;p&gt;Thanks RK for good speculation.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m wondering for example: should I put the soft device event handler task under/above/same FreeRTOS level as the TmrS task of the FreeRTOS port.&lt;/p&gt;
&lt;p&gt;Reading this
&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s132.sds%2Fdita%2Fsoftdevices%2Fs130%2Fprocessor_avail_interrupt_latency%2Fexception_mgmt_sd.html&amp;amp;cp=2_3_0_0_15_1"&gt;infocenter.nordicsemi.com/index.jsp&lt;/a&gt;
looks like we should try to use only interrupt levels 6 and 7 with RTOS application level interrupts - or otherwise be very specific what to start from those higher level interrupts.&lt;/p&gt;
&lt;p&gt;I recall having somewhere interrupt level 3 in use - will check that next...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS and SoftDevice events: hard fault</title><link>https://devzone.nordicsemi.com/thread/52839?ContentTypeID=1</link><pubDate>Fri, 13 May 2016 08:21:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64031fbf-fc10-489d-b913-a2e6abfaf3ae</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;+1 for qu. 2 which has been bothering me. If the RTOS task runs at lower priority than the SVC, everything should be fine, but if it runs at a higher priority sooner or later, probably sooner, it&amp;#39;s going to interrupt something in a SVC call, stack the current state, inside the SD then task switch to something else. If that then also does an SVC call I can&amp;#39;t think it would end well.&lt;/p&gt;
&lt;p&gt;I wouldn&amp;#39;t expect the SD to have any internal mutexes as it doesn&amp;#39;t really need them , anything which can interrupt an SVC call can&amp;#39;t call another one (can&amp;#39;t SVC from a higher priority interrupt), anything of lower priority won&amp;#39;t run, so there&amp;#39;s an automatic protection.&lt;/p&gt;
&lt;p&gt;With an RTOS which can interrupt an SVC call and then adjust the stack to return to somewhere totally different, you lose that. I believe the RTOS port however has the scheduler running at higher priority than SVC, don&amp;#39;t see how that works.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>