<?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>Reconnection failure after SAADC</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52664/reconnection-failure-after-saadc</link><description>We are now developing BLE ADC sender, using nRF5_SDK_14.0.0_3bcc1f7, and two nRF528322s (sender and reciever). 
 We send SAADC data via BLE, after that, we disconnect, and tried to reconnect, then &amp;quot;HardFault&amp;quot; happened. 
 
 Situation is as follow, 
 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 11 Oct 2019 12:40:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52664/reconnection-failure-after-saadc" /><item><title>RE: Reconnection failure after SAADC</title><link>https://devzone.nordicsemi.com/thread/214607?ContentTypeID=1</link><pubDate>Fri, 11 Oct 2019 12:40:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac7a20a5-e263-47ad-9d95-49a606113b75</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;In&amp;nbsp;ble_evt_handler(), do you have anything else apart from the switch case shown in the code snippet you posted now? Prior stack frame indicates that the program counter (PC) gets corrupted while processing the BLE event =&amp;gt; SP+1C = PC = 0x22e022c. That is an illegal address that will cause Hardfault. I suggest using the debugger and single-step through the&amp;nbsp;&lt;span&gt;ble_evt_handler() to find out&amp;nbsp;at what code line the PC&amp;nbsp;got&amp;nbsp;changed to this value.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Stack frame for reference (&lt;a href="https://developer.arm.com/docs/dui0553/a/the-cortex-m4-processor/exception-model/exception-entry-and-return"&gt;from ARM doc&lt;/a&gt;):&amp;nbsp;&lt;a href="https://static.docs.arm.com/dui0553/a/graphics/exception_stack_frame.svg"&gt;https://static.docs.arm.com/dui0553/a/graphics/exception_stack_frame.svg&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reconnection failure after SAADC</title><link>https://devzone.nordicsemi.com/thread/214259?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 05:13:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58b5ee5f-fc3b-4180-99df-0b9eed41aef6</guid><dc:creator>yuki_ish</dc:creator><description>&lt;p&gt;I tried HardFault handling library. After that, I found figures(and address) below at Stack pointer.&lt;/p&gt;
&lt;p&gt;SP&lt;/p&gt;
&lt;p&gt;0x2000DCC0: 00000004 Flash&lt;br /&gt;0x2000DCC4: 022E022D Reserved&lt;br /&gt;0x2000DCC8: 0000022E Flash&lt;br /&gt;0x2000DCCC: 00029C24 Flash&lt;/p&gt;
&lt;p&gt;I checked these address data, but I cannot understand what is wrong.&lt;/p&gt;
&lt;p&gt;Do you have any ideas to?specify the reason of Hardfault from these values?&lt;/p&gt;
&lt;p&gt;I attached display hardcopy:&lt;br /&gt;and 0x00000004～0x00029C24 values&lt;/p&gt;
&lt;p&gt;And, about the situation when HardFault happened.&lt;br /&gt;When we tried to make reconnection, BLE event process is successfully done until &amp;quot;BLE_GAP_EVT_CONNECTED&amp;quot;&amp;#39;s break;&lt;br /&gt;Just after that, the HardFault looked happening.&lt;/p&gt;
&lt;p&gt;We think BLE reconnection is the problem itself, do you know the simillar situation when BLE connecting?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
/****************** Interrupt BLE event process ****************/
int ble_connect_state=0;//20190312 y.t
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code;


    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GATTS_EVT_HVN_TX_COMPLETE:// ack from central
            ble_gatts_evt_hvn_tx_complete_flag = 1; 
            break;
			
        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO(&amp;quot;Connected&amp;quot;);
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
            ble_connect_state=1;//20190312
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            NRF_LOG_INFO(&amp;quot;Disconnected&amp;quot;);
            err_code = bsp_indication_set(BSP_INDICATE_IDLE);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            ble_connect_state=0;//20190312
            //sd_nvic_SystemReset();//201900926 for debug 
            break;


　　　...
　　　...
　　　...


        default:
            // No implementation needed.
            break;
    }
}&lt;/pre&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/493x1045/__key/communityserver-discussions-components-files/4/flash_5F00_data.png" /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/1040x1000/__key/communityserver-discussions-components-files/4/HardFault_5F00_stack_5F00_t.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reconnection failure after SAADC</title><link>https://devzone.nordicsemi.com/thread/212427?ContentTypeID=1</link><pubDate>Mon, 30 Sep 2019 00:44:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9b13f07-76b7-4d67-a45c-e45e6e775f2c</guid><dc:creator>yuki_ish</dc:creator><description>&lt;p&gt;Thank you for your reply, Vidar Berg,&lt;/p&gt;
&lt;p&gt;I will try your advice from now on, I will report you afterward.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reconnection failure after SAADC</title><link>https://devzone.nordicsemi.com/thread/212426?ContentTypeID=1</link><pubDate>Mon, 30 Sep 2019 00:42:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5f13037-b1bd-4388-b176-79c84aabeba2</guid><dc:creator>yuki_ish</dc:creator><description>&lt;p&gt;Thank you for your reply. I submitted our code as you mentioned. How is this?&lt;pre class="ui-code" data-mode="c_cpp"&gt;
/****************** Happening HardFault area****************************************/
......\pca10040\s132\arm5_no_packs\RTE\Device\nRF52832_xxAA\arm_startup_nrf52.s

; Dummy Exception Handlers (infinite loops which can be modified)

NMI_Handler     PROC
                EXPORT  NMI_Handler               [WEAK]
                B       .
                ENDP
HardFault_Handler\
                PROC
                EXPORT  HardFault_Handler         [WEAK]
                B       .
                ENDP



/****************** SAADC process ****************/
#define BUFF_SIZE 100
uint16_t send_data_buf[ BUFF_SIZE ][ SAMPLES_IN_BUFFER+2 ] ;//ling buffer
int buf_w_point=0;
int send_count = 0;//100sample a/d data counter  
int ble_send_start = 0;
int count1 = 0;

static void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;

        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

       if (ad_tx_start_f == 1)
       {
	   int i;
           for (i = 0; i &amp;lt; SAMPLES_IN_BUFFER; i++)
           {
	       send_data_buf[ buf_w_point ][ i ] = p_event-&amp;gt;data.done.p_buffer[i];
           }			

           send_count++;
				
	   send_data_buf[buf_w_point][SAMPLES_IN_BUFFER] = (uint16_t)m_adc_evt_counter;
	   send_data_buf[buf_w_point][SAMPLES_IN_BUFFER+1] = (uint16_t)send_count;
           if(buf_w_point&amp;gt; (BUFF_SIZE-1))
           {  
              buf_w_point=0; 
           } 
           else
           { 
              buf_w_point++; 
           } 
        }  
        else
        {
           send_count = 0; 
           buf_w_point=0; 
        }
 
        m_adc_evt_counter++;
        now_buffer_pool_p = (uint16_t *)p_event-&amp;gt;data.done.p_buffer;	

    }
}


/****************** Reading buffer process ****************/
        if(send_count &amp;gt; 10) 
        { 
            //send_count--; 
            m=0;
							
            param[2].uspoint = &amp;amp;adc_data[0];

            for(i=0;i&amp;lt;100;i++) 
            { 
                total=0; 
                for(n=0;n&amp;lt;16;n++) 
                {
                   total += send_data_buf[ buf_r_point ][ m+n ]; 
                }
                //ave = total/16; 
                ave_too = total &amp;gt;&amp;gt; 4;
                param[2].uspoint[i] = (uint16_t) ave_too; 
                m=m+16;
 
                if(m&amp;gt;=160) 
                { 
                      send_count--; 
                      m=0;
                      if(buf_r_point&amp;gt; (BUFF_SIZE-1)) 
                      {
                         buf_r_point=0; 
                      }
                      else 
                      {
                         buf_r_point=buf_r_point+1; 
                      }
								}
							
							}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reconnection failure after SAADC</title><link>https://devzone.nordicsemi.com/thread/212295?ContentTypeID=1</link><pubDate>Fri, 27 Sep 2019 13:11:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9954645d-2816-4c7b-b3d2-77e3d0175808</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Try to include the&amp;nbsp;&lt;a title="HardFault handling library" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/lib_hardfault.html?cp=5_1_3_20"&gt;HardFault handling library&lt;/a&gt;&amp;nbsp;into your project.&amp;nbsp;This library may help you to determine where and why the exception occurred more easily. To use the library, you need to include source files listed below and&amp;nbsp;also set HARDFAULT_HANDLER_ENABLED to &amp;#39;1&amp;#39; in sdk_config and include &amp;#39;DEBUG&amp;#39; in the list of preprocessor symbols.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;-&amp;nbsp;hardfault_implementation.c&lt;/p&gt;
&lt;p&gt;- Select one of the three handler implementations based on the compiler you use: hardfault_handler_keil.c /&amp;nbsp;hardfault_handler_iar.c /&amp;nbsp;hardfault_handler_gcc.c&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reconnection failure after SAADC</title><link>https://devzone.nordicsemi.com/thread/212220?ContentTypeID=1</link><pubDate>Fri, 27 Sep 2019 09:11:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e0383729-ab16-4a25-a200-64a2174a543c</guid><dc:creator>awneil</dc:creator><description>[quote userid="76013" url="~/f/nordic-q-a/52664/reconnection-failure-after-saadc"]then &amp;quot;HardFault&amp;quot; happened[/quote]
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/52662/getting-hardfault-handler-after-porting-latest-nrf_sdk_15-3-0-to-nrf52840/212216#212216"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/52662/getting-hardfault-handler-after-porting-latest-nrf_sdk_15-3-0-to-nrf52840/212216#212216&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/0841._5F00_Insert-Code-_2D00_-Nordic-2.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>