<?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>sd_softdevice_disable() causes application to crash/hang if device is paired</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/8941/sd_softdevice_disable-causes-application-to-crash-hang-if-device-is-paired</link><description>If the device is paired (but not bonded) using &amp;quot;Just Works&amp;quot;, sd_softdevice_disable() causes the application to hang/crash (nothing happens until reset by watchdog timer). 
 I use dfu_app_handler.c from sdk 8.1.0, so sd_softdevice_disable() is called</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 03 Sep 2015 10:34:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/8941/sd_softdevice_disable-causes-application-to-crash-hang-if-device-is-paired" /><item><title>RE: sd_softdevice_disable() causes application to crash/hang if device is paired</title><link>https://devzone.nordicsemi.com/thread/32913?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 10:34:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef012d60-564d-4c92-902a-5968b367a022</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Thanks for updating this thread.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_softdevice_disable() causes application to crash/hang if device is paired</title><link>https://devzone.nordicsemi.com/thread/32912?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2015 10:26:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e10ac7c4-5227-4cc9-8647-58e0856264ad</guid><dc:creator>ned_zeppelin</dc:creator><description>&lt;p&gt;Hi, I was finally able to do some proper debugging. I was incorrect in assuming that sd_softdevice_disable() caused the program to halt. The reason my uart printout directly after sd_softdevice_disable() did not appear is that I call sd_mutex_acquire() before every printout, and abort if NRF_SUCCESS is not returned. In this case the softdevice had been disabled so the printout was aborted.&lt;/p&gt;
&lt;p&gt;However, dm_application_context_set(), called from dfu_app_handler.c, returns (NRF_ERROR_INVALID_STATE | DEVICE_MANAGER_ERR_BASE) (due to VERIFY_DEVICE_BOND(p_handle-&amp;gt;connection_id) failing), causing the app_error_handler() to be called.&lt;/p&gt;
&lt;p&gt;The first line of my app_error_handler is APP_ERROR_CHECK(sd_nvic_critical_region_enter(0)), which is probably what caused program execution to &amp;quot;hang&amp;quot; (as the softdevice had been disabled).&lt;/p&gt;
&lt;p&gt;I was able to recreate it using the ble_app_hrs example with dfu from sdk 8.1.0 by adjusting the security settings etc., but the issue was as explained above not sd_softdevice_disable().&lt;/p&gt;
&lt;p&gt;The bug was in my code and not the SDK or Softdevice. The DEVICE_MANAGER_APP_CONTEXT_SIZE define should be set to 0, if pairing (but not bonding) is performed.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_softdevice_disable() causes application to crash/hang if device is paired</title><link>https://devzone.nordicsemi.com/thread/32911?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2015 07:49:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32e75bde-9047-4096-9a3c-ac9f9c756bc3</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;I cannot reproduce this within the examples we have, can i try your project?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_softdevice_disable() causes application to crash/hang if device is paired</title><link>https://devzone.nordicsemi.com/thread/32910?ContentTypeID=1</link><pubDate>Mon, 31 Aug 2015 16:08:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd2f3aaa-2f7c-4a47-ae8c-e5fbc3cd5df7</guid><dc:creator>ned_zeppelin</dc:creator><description>&lt;p&gt;Yes, the following function is called to do this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void reset_prepare(void)
{
    uint32_t err_code;

    if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
    {
        // Disconnect from peer.
        err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
        APP_ERROR_CHECK(err_code);
    }
    else
    {
        // If not connected, the device will be advertising. Hence stop the advertising.
        advertising_stop();
    }

    err_code = ble_conn_params_stop();
    APP_ERROR_CHECK(err_code);

    nrf_delay_ms(500);
}
/** @snippet [DFU BLE Reset prepare] */
#endif // BLE_DFU_APP_SUPPORT
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In context, this is what happens before sd_softdevice_disable() is called (when DFU is triggered):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t err_code;
uint16_t sys_serv_attr_len = sizeof(m_peer_data.sys_serv_attr);

err_code = sd_ble_gatts_sys_attr_get(conn_handle,
                                     m_peer_data.sys_serv_attr,
                                     &amp;amp;sys_serv_attr_len,
                                     BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS);
if (err_code != NRF_SUCCESS)
{
    // Any error at this stage means the system service attributes could not be fetched.
    // This means the service changed indication cannot be sent in DFU mode, but connection
    // is still possible to establish.
}

m_reset_prepare();

err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START);
APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_softdevice_disable() causes application to crash/hang if device is paired</title><link>https://devzone.nordicsemi.com/thread/32909?ContentTypeID=1</link><pubDate>Mon, 31 Aug 2015 10:10:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:df4f775c-ad50-49e3-9129-a4c8bb9b8569</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;have you made sure to stop all BLE activity before calling this? like stopping advertising and scanning or disconnecting any active connection(s)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_softdevice_disable() causes application to crash/hang if device is paired</title><link>https://devzone.nordicsemi.com/thread/32908?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2015 07:42:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad938349-68bc-46c1-98b1-084078db9f4f</guid><dc:creator>ned_zeppelin</dc:creator><description>&lt;p&gt;I am not sure, as I am using UART printouts for debugging at this point. But the program halts after sd_softdevice_disable() is called, meaning program execution never returns from the point where the function is called. There is no reset. I have adjusted my watchdog timeout to 10 seconds for testing, and this eventually resets the system.&lt;/p&gt;
&lt;p&gt;Although I cannot be sure, I suspect the situation is reproducible by using an example from sdk 8.1.0 which supports entering DFU from the application (using my security parameters). I say this because the issue disappears when setting SEC_PARAM_BOND to &amp;#39;1&amp;#39;. It also disappears if pairing is not performed at all.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_softdevice_disable() causes application to crash/hang if device is paired</title><link>https://devzone.nordicsemi.com/thread/32907?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2015 06:49:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f4a0b006-d841-485b-a532-baf38927fbc5</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;what does it mean by system crash?
Is it hardfaulting or does your application does a system reset in some error handler?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_softdevice_disable() causes application to crash/hang if device is paired</title><link>https://devzone.nordicsemi.com/thread/32906?ContentTypeID=1</link><pubDate>Thu, 27 Aug 2015 18:42:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7e596f8-4919-4611-b989-48f511f37c91</guid><dc:creator>ned_zeppelin</dc:creator><description>&lt;p&gt;If I set SEC_PARAM_BOND to &amp;#39;1&amp;#39;, it doesn&amp;#39;t crash. Are my (initial) security parameters invalid, or is this a bug?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>