<?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>Dynamic allocate BLE observers</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30470/dynamic-allocate-ble-observers</link><description>Hi 
 I am working on a firmware which can be used in serveral custom boards. While it works perfect in old sdk, I met the following problem when migrating from Sdk 12.2 to 14.2. Would you please take a look? Thanks 
 Since I HAVE serveral boards which</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 19 Feb 2018 11:17:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30470/dynamic-allocate-ble-observers" /><item><title>RE: Dynamic allocate BLE observers</title><link>https://devzone.nordicsemi.com/thread/121232?ContentTypeID=1</link><pubDate>Mon, 19 Feb 2018 11:17:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e2f24ab-11c5-4126-803b-79b80025f9fd</guid><dc:creator>nine-fox</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;H&amp;aring;kon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks a lot for your reply!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Your suggestions look great to me and I will have a try :-)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Vincent&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic allocate BLE observers</title><link>https://devzone.nordicsemi.com/thread/121203?ContentTypeID=1</link><pubDate>Mon, 19 Feb 2018 09:00:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f217ec48-1593-4091-b520-8c1c32b2e6ce</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Vincent,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Sorry for misunderstanding, and thanks for clarifying your use-case!&lt;/p&gt;
&lt;p&gt;I am functions from SDK v14, application ble_app_hids_keyboard as an example here;&lt;/p&gt;
&lt;p&gt;you can mimic the &amp;quot;older&amp;quot; use-case by declaring the m_hids variable as you did in SDK 12, and then call &amp;quot;ble_hids_on_ble_evt(p_ble_evt, NULL)&amp;quot; from main.c::ble_evt_handler() with an if-condition for dynamic handling. Note that you&amp;#39;ll also need to comment out (or, wrap an if-condition around if&amp;nbsp;dynamic handling of HIDS) hids_init() in main.c::services_init().&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If DEVICE B never needs the hid-service, then I would just use #ifdef to remove it from the project when compiling for this specific device.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic allocate BLE observers</title><link>https://devzone.nordicsemi.com/thread/121147?ContentTypeID=1</link><pubDate>Sat, 17 Feb 2018 05:33:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65305604-034d-4f50-818a-096903906cc0</guid><dc:creator>nine-fox</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;H&amp;aring;kon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks a lot for your detailed reply! Following your guide, I can define these observers successfully. However, it is *STATIC*.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;For example, my&amp;nbsp;firmware needs to start with HID and NUS service for DEVICE A, so I add the following lines in my code:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;BLE_HIDS_DEF(m_hids);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;BLE_NUS_DEF(m_nus);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;However, when this firmware starts for DEVICE B, it only needs NUS service ONLY. As a result,&amp;nbsp;m_hids is not used, and the hid listener is added anyway.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;How can I add NUS service and listen for NUS events only for DEVICE B? (while DEVICE A works well)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Vincent&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Dynamic allocate BLE observers</title><link>https://devzone.nordicsemi.com/thread/120786?ContentTypeID=1</link><pubDate>Wed, 14 Feb 2018 09:24:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96bc8675-b940-4829-ade8-d9871d1a66c4</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Most of this is done in linker sections. This is what BLE_HIDS_DEF expands to:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define BLE_HIDS_DEF(_name)                                                                         \
static ble_hids_t _name;                                                                            \
NRF_SDH_BLE_OBSERVER(_name ## _obs,                                                                 \
                     BLE_HIDS_BLE_OBSERVER_PRIO,                                                    \
                     ble_hids_on_ble_evt, &amp;amp;_name)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And NRF_SDH_BLE_OBSERVER(...) expands to defining a linker section (though several steps), which shall be declared in your linker script as the .sdh_ble_observer section:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;*snip*
  .sdh_ble_observers :
  {
    PROVIDE(__start_sdh_ble_observers = .);
    KEEP(*(SORT(.sdh_ble_observers*)))
    PROVIDE(__stop_sdh_ble_observers = .);
  } &amp;gt; FLASH
*snip*&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This tells the linker where the section is located both with a __start and a __stop symbol (think of it like a pointer), so that it is able to&amp;nbsp;statically allocate &amp;#39;n&amp;#39; amount of observers based on how many BLE_ANY_SERVICE_DEF(...) that you have in your application.&lt;/p&gt;
&lt;p&gt;The library nrf_sdh will then iterate over all the BLE_*_DEF() objects so you do not have to go into your main.c::on_ble_evt() function to add another function call.&lt;/p&gt;
&lt;p&gt;In order to migrate your current project to SDK 14.x, you need to conform to the BLE_*_DEF() API for your BLE observers, and updated your linker script. The linker script can be taken from almost any ble_app_* example, as they all include the sections needed. Remember that you might need to adjust the RAM start address.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Let me know if you run into trouble.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>