<?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>Central and Peripheral: BLE_NUS in parallel with BLE_HRS_C</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/44745/central-and-peripheral-ble_nus-in-parallel-with-ble_hrs_c</link><description>Hi, 
 would like to run several (8) BLE_HRS_C in parallel to one BLE_NUS on a nRF5. Can that work? 
 In general, is it there any sample code showing how to implement peripheral role (BLE_NUS) in parallel with central role (BLE_HRS_C)? 
 The problem I</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 30 Jun 2019 22:44:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/44745/central-and-peripheral-ble_nus-in-parallel-with-ble_hrs_c" /><item><title>RE: Central and Peripheral: BLE_NUS in parallel with BLE_HRS_C</title><link>https://devzone.nordicsemi.com/thread/195488?ContentTypeID=1</link><pubDate>Sun, 30 Jun 2019 22:44:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d67d6b0-b76e-450d-8290-5d3554f1d239</guid><dc:creator>goldwake</dc:creator><description>&lt;p&gt;This issue is a pain for me as well. Having central and peripheral connections doesn&amp;#39;t work very well with the link ctx mgr. It&amp;#39;s a bit wasteful having&amp;nbsp; sizeof(ble_nus_client_context_t) * num_central_connections unused bytes allocated for the ctx manager. Especially when you&amp;#39;ve got a lot of connection which use up a lot ofRAM already.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I know it&amp;#39;s not ideal but I use my own blcm_link_ctx_get function to handle this&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static uint32_t get_link_ctx(ble_gm_device_t * p_gm_device, uint16_t conn_handle, ble_gm_device_client_context_t ** const p_client)
{
    if (p_client == NULL)
    {
        return NRF_ERROR_NULL;
    }
    else
    {
        *p_client = NULL;
    }
    
    VERIFY_PARAM_NOT_NULL(p_gm_device-&amp;gt;p_link_ctx_storage);
    VERIFY_PARAM_NOT_NULL(p_gm_device-&amp;gt;p_link_ctx_storage-&amp;gt;p_ctx_data_pool);
    VERIFY_TRUE((p_gm_device-&amp;gt;p_link_ctx_storage-&amp;gt;link_ctx_size % BYTES_PER_WORD) == 0, NRF_ERROR_INVALID_PARAM);
    
    uint16_t link_ctx_index = 0;
    for(link_ctx_index = 0; link_ctx_index &amp;lt; p_gm_device-&amp;gt;p_link_ctx_storage-&amp;gt;max_links_cnt; link_ctx_index++)
    {
        if(p_gm_device-&amp;gt;conn_handles[link_ctx_index] == conn_handle )
        {
            *p_client = (void *) ((uint8_t *) p_gm_device-&amp;gt;p_link_ctx_storage-&amp;gt;p_ctx_data_pool + 
                             link_ctx_index * p_gm_device-&amp;gt;p_link_ctx_storage-&amp;gt;link_ctx_size);
            return NRF_SUCCESS;
        }
    }
    return NRF_ERROR_NOT_FOUND;
    
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central and Peripheral: BLE_NUS in parallel with BLE_HRS_C</title><link>https://devzone.nordicsemi.com/thread/177051?ContentTypeID=1</link><pubDate>Tue, 19 Mar 2019 13:40:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b74e5c0-0f35-4977-8f16-cd0d3ea26118</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;With&amp;nbsp;the current implementation, the&amp;nbsp;more correct way&amp;nbsp;would&amp;nbsp;probably be to use the link context manager for all links and not just the NUS connection. But I think it&amp;#39;s ok to modify the SDK module as you did.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central and Peripheral: BLE_NUS in parallel with BLE_HRS_C</title><link>https://devzone.nordicsemi.com/thread/176781?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2019 15:08:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c4609f7-47d5-4c8c-84d8-ad55f2d7a1b8</guid><dc:creator>Andrea Aizza</dc:creator><description>&lt;p&gt;Yes, sure. The below is sufficient. But I did not wanna modify SDK files. Just wondering what is the right way to do it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;diff --git a/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c b/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c
index 2a139f4..11ae062 100644
--- a/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c
+++ b/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c
@@ -67,10 +67,10 @@ ret_code_t blcm_link_ctx_get(blcm_link_ctx_storage_t const * const p_link_ctx_st
         return NRF_ERROR_NOT_FOUND;
     }
 
-    if (conn_id &amp;gt;= p_link_ctx_storage-&amp;gt;max_links_cnt)
-    {
-        return NRF_ERROR_NO_MEM;
-    }
+    //if (conn_id &amp;gt;= p_link_ctx_storage-&amp;gt;max_links_cnt)^M
+    //{^M
+    //    return NRF_ERROR_NO_MEM;^M
+    //}^M
 
     *pp_ctx_data = (void *) ((uint8_t *) p_link_ctx_storage-&amp;gt;p_ctx_data_pool + 
                              conn_id * p_link_ctx_storage-&amp;gt;link_ctx_size);
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central and Peripheral: BLE_NUS in parallel with BLE_HRS_C</title><link>https://devzone.nordicsemi.com/thread/176662?ContentTypeID=1</link><pubDate>Mon, 18 Mar 2019 10:36:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a3d82a31-b05b-4900-abf6-d3c47d793adf</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Sorry, you&amp;#39;re right, the link context manager uses the connection handle value to determine if it has enough buffer for the connection even though it&amp;#39;s only used for the NUS connection in this case. Does it work if you also comment out the error check in &amp;nbsp;ble_link_ctx_manager?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central and Peripheral: BLE_NUS in parallel with BLE_HRS_C</title><link>https://devzone.nordicsemi.com/thread/176423?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2019 13:30:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f65b72b0-a40f-4535-a80c-3c1441f93cf3</guid><dc:creator>Andrea Aizza</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;does not work. conn_id==8 still reaches&amp;nbsp;components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c as above and generates same error above.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;(gdb) p conn_handle
$2 = 8
(gdb) s
nrf_atflags_get (p_flags=p_flags@entry=0x2000bf90 &amp;lt;m_bcs+4&amp;gt;, flag_index=flag_index@entry=8)
    at ../../../../../../components/libraries/atomic_flags/nrf_atflags.c:95
95          return (p_flags[FLAG_BASE(flag_index)] &amp;amp; FLAG_MASK(flag_index)) != 0;
(gdb) s
blcm_link_ctx_get (p_link_ctx_storage=0x2000ad74 &amp;lt;m_nus_link_ctx_storage&amp;gt;,
    conn_handle=conn_handle@entry=8, pp_ctx_data=pp_ctx_data@entry=0x2000fba4)
    at ../../../../../../components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c:65
65          if (conn_id == BLE_CONN_STATE_MAX_CONNECTIONS)
(gdb) bt
#0  blcm_link_ctx_get (p_link_ctx_storage=0x2000ad74 &amp;lt;m_nus_link_ctx_storage&amp;gt;, conn_handle=conn_handle@entry=8, pp_ctx_data=pp_ctx_data@entry=0x2000fba4)
    at ../../../../../../components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c:65
#1  0x000342d8 in ble_nus_data_send (p_nus=p_nus@entry=0x2000ad58 &amp;lt;m_nus&amp;gt;, p_data=p_data@entry=0x2000b83c &amp;lt;data_array&amp;gt; &amp;quot;&amp;lt;removed text&amp;gt;\r&amp;quot;, p_length=0x2000fbd2, 
    p_length@entry=0x2000fbb2, conn_handle=&amp;lt;optimized out&amp;gt;) at ../../../../../../components/ble/ble_services/ble_nus/ble_nus.c:325
#2  0x0002c268 in send_to_nus (fmt=0x35a38 &amp;quot;blished, starting DB discovery.&amp;quot;) at ../../../main.c:185
#3  0x0002c69e in ble_evt_handler (p_ble_evt=0x2000fc84, p_context=&amp;lt;optimized out&amp;gt;) at ../../../main.c:433
#4  0x0002d0aa in nrf_sdh_ble_evts_poll (p_context=&amp;lt;optimized out&amp;gt;) at ../../../../../../components/softdevice/common/nrf_sdh_ble.c:307
#5  0x0002d056 in nrf_sdh_evts_poll () at ../../../../../../components/softdevice/common/nrf_sdh.c:358
#6  SWI2_EGU2_IRQHandler () at ../../../../../../components/softdevice/common/nrf_sdh.c:367
#7  &amp;lt;signal handler called&amp;gt;
#8  0x00015c7e in ?? ()
#9  0x00015c7c in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Anything I am doing wrong?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central and Peripheral: BLE_NUS in parallel with BLE_HRS_C</title><link>https://devzone.nordicsemi.com/thread/176353?ContentTypeID=1</link><pubDate>Fri, 15 Mar 2019 09:16:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8dd71364-e0ea-4f0e-8612-616178692788</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Andrea,&lt;/p&gt;
&lt;p&gt;Yes, that&amp;#39;s what I meant.&amp;nbsp;My proposed change should prevent the &amp;quot;&lt;span&gt;BLE_HRS_C&amp;quot; connections from being&amp;nbsp;processed by the NUS service.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central and Peripheral: BLE_NUS in parallel with BLE_HRS_C</title><link>https://devzone.nordicsemi.com/thread/176290?ContentTypeID=1</link><pubDate>Thu, 14 Mar 2019 17:16:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf558ccc-b48d-4805-9e0a-c2474f3377c7</guid><dc:creator>Andrea Aizza</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;ok, thanks and noted about not available sample.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you mean that i need anyhow to modify ble_nus.c? And you modification is the one to take, not the one I actually made (see below)?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;diff --git a/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c b/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c
index 2a139f4..11ae062 100644
--- a/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c
+++ b/components/ble/ble_link_ctx_manager/ble_link_ctx_manager.c
@@ -67,10 +67,10 @@ ret_code_t blcm_link_ctx_get(blcm_link_ctx_storage_t const * const p_link_ctx_st
         return NRF_ERROR_NOT_FOUND;
     }
 
-    if (conn_id &amp;gt;= p_link_ctx_storage-&amp;gt;max_links_cnt)
-    {
-        return NRF_ERROR_NO_MEM;
-    }
+    //if (conn_id &amp;gt;= p_link_ctx_storage-&amp;gt;max_links_cnt)^M
+    //{^M
+    //    return NRF_ERROR_NO_MEM;^M
+    //}^M
 
     *pp_ctx_data = (void *) ((uint8_t *) p_link_ctx_storage-&amp;gt;p_ctx_data_pool + 
                              conn_id * p_link_ctx_storage-&amp;gt;link_ctx_size);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Andrea&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Central and Peripheral: BLE_NUS in parallel with BLE_HRS_C</title><link>https://devzone.nordicsemi.com/thread/176179?ContentTypeID=1</link><pubDate>Thu, 14 Mar 2019 12:42:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1594bf75-7c70-4e27-b2cb-653ad4cbd752</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;We don&amp;#39;t have an example for combining hrs_c and nus unfortunately.&amp;nbsp;But you can try adding filtering of the BLE events in the NUS services so only connections with GAP peripheral role will be processed by the event handler.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can use the &lt;a href="https://www.nordicsemi.com/DocLib/Content/SDK_Doc/nRF5_SDK/v15-3-0/lib_ble_link_ctx_manager"&gt;connection state module&lt;/a&gt; to keep track GAP roles for each active connections. E.g.,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="diff"&gt;diff --git a/components/ble/ble_services/ble_nus/ble_nus.c b/components/ble/ble_services/ble_nus/ble_nus.c
index 1c32b52..631f1c4 100644
--- a/components/ble/ble_services/ble_nus/ble_nus.c
+++ b/components/ble/ble_services/ble_nus/ble_nus.c
@@ -217,7 +217,8 @@ static void on_hvx_tx_complete(ble_nus_t * p_nus, ble_evt_t const * p_ble_evt)

 void ble_nus_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
 {
-    if ((p_context == NULL) || (p_ble_evt == NULL))
+    if ((p_context == NULL) || (p_ble_evt == NULL) ||
+        (BLE_GAP_ROLE_PERIPH != ble_conn_state_role(p_ble_evt-&amp;gt;evt.common_evt.conn_handle)))
     {
         return;
     }
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>