<?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>Issues with modularising code</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/85391/issues-with-modularising-code</link><description>I am developing my first BLE Server application with the nRF52832 and using VSC/nRF Connect/Zephyr ROTS. I come from a Cypress/PSOC Creator background, and am struggling a bit to get up to speed with the Nordic stuff. 
 Using the peripheral_dis example</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 08 Mar 2022 09:40:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/85391/issues-with-modularising-code" /><item><title>RE: Issues with modularising code</title><link>https://devzone.nordicsemi.com/thread/356802?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2022 09:40:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ed474b6-26a7-48f9-b9d5-5b2235bcf4b2</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;Thanks for the clarification.&amp;nbsp; Gave your suggest a go and it works - thanks&lt;/p&gt;
&lt;p&gt;- Mike.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issues with modularising code</title><link>https://devzone.nordicsemi.com/thread/356781?ContentTypeID=1</link><pubDate>Tue, 08 Mar 2022 08:44:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:041f0068-96f9-4307-a238-a25d2f6aea57</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Right, I see.&lt;/p&gt;
&lt;p&gt;I believe you&amp;#39;ll want to define the arrays in the same file that you use them in, anything else would just make things more difficult for yourself.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been able to define bt_data structs outside main.c before, but then I called bt_le_adv_start in a custom bluetooth init function that was then called in main.&lt;/p&gt;
&lt;p&gt;That way, you don&amp;#39;t have to worry about your structs being defined outside your bluetooth file, maybe that could work for your project?&lt;/p&gt;
&lt;p&gt;-Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issues with modularising code</title><link>https://devzone.nordicsemi.com/thread/356725?ContentTypeID=1</link><pubDate>Mon, 07 Mar 2022 22:49:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b01dc52d-01d0-4f78-acd9-f6e5edb2ac86</guid><dc:creator>Mike Austin (LPI)</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve done some more investigations into this.&amp;nbsp; The problem seems to come when I try and move my advertising and scan response packet definitions outside my main.c&lt;/p&gt;
&lt;p&gt;So, with these two definitions inside main.c - everything works OK&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Bluetooth Advertising data
static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),   // Sets up advertising parameters
	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_LPI_DEVICE),  				// Defines any Service UUIDs to include in advertising packet
};

// Bluetooth Scan Response data (initially empty)
static struct bt_data sd[] = {
    BT_DATA(BT_DATA_MANUFACTURER_DATA, NULL, BT_GAP_ADV_MAX_ADV_DATA_LEN-2),
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But if I attempt to shift these into my bt_config.c and bt_config.h, things fall over.&amp;nbsp; I think its got something to do with not being allowed to have a variable length array defined in another .c file and attempt to make this visible to other .c files.&lt;/p&gt;
&lt;p&gt;I attempted to get around this by defining those arrays with a fixed length, using&amp;nbsp;BT_GAP_ADV_MAX_ADV_DATA_LEN.&amp;nbsp; So, in bt_config.c I had:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;// Bluetooth Advertising data
const struct bt_data ad[BT_GAP_ADV_MAX_ADV_DATA_LEN] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),   // Sets up advertising parameters
	BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_LPI_DEVICE),  				// Defines any Service UUIDs to include in advertising packet
};

// Bluetooth Scan Response data (initially empty)
struct bt_data sd[BT_GAP_ADV_MAX_ADV_DATA_LEN] = {
    BT_DATA(BT_DATA_MANUFACTURER_DATA, NULL, BT_GAP_ADV_MAX_ADV_DATA_LEN-2),
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And then in bt_config.h I had:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
extern const struct bt_data ad[BT_GAP_ADV_MAX_ADV_DATA_LEN];
extern struct bt_data sd[BT_GAP_ADV_MAX_ADV_DATA_LEN];&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But whilst this would compile, it would throw up err = -22 when I tried to initialise the Bluetooth in main.c with a call to&amp;nbsp;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;err = bt_le_adv_start(&lt;/span&gt;&lt;/span&gt;&lt;span&gt;BT_LE_ADV_CONN_NAME&lt;/span&gt;&lt;span&gt;, ad, &lt;/span&gt;&lt;span&gt;ARRAY_SIZE&lt;/span&gt;&lt;span&gt;(ad), sd, &lt;/span&gt;&lt;span&gt;ARRAY_SIZE&lt;/span&gt;&lt;span&gt;(sd));&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Regards,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Mike&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Issues with modularising code</title><link>https://devzone.nordicsemi.com/thread/355992?ContentTypeID=1</link><pubDate>Thu, 03 Mar 2022 10:29:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84cf46f6-6a6e-4b2c-b2dc-aa43db8aab1d</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Hello!&lt;/p&gt;
&lt;p&gt;Are you using NCS 1.9, or are you using an older version?&lt;/p&gt;
&lt;p&gt;And could you please share the compile error messages you are getting?&lt;/p&gt;
&lt;p&gt;That would make it much easier to help you.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>