<?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>Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87490/define-a-ble-service-instance-on-the-header-file</link><description>Hi, 
 I&amp;#39;m currently development firmware for a application using a Nordic chip. This application will use some drivers allowing the communication with sensors and for the transmission of the sensor data I will use the BLE. So t his application is expected</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 11 May 2022 21:05:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87490/define-a-ble-service-instance-on-the-header-file" /><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/367491?ContentTypeID=1</link><pubDate>Wed, 11 May 2022 21:05:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e207720-41ac-40f7-a111-427d133e33bd</guid><dc:creator>jpedroliveira</dc:creator><description>&lt;p&gt;Hi!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So I think we can close this ticket! Thank you so much for your help&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/367092?ContentTypeID=1</link><pubDate>Tue, 10 May 2022 08:34:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb9bd9c6-09b4-4e58-baa5-3daa1a2badf8</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi, no worries.&lt;/p&gt;
[quote user="jpedroliveira"]But I have some questions, the others instances are also defined there, why for them there is no problem? [/quote]
&lt;p&gt;It is problematic to have multiple instances of the service structs even you don&amp;#39;t notice any problems right away. The reason the others don&amp;#39;t cause a crash in their respective on_connect() implementations is that they happen to include additional checks that will prevent the program from calling the zero-initialized function pointer.&lt;/p&gt;
&lt;p&gt;e.g. here is the on_connect() implementation in ble_nus.c:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1652171516631v1.png" alt=" " /&gt;&lt;/p&gt;
[quote user="jpedroliveira"]And also, can I do something to define the LLS instance one time only (on the .h file)?&amp;nbsp;[/quote]
&lt;p&gt;Then you have to declared the variable as &amp;quot;extern&amp;quot; in your header file.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/366921?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 12:15:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a761fe56-ba61-46d2-8fe7-9398f1dceb78</guid><dc:creator>jpedroliveira</dc:creator><description>&lt;p&gt;Hi! Sorry for the late answer. Regarding your question, after doing some tests I believe that you are correct. The .h file are been called in different .c files.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But I have some questions, the others instances are also defined there, why for them there is no problem? And also, can I do something to define the LLS instance one time only (on the .h file)?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/366482?ContentTypeID=1</link><pubDate>Thu, 05 May 2022 13:19:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb9bcbcb-5aee-4c74-b515-7ba9a1b8055a</guid><dc:creator>Vidar Berg</dc:creator><description>[quote user="jpedroliveira"]But for some reason, when declaring the instance in the .h file[/quote]
&lt;p&gt;I guess maybe you have this .h file included in different .c files? In that case, you will end up with multiple instances of the link loss service structure, but only one will be correctly initialized. This means your program will end up executing a null pointer when processing the connection event and trigger a hardfault exception.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/1614.pastedimage1651756537161v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt;: just to be clear, the function pointer I&amp;#39;m referring to is &amp;#39;.&lt;strong&gt;evt_handler&lt;/strong&gt;&amp;#39;. I realize &lt;strong&gt;&lt;/strong&gt;the arrow I drew in the picture above can be misleading.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/366315?ContentTypeID=1</link><pubDate>Wed, 04 May 2022 16:05:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0ca5ec6-b8c1-4b77-8ac9-ca47269317a5</guid><dc:creator>jpedroliveira</dc:creator><description>&lt;p&gt;But the BLE event 0x10 happen in both examples. But for some reason, when declaring the instance in the .h file, the code block after going to the lls_handler_evt. And for that reason the firmware never goes to the ble_handler_evt&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/366148?ContentTypeID=1</link><pubDate>Wed, 04 May 2022 09:35:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c7bd5855-9f54-45a4-9b0d-d0f9bafd155c</guid><dc:creator>dejans</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Regarding nrf_sdh_ble BLE event 0x10, you can take a look at \headers\ble_ranges.h. This corresponds to the BLE_GAP_EVT_CONNECTED in the ble_gap.h. BLE_GAP_EVT_CONNECTED is one of the events that are coming from the stack to the application.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Dejan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/366066?ContentTypeID=1</link><pubDate>Tue, 03 May 2022 18:21:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1af24437-5fd6-4b8d-8ba5-abae9870e6e9</guid><dc:creator>jpedroliveira</dc:creator><description>&lt;p&gt;Hi!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using the nRF2840-DK with the nRF5_SDK_17.0.2 and the softdevice is the 140_nrf52_7.2.0_softdevice.hex&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/366050?ContentTypeID=1</link><pubDate>Tue, 03 May 2022 15:39:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:819e7da1-e473-4eaf-b933-90d57d5d0828</guid><dc:creator>dejans</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;Which board and SoftDevice version are you using?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Dejan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/365967?ContentTypeID=1</link><pubDate>Tue, 03 May 2022 11:59:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d09dce57-6356-436d-b0d8-cfc2e40abfb7</guid><dc:creator>jpedroliveira</dc:creator><description>&lt;p&gt;Hi! Thanks for your reply!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This first 2 images are basically the same but with Battery Service implemented.&lt;/p&gt;
&lt;p&gt;When I define the&amp;nbsp;&lt;span&gt;Link Loss Service instance on the .h file and I try to connect, the code blocks at this point. Even if a try connect again, nothing happen.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1651578280022v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;This second image is when a define the Link Loss Service instance on the .c file.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1651578177527v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;On this last 2 images, only the Link Loss Service is implemented. The first one is when the service instance is declared on the .h file&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1651578938788v4.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Only with the Link Loss Service and the instance being declare on the .c file.&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1651578782237v3.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/365952?ContentTypeID=1</link><pubDate>Tue, 03 May 2022 11:04:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0256259b-ca37-4e3e-92f3-13827353ac31</guid><dc:creator>dejans</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;Could you share results of these scenarios with one&amp;nbsp;(LLS) and two (LLS and one more) services?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Dejan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/365894?ContentTypeID=1</link><pubDate>Tue, 03 May 2022 08:11:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8430a3f9-e1bc-4e04-a09c-9dfedc83d616</guid><dc:creator>jpedroliveira</dc:creator><description>&lt;p&gt;Hi! Thanks for your reply. Yes, I have tried with the LLS alone and with only one more service.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Define a BLE service instance on the header file</title><link>https://devzone.nordicsemi.com/thread/365840?ContentTypeID=1</link><pubDate>Mon, 02 May 2022 17:56:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fd12d12-3a69-4a16-a947-28e46b98c3a4</guid><dc:creator>austin944</dc:creator><description>&lt;p&gt;Have you tried it with just LLS and BAS, or LLS and NUS, or perhaps LLS alone?&amp;nbsp; I vaguely recall that I had problems when defining too many services.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>