<?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>Refer to ble_app_hrs_freertos example.Error calling xQueueReceive for the second time.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/88410/refer-to-ble_app_hrs_freertos-example-error-calling-xqueuereceive-for-the-second-time</link><description>Hi. 
 I use nrf52840. 
 sdk nRF5_SDK_17.0.2_d674dde\examples\ble_peripheral\ble_app_hrs_freertos. 
 Error calling xQueueReceive for the second time. 
 Here is the code and log： 
 if (pdPASS != xTaskCreate(lte_thread, &amp;quot;LTE&amp;quot;, 768, NULL, 3, &amp;amp;m_uart_thread</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 01 Jun 2022 05:47:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/88410/refer-to-ble_app_hrs_freertos-example-error-calling-xqueuereceive-for-the-second-time" /><item><title>RE: Refer to ble_app_hrs_freertos example.Error calling xQueueReceive for the second time.</title><link>https://devzone.nordicsemi.com/thread/370323?ContentTypeID=1</link><pubDate>Wed, 01 Jun 2022 05:47:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14892a55-afb8-4708-8e2e-58d0e7d65d78</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;In your map file you can see&amp;nbsp;the below two lines (Line 38163)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; .text.record_find
                0x00000000000293f0       0xe4 Output/Release/Obj/btk_bitlink_s140/fds.o
 .text.records_stat
                0x00000000000294d4       0xe4 Output/Release/Obj/btk_bitlink_s140/fds.o&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can see that&amp;nbsp;&lt;span&gt;0x20009444 lies in the function record_find. There are two different directions that you can try to debug this issue.&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span&gt;Assuming that this hardfault is infact caused by something inside record_find inside fds.c file. One place where I can see is the below line&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;           fds_header_t const * p_header = (fds_header_t*)p_token-&amp;gt;p_addr;

            // A valid record was found, check its header for a match.
            if ((p_file_id != NULL) &amp;amp;&amp;amp;
                (p_header-&amp;gt;file_id != *p_file_id))
            {
                continue;
            }

            if ((p_record_key != NULL) &amp;amp;&amp;amp;
                (p_header-&amp;gt;record_key != *p_record_key))
            {
                continue;
            }&lt;/pre&gt;&lt;br /&gt;It looks like p_header is being assigned from p_token-&amp;gt;p_addr but I do not see any NULL pointer checkes on p_header. There is a possibility of null pointer dereference here. You can add the check like below&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;           fds_header_t const * p_header = (fds_header_t*)p_token-&amp;gt;p_addr;

            if(p_header == NULL)
            {
                continue;
            }
     
            // A valid record was found, check its header for a match.
            if ((p_file_id != NULL) &amp;amp;&amp;amp;
                (p_header-&amp;gt;file_id != *p_file_id))
            {
                continue;
            }

            if ((p_record_key != NULL) &amp;amp;&amp;amp;
                (p_header-&amp;gt;record_key != *p_record_key))
            {
                continue;
            }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;[quote user="john.liu"]&amp;lt;error&amp;gt; hardfault: Cause: The processor has attempted an illegal load of EXC_RETURN to the PC, as a result of an invalid context, or an invalid EXC_RETURN value.[/quote]
&lt;p&gt;If we can trust the bits set in &lt;a href="https://developer.arm.com/documentation/dui0552/a/cortex-m3-peripherals/system-control-block/configurable-fault-status-register"&gt;UsageFault Status Register&lt;/a&gt; in the CortexM3 processor, then it is telling us that the PC load value from the exc_return is invalid. This happens when a wrong/corrupted stack frame is popped back into the registers rendering the PC value with garbage or corrupted value. This happens mostly when the stack size of the current or the tasks using neighboring stack pool overflow its stack usage. You can do two things for debugging this..&lt;/p&gt;
&lt;span&gt;&lt;/span&gt;
&lt;ol&gt;
&lt;li&gt;Increase the task stack size significantly for the task that is running fds.c context. I am guessing that this one of your application tasks, since softdevice_task (components\softdevice\common\nrf_sdh_freertos.c)&amp;nbsp; should not use flash usage, unless you are making flash operations from the softdevice events callback&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.freertos.org/Stacks-and-stack-overflow-checking.html"&gt;Enable stack overflow checking&lt;/a&gt; in FreeRTOS and see if you have any hits. This is not a failsafe way of checking stack overflows but there is a great chance that a stack overflow is caught in these checks if there are any.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Refer to ble_app_hrs_freertos example.Error calling xQueueReceive for the second time.</title><link>https://devzone.nordicsemi.com/thread/370314?ContentTypeID=1</link><pubDate>Wed, 01 Jun 2022 02:23:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d14b1e4-ee0d-4230-824e-a4ba51073bf1</guid><dc:creator>john.liu</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I can confirm that it is not&amp;nbsp;&lt;span&gt;limited task.(I tried modifying the task usStackDepth)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The context of 0x20009444 was not found in the map.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;info&amp;gt; app: beacon started.&lt;br /&gt;&amp;lt;info&amp;gt; app: BitLink FreeRTOS example started.&lt;br /&gt;&amp;lt;info&amp;gt; app: lte thread.&lt;br /&gt;&amp;lt;info&amp;gt; app: ----RES OK [OK&lt;br /&gt;]&lt;br /&gt;&amp;lt;info&amp;gt; app: AT 1&lt;br /&gt;&amp;lt;info&amp;gt; app: ----RES data:&lt;br /&gt;&amp;lt;info&amp;gt; app: 38 36 34 34 37 35 30 34|86447504&lt;br /&gt;&amp;lt;info&amp;gt; app: 39 39 39 39 39 35 35 |9999955 &lt;br /&gt;&amp;lt;info&amp;gt; app: IMEI 1&lt;br /&gt;&amp;lt;info&amp;gt; app: ----RES data:&lt;br /&gt;&amp;lt;info&amp;gt; app: 2B 43 43 49 44 3A 20 38|+CCID: 8&lt;br /&gt;&amp;lt;info&amp;gt; app: 39 38 36 30 36 32 30 32|98606202&lt;br /&gt;&amp;lt;info&amp;gt; app: 32 30 30 32 30 35 39 34|20020594&lt;br /&gt;&amp;lt;info&amp;gt; app: 39 38 37 |987 &lt;br /&gt;&amp;lt;info&amp;gt; app: ICCID 1&lt;br /&gt;&amp;lt;info&amp;gt; app: lte thread.&lt;br /&gt;&amp;lt;error&amp;gt; hardfault: HARD FAULT at 0x20009444&lt;br /&gt;&amp;lt;error&amp;gt; hardfault: R0: 0x2000A818 R1: 0x20008BEC R2: 0x2000A7EC R3: 0x00000000&lt;br /&gt;&amp;lt;error&amp;gt; hardfault: R12: 0xA5A5A5A5 LR: 0x0002EE8F PSR: 0x2000A82C&lt;br /&gt;&amp;lt;error&amp;gt; hardfault: Cause: The processor has attempted an illegal load of EXC_RETURN to the PC, as a result of an invalid context, or an invalid EXC_RETURN value.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/btk_5F00_bitlink_5F00_s140.map"&gt;devzone.nordicsemi.com/.../btk_5F00_bitlink_5F00_s140.map&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Refer to ble_app_hrs_freertos example.Error calling xQueueReceive for the second time.</title><link>https://devzone.nordicsemi.com/thread/370182?ContentTypeID=1</link><pubDate>Tue, 31 May 2022 11:28:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24b69d72-688f-40ec-bc57-ab1bb38d29ce</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;You have the hardfault instruction given here -&amp;gt;&amp;nbsp;&lt;span&gt;0x20009834.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You can try to look at the map file and get the context in which the hardfault is happening.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Also make sure that there are no stack overflows due to the limited task stack sizes you create.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>