<?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>BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52552/ble-central-freeze-on-disconnect-with-freertos</link><description>Hello support team, 
 I try to get the NRF52840 DK to work as a central with FreeRTOS. Connecting and getting notifications works well, but the device freezes on a disconnect event. 
 After trying to debug it with gdb, it seems that it is indefinetly</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 23 Aug 2021 07:35:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52552/ble-central-freeze-on-disconnect-with-freertos" /><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/326109?ContentTypeID=1</link><pubDate>Mon, 23 Aug 2021 07:35:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12907c2b-14a2-4262-ac86-4cb1f85bd6e4</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am sorry but I am not able to backtrace the changes I thought were approved. So this issue still exists in app_timer_freertoc.c-&amp;gt;app_timer_stop.c where the timer_id is dereferenced without any checks. Please make sure that you do not send a NULL as a timer_id&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/281220?ContentTypeID=1</link><pubDate>Sun, 22 Nov 2020 21:42:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0bbae021-d4b4-463b-9662-b409c3b46c1e</guid><dc:creator>Davide Di Gesualdo</dc:creator><description>&lt;p&gt;Hi everyone! I have the same&amp;nbsp;issue and it is solved by applying the solution below.&lt;br /&gt;FYI, I am using SDK 17.0.2 and the code in&amp;nbsp;&lt;span&gt;ble_conn_params.c of the on_disconnect function is the same as the one posted by KevinG.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/244960?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 11:35:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0384001e-aeba-4cac-a331-8ce5d4a921f4</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;the changes are pushed in and accepted after SDK16 was released, they should come out in SDK17&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/244938?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 10:40:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7640871-073e-46a4-95a5-d26250519adc</guid><dc:creator>He!k0</dc:creator><description>&lt;p&gt;Just had the same issue on SDK16 (0098a08e2) and could solve it buy applying the suggested changing of KevinG. Looks like the pull request hasn&amp;#39;t been accepted yet.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/225887?ContentTypeID=1</link><pubDate>Tue, 17 Dec 2019 13:07:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92c43454-aa67-41d2-afcb-d6d6de7cd793</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;KevinG, your way seems cleaner than the rest. I will do&amp;nbsp;a pull request to apply this change for the next release.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/225766?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 22:55:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe8b3363-61ae-4a63-9883-ef7a6114cde3</guid><dc:creator>KevinG</dc:creator><description>&lt;p&gt;I had a similar issue that I believe is a bug as well.&amp;nbsp; on_disconnect is called inside ble_conn_params.c when BLE disconnects and it looks to stop a timer, but if the timer is null, an assertion happens.&amp;nbsp; The call to stop the timer should not be made if it&amp;#39;s null so I updated the code to check for that:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Old code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void on_disconnect(ble_evt_t const * p_ble_evt)
{
    ret_code_t                   err_code;
    uint16_t                     conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
    ble_conn_params_instance_t * p_instance  = instance_get(conn_handle);

    if (p_instance != NULL)
    {
    // Stop timer if running
        err_code = app_timer_stop(p_instance-&amp;gt;timer_id);
        if (err_code != NRF_SUCCESS)
        {
            send_error_evt(err_code);
        }

        instance_free(p_instance);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;New Code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void on_disconnect(ble_evt_t const * p_ble_evt)
{
    ret_code_t                   err_code;
    uint16_t                     conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
    ble_conn_params_instance_t * p_instance  = instance_get(conn_handle);

    if (p_instance != NULL)
    {
    // Stop timer if running
        if(p_instance-&amp;gt;timer_id != NULL) 
        {
            err_code = app_timer_stop(p_instance-&amp;gt;timer_id);
            if (err_code != NRF_SUCCESS)
            {
                send_error_evt(err_code);
            }
        }
        instance_free(p_instance);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I used this method over yours because I didn&amp;#39;t want on_disconnect throwing an error when one didn&amp;#39;t actually exist.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/218672?ContentTypeID=1</link><pubDate>Tue, 05 Nov 2019 18:01:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6af2ae45-db3c-4bbd-aeb4-01d5d0399735</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;nice work&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/djvenczel"&gt;DjVenczel&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/218012?ContentTypeID=1</link><pubDate>Fri, 01 Nov 2019 16:35:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42777f3d-8ebb-446a-8075-276b83745dec</guid><dc:creator>Viktor Venczel</dc:creator><description>&lt;p&gt;Hello everyone!&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve run into the same issue a few days ago, then luckily found this thread, I had spent lots of time to find this bug. Based on Susheel Nuguru&amp;#39;s post I made a fix in &amp;quot;app_timer_freertos.c&amp;quot;&lt;/p&gt;
&lt;p&gt;The timer not just never started, it is even never created, therefore a null pointer is given to the &amp;quot;app_timer_stop&amp;quot; function. If you comment out those lines, the same SDK would make problems when it is used in an application with BLE device. Hence a better fix:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint32_t app_timer_stop(app_timer_id_t timer_id)
{
    //invalid timer
    if (timer_id == NULL)
    {
        return NRF_ERROR_INVALID_STATE;
    }

    app_timer_info_t * pinfo = (app_timer_info_t*)(timer_id);
    ...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Same applies to &amp;quot;app_timer_start&amp;quot; just to avoid future problems.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/212997?ContentTypeID=1</link><pubDate>Wed, 02 Oct 2019 12:32:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e8cceec-730b-43e3-96bf-6430a11e5094</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;DanielK,&lt;/p&gt;
&lt;p&gt;I found the bug you are trying to trace.&lt;/p&gt;
&lt;p&gt;It seems that the ble_conn_params.c could have a bug that it might not be suitable for central. I am not 100% sure on that part but the problem seems to be a hardfault when trying to remove a timer from kernel queue where the timer does not exist.&lt;/p&gt;
&lt;p&gt;The app_timer is never started in ble_conn_params.c since the negotiations were never triggered.&lt;/p&gt;
&lt;p&gt;So in ble_conn_params.c-&amp;gt;on_disconnect()-&amp;gt; comment out the app_timer_stop function as below&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;        // Stop timer if running
        //err_code = app_timer_stop(p_instance-&amp;gt;timer_id);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I will discuss this internally how to handle it. But for you this workaround should fix your problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/212837?ContentTypeID=1</link><pubDate>Tue, 01 Oct 2019 13:36:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ffe38f5-09c4-4f1a-b92b-3310a2f881eb</guid><dc:creator>DanielK</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;in the minimal example I have created a blinking LED task which stops blinking after a disconnect. I made it to make an easy reproducible example, I hope you can try it out and reproduce the behaviour. It connects to any peripheral you want which has the same device name as specified in DEVICE_NAME_PERIPHERAL.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not that experienced with gdb, but by setting a breakpoint on the line 151 and stepping through the following instructions it won&amp;#39;t get into any fault handler, but it finally stays in ulTaskNotifyTake inside the softdevice_task without allowing any possiblity to make another step in the debugger.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/212726?ContentTypeID=1</link><pubDate>Tue, 01 Oct 2019 07:46:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00c4b6b4-a92f-462a-9849-b4c3223cfc2c</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Hi Daniel,&lt;/p&gt;
&lt;p&gt;You need to give us more details on what you mean by &amp;quot;freezes&amp;quot; on a disconnect event.&lt;/p&gt;
&lt;p&gt;How did you come to the conclusion that the execution is hanging inside softdevice_task inside nrf_sdh_freertos.c task? Was there some event that your application expected that never arrived?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE Central: freeze on disconnect with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/212022?ContentTypeID=1</link><pubDate>Thu, 26 Sep 2019 11:11:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65c7ced3-c27f-42dd-9fc4-148ad7670430</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;The FreeRTOS expert is currently out of office, but we&amp;#39;ll try to look into this next week.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>