<?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: Context switch hardfault</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/49587/freertos-context-switch-hardfault</link><description>Hello, 
 When debugging one of the projects, I encountered the situation of a frequent reset of the device during connection. A quick scan under the debugger helped show the cause: a hard failure. 
 More detailed debugging helped identify the following</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 08 Oct 2019 13:45:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/49587/freertos-context-switch-hardfault" /><item><title>RE: FreeRTOS: Context switch hardfault</title><link>https://devzone.nordicsemi.com/thread/213948?ContentTypeID=1</link><pubDate>Tue, 08 Oct 2019 13:45:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8fb197c6-531b-4750-8280-6b9a5bb53755</guid><dc:creator>CheMax</dc:creator><description>&lt;p&gt;I apologize for the long absence and silence in this topic, I was on vacation in connection with the birth of my daughter.&lt;/p&gt;
&lt;p&gt;Yes, the problem was similar in the incorrect organization of access to a shared resource (pointer to data). Plus, you must correctly prioritize threads (and interrupts).&lt;/p&gt;
&lt;p&gt;I believe that the answer was received during the discussion. the correct answers in my opinion I marked&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS: Context switch hardfault</title><link>https://devzone.nordicsemi.com/thread/201391?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2019 05:57:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0d928115-60bc-44f8-abda-ebc6bb398fca</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="CheMax"]At the moment, after changing priorities, the problem situation is not repeated anymore. But the question is: what exactly the reason remains unanswered[/quote]
&lt;p&gt;&amp;nbsp;Any task synchronizing mechanism could cause a temporary priority inversion and this is expected. But this should not cause a stack corruption as this is allowed and like I said very much expected.&amp;nbsp;It looks like the sanity of the data pointers in your lower priority thread is not checked before being dereferenced. Seems like you have some design flaw in how the two tasks communicate. I would recommend you to atleast check the sanity of the data pointers being used if they are accessed by more than one task.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS: Context switch hardfault</title><link>https://devzone.nordicsemi.com/thread/200869?ContentTypeID=1</link><pubDate>Mon, 29 Jul 2019 05:16:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1f609878-b080-45de-85ab-5fba9a4dc5af</guid><dc:creator>CheMax</dc:creator><description>&lt;p&gt;Good Moning,&lt;br /&gt;No, I use queue module from NRF SDK (nrf queue.c \ nrf queue.h).&lt;/p&gt;
&lt;p&gt;It seemed to me that it is more flexible (and yes, I like its API) and is better suited for my tasks (data damping before and after processing).&lt;/p&gt;
&lt;p&gt;At the moment, after changing priorities, the problem situation is not repeated anymore. But the question is: what exactly the reason remains unanswered (&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS: Context switch hardfault</title><link>https://devzone.nordicsemi.com/thread/200707?ContentTypeID=1</link><pubDate>Fri, 26 Jul 2019 09:47:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25051546-02d4-40c0-87d0-a2885a2e6c3d</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi, I don&amp;#39;t think priority inversion should lead to corruption and writes to an arbitrary memory area, but I&amp;#39;m also not sure what&amp;#39;s causing the memory corruption. Did you consider to use the Freertos module for Queing?&amp;nbsp;&lt;a href="https://www.freertos.org/a00018.html"&gt;https://www.freertos.org/a00018.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS: Context switch hardfault</title><link>https://devzone.nordicsemi.com/thread/198121?ContentTypeID=1</link><pubDate>Fri, 12 Jul 2019 10:58:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6a84a53-51b5-4da1-9606-a403deedb525</guid><dc:creator>CheMax</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I saw this post earlier when I did a preliminary search for possible problems before adding a queue module to the code. And even copied the proposed corrections just in case.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;My question is related to this section of the code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Macro for entering a critical region.
 *
 * @note Due to implementation details, there must exist one and only one call to
 *       CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
 *       in the same scope.
 */
#ifdef SOFTDEVICE_PRESENT
#define CRITICAL_REGION_ENTER()                                                             \
    {                                                                                       \
        uint8_t __CR_NESTED = 0;                                                            \
        app_util_critical_region_enter(&amp;amp;__CR_NESTED);
#else
#define CRITICAL_REGION_ENTER() app_util_critical_region_enter(NULL)
#endif

/**@brief Macro for leaving a critical region.
 *
 * @note Due to implementation details, there must exist one and only one call to
 *       CRITICAL_REGION_EXIT() for each call to CRITICAL_REGION_ENTER(), and they must be located
 *       in the same scope.
 */
#ifdef SOFTDEVICE_PRESENT
#define CRITICAL_REGION_EXIT()                                                              \
        app_util_critical_region_exit(__CR_NESTED);                                         \
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Interrupts will be temporarily disabled and then allowed. If you use these functions in tasks with low priority, can a situation of knowledge be known as priority inversion (a low-priority thread blocks a high-priority)?&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;As far as I understood, I had the following: the simultaneous occurrence of high priority interruption and the process context switching process. At the same time, the contents of the registers (R0 - R12) seemed to overlap and instead of being saved to the stack, they were saved into an arbitrary memory area.&lt;br /&gt;This can be taken as an explanation of the situation when the contents of the data buffers had the form of code located in the stack area.&lt;/p&gt;
&lt;p&gt;I could investigate this issue in detail if there is a profiler, Segger SysView for example. But I had difficulties with its integration into the project. &lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/instrumenting-with-segger-systemview"&gt;An example&lt;/a&gt; that you have created for the stack &lt;span style="text-decoration:underline;"&gt;&lt;strong&gt;s132 and nrf52832 device&lt;/strong&gt;&lt;/span&gt;. Is it possible (or the availability of a ready solution for your team) to adapt that code under the stack &lt;span style="text-decoration:underline;"&gt;&lt;strong&gt;s140 (nrf52840)&lt;/strong&gt;&lt;/span&gt;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS: Context switch hardfault</title><link>https://devzone.nordicsemi.com/thread/197867?ContentTypeID=1</link><pubDate>Thu, 11 Jul 2019 13:28:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b20cc4b0-c234-4b43-a2e4-f9a9726412fb</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi, good to hear that you have had progress.&amp;nbsp;The Softdevice reserves some of the interrupt priorities&amp;nbsp;(if you&amp;#39;re using Bluetooth), but not sure&amp;nbsp;how&amp;nbsp;wrong interrupt priority would cause the data corruption. Maybe it could be related to the issue Jakub mentions here:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/46916/nrf_queue-will-not-fit-in-region-unplaced_sections-on-nrf52810/185496#185496"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/46916/nrf_queue-will-not-fit-in-region-unplaced_sections-on-nrf52810/185496#185496&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FreeRTOS: Context switch hardfault</title><link>https://devzone.nordicsemi.com/thread/197712?ContentTypeID=1</link><pubDate>Thu, 11 Jul 2019 07:09:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6aa597a5-8e28-4152-8ad3-374302803c02</guid><dc:creator>CheMax</dc:creator><description>&lt;p&gt;So, one more working day is progress. It looks like I did not take into account the real priority of interrupts and the requirements of the RTOS.&lt;/p&gt;
&lt;p&gt;In the file&amp;nbsp;&lt;strong&gt;FreeRTOSConfig.h&lt;/strong&gt; describes the minimum priority level and the maximum for interrupts that use the RTOS api functions (with _fromISR).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;I also did not notice that Nordic &lt;span style="text-decoration:underline;"&gt;recommends &lt;/span&gt;(or &lt;span style="text-decoration:underline;"&gt;&lt;strong&gt;requires&lt;/strong&gt;&lt;/span&gt;?) the following levels of priorities (file &lt;strong&gt;app_util_platform.h)&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define _PRIO_SD_HIGH       0
#define _PRIO_SD_MID        1
#define _PRIO_APP_HIGH      2
#define _PRIO_APP_MID       3
#define _PRIO_SD_LOW        4
#define _PRIO_SD_LOWEST     5
#define _PRIO_APP_LOW       6
#define _PRIO_APP_LOWEST    7
#define _PRIO_THREAD        15&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Indeed, the use of task priorities and priorities of interrupts MK is very complicated.&lt;/p&gt;
&lt;p&gt;But I would like to get an answer to my question related to the use of the queue module in conjunction with the RTOS. Are there any restrictions or recommendations?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>