<?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>Multiple BLE_CUS_DEF() calls error</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/52010/multiple-ble_cus_def-calls-error</link><description>Hi I am trying to add multiple services to the custom_ble_service tutorial example right now. When I try to create a second ble_cus_t instance &amp;#39;mcus2&amp;#39; by calling BLE_CUS_DEF(m_cus2) the code compiles, but after I flash the code and connect to DK board</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 28 Nov 2024 08:29:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/52010/multiple-ble_cus_def-calls-error" /><item><title>RE: Multiple BLE_CUS_DEF() calls error</title><link>https://devzone.nordicsemi.com/thread/512519?ContentTypeID=1</link><pubDate>Thu, 28 Nov 2024 08:29:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aeeff07e-ebe2-476d-a104-45c6522b45a5</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/* near top of your main.c file */
#define BLE_CUSTOM_SERVICE_ARRAY_DEF(_name, _cnt)                 \
static ble_nus_c_t _name[_cnt];                          \
NRF_SDH_BLE_OBSERVERS(_name ## _obs,                     \
                      BLE_NUS_C_BLE_OBSERVER_PRIO,       \
                      ble_evt_handler, &amp;amp;_name, _cnt)
                      
                      
BLE_CUSTOM_SERVICE_ARRAY_DEF(m_ble_observers, MAX_CONNECTIONS)

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Try adding this close to the top of your main.c. This will generate context pointers to each of your instances. You need to place it in main.c, since this is where your ble_evt_handler is defined. You may need to declare the ble_evt_handler before your call to BLE_CUSTOM_SERVICE_ARRAY_DEF() like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple BLE_CUS_DEF() calls error</title><link>https://devzone.nordicsemi.com/thread/512513?ContentTypeID=1</link><pubDate>Thu, 28 Nov 2024 07:56:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27eaff86-1298-417c-ab07-d02549f4dee3</guid><dc:creator>arnold park.jr</dc:creator><description>&lt;p&gt;Thx for your fast reply.&lt;br /&gt;&lt;br /&gt;I defined like below.&lt;/p&gt;
&lt;p&gt;static void * const obs_context[] = {NULL,&amp;nbsp;&lt;span&gt;NULL,&amp;nbsp;&lt;/span&gt;&lt;span&gt;NULL,&amp;nbsp;&lt;/span&gt;&lt;span&gt;NULL,&amp;nbsp;&lt;/span&gt;&lt;span&gt;NULL,&amp;nbsp;&lt;/span&gt;&lt;span&gt;NULL }&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;NRF_SDH_BLE_OBSERVERS(m_ble_observers, 3, ble_evt_handler, obs_context, 6);&amp;nbsp; &amp;nbsp;//This define is in ble_stack_init() function.&lt;/p&gt;
&lt;p&gt;But an error&amp;nbsp;corrupt,&amp;nbsp;&amp;nbsp;&amp;#39;expression must have a constant value&amp;#39;. I cant understand which parameter should be in&amp;nbsp;NRF_SDH_BLE_OBSERVERS().&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple BLE_CUS_DEF() calls error</title><link>https://devzone.nordicsemi.com/thread/512508?ContentTypeID=1</link><pubDate>Thu, 28 Nov 2024 07:45:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2303cb2f-9779-4c30-98cb-9773287908ad</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I suggest you study the SDK\examples\ble_central\ble_app_uart_c example, and look at how it uses defines:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/** @brief Macro for defining multiple ble_nus_c instances.
 *
 * @param   _name   Name of the array of instances.
 * @param   _cnt    Number of instances to define.
 * @hideinitializer
 */
#define BLE_NUS_C_ARRAY_DEF(_name, _cnt)                 \
static ble_nus_c_t _name[_cnt];                          \
NRF_SDH_BLE_OBSERVERS(_name ## _obs,                     \
                      BLE_NUS_C_BLE_OBSERVER_PRIO,       \
                      ble_nus_c_on_ble_evt, &amp;amp;_name, _cnt)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in ble_nus_c.h. You can do something similar in your application. Create a macro called BLE_CUSTOM_SERVICE_ARRAY_DEF(_name, _cnt), and use it from your main.c. The only thing you need to change is the name of the macro (BLE_CUSTOM_SERVICE_ARRAY_DEF(), and make sure to keep the _cnt argument up to date from where it is being called in main.c. (you can set it equal to&amp;nbsp;NRF_SDH_BLE_PERIPHERAL_LINK_COUNT or&amp;nbsp;NRF_SDH_BLE_CENTRAL_LINK_COUNT, perhaps).&lt;/p&gt;
&lt;p&gt;You also need to replace&amp;nbsp;ble_nus_c_on_ble_evt with the name of the callback function that you want to use for this observer, and to replace the BLE_NUS_C_BLE_OBSERVER_PRIO with whatever priority you want to use. Either create a new definition in sdk_config.h, or just use one of the ones that are available in the sdk_config.h file. Search for &amp;quot;OBSERVER_PRIO&amp;quot;, and use one of them. As you can see, they are typically set to 2, so you can use this.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple BLE_CUS_DEF() calls error</title><link>https://devzone.nordicsemi.com/thread/512475?ContentTypeID=1</link><pubDate>Thu, 28 Nov 2024 01:58:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4200447b-9830-4b16-aa10-fbf11559f22c</guid><dc:creator>arnold park.jr</dc:creator><description>&lt;p&gt;Hi.. i facing this issue too. If I defined&amp;nbsp;&lt;span&gt;NRF_SDH_BLE_OBSERVER&amp;#39;S&amp;#39;(), not&amp;nbsp;NRF_SDH_BLE_OBSERVER(), error corrupt called &amp;#39;expression must have pointer-to-object type&amp;#39;.&lt;br /&gt;I dont know how to use it&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; Plz tell share me how to fixed it.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple BLE_CUS_DEF() calls error</title><link>https://devzone.nordicsemi.com/thread/445726?ContentTypeID=1</link><pubDate>Wed, 13 Sep 2023 04:14:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c32cf79d-b33e-4f1f-9d5b-8cfda4711cf8</guid><dc:creator>Abiots</dc:creator><description>&lt;p&gt;Hi, I too am facing similar issues, may I know how you fixed it?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple BLE_CUS_DEF() calls error</title><link>https://devzone.nordicsemi.com/thread/209509?ContentTypeID=1</link><pubDate>Fri, 13 Sep 2019 03:45:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32202f3d-cf8a-4192-a480-8b3d3e205f8d</guid><dc:creator>thoric_fish</dc:creator><description>&lt;p&gt;Hi an update: I got it working after using&amp;nbsp;NRF_SDH_BLE_OBSERVERS().&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple BLE_CUS_DEF() calls error</title><link>https://devzone.nordicsemi.com/thread/209258?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2019 16:55:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b1e05f3-4aed-4cf2-bb1b-f7ceb1e8503b</guid><dc:creator>thoric_fish</dc:creator><description>&lt;p&gt;SDK v15.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;err_code = ble_cus_init(&amp;amp;m_cus, &amp;amp;cus_init);
        APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;returns NRF_SUCESS and the rest of the code in main() for initializing the services and advertising works. The advertising starts normally and I can scan &amp;amp; connect to the DK. But immediately after the connection is made the connection disconnects and I cannot reconnect. If I remove&amp;nbsp;BLE_CUS_DEF(m_cus2); from main.c there is no longer this issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Multiple BLE_CUS_DEF() calls error</title><link>https://devzone.nordicsemi.com/thread/209104?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2019 08:40:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3ce7706-3f12-4263-9db5-beb6588fdc3a</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;What SDK version are you using?&lt;/p&gt;
&lt;p&gt;Have you checked whether one of your function calls returns an err_code != NRF_SUCCESS?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>