<?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>Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77164/setting-the-ble-public-address-on-nrf5340</link><description>I am trying to set the public ble mac address from the application core of a nRF5340, I understand that I need to use bt_ctlr_set_public_addr() but I can&amp;#39;t seem to get my project to compile when I include bluetooth/controller.h , due to the source file</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 03 Sep 2023 23:59:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77164/setting-the-ble-public-address-on-nrf5340" /><item><title>RE: Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/thread/444203?ContentTypeID=1</link><pubDate>Sun, 03 Sep 2023 23:59:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:61bbecb7-d45a-4c09-b316-0f0c0b939b2f</guid><dc:creator>Michael Zeng</dc:creator><description>&lt;p&gt;This was helpful to me, so just to add on a bit more:&lt;/p&gt;
&lt;p&gt;This code didn&amp;#39;t work for me until I added&amp;nbsp;BT_LE_ADV_OPT_USE_IDENTITY to my advertising params.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/thread/434899?ContentTypeID=1</link><pubDate>Thu, 06 Jul 2023 09:44:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9b47c2d-286a-43a1-9f6d-ae0623b546c6</guid><dc:creator>John</dc:creator><description>&lt;p&gt;hi Marte,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;I follow&amp;nbsp;Capn Odin&amp;#39;s sample code and it can change the BLE mac address after system just boot up.&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;But after&amp;nbsp;&lt;span&gt;boot up, I want to change&amp;nbsp;&amp;nbsp;the BLE mac address again, it doesn&amp;#39;t work and the ble MAC address keep unchanged, it is expected?&amp;nbsp; Is it possible to change the desired BLE mac address at real time without HW reset?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/thread/326172?ContentTypeID=1</link><pubDate>Mon, 23 Aug 2021 11:52:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed20270f-1308-443e-a6f9-aa6ec8ce2c91</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I hope you&amp;nbsp;had a nice vacation, and I am glad to hear that you figured it out.&lt;/p&gt;
&lt;p&gt;Thank you so much for sharing what you did here for others to find, it is very appreciated!&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/thread/325131?ContentTypeID=1</link><pubDate>Mon, 16 Aug 2021 13:01:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a24d654b-20c9-4b6f-8ecb-d1928d71fea4</guid><dc:creator>Capn Odin</dc:creator><description>&lt;p&gt;Sorry that I did not respond sooner but some new priorities came up so I did not get time to look at this before my holiday.&lt;/p&gt;
&lt;p&gt;I was stuck for a bit because I had not understood that everything needed to talk with the network core was already in place.&lt;/p&gt;
&lt;p&gt;But if anyone else ends up on this page here is how I did it.&lt;/p&gt;
&lt;h2 id="mcetoc_1fd7gpgsm2"&gt;main.c&lt;/h2&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;bluetooth/hci_vs.h&amp;gt;
#include &amp;lt;settings/settings.h&amp;gt;
#include &amp;lt;logging/log.h&amp;gt;

LOG_MODULE_REGISTER(ble);
#define REPORT_ERROR(_ERR_CODE_)	LOG_WRN(&amp;quot;Error: %d\tFun: %s:%d\tFile: %s&amp;quot;, (_ERR_CODE_), __func__, __LINE__, __FILE__)

static char ble_device_name[30];
static bt_addr_le_t addrs[1];

void ble_set_mac(bt_addr_t* addr) {
	struct net_buf *buf;
	int err;

	buf = bt_hci_cmd_create(BT_HCI_OP_VS_WRITE_BD_ADDR, sizeof(*addr));
	if(!buf) {
		REPORT_ERROR(-ENOBUFS);
	}

	net_buf_add_mem(buf, addr, sizeof(*addr));

	err = bt_hci_cmd_send_sync(BT_HCI_OP_VS_WRITE_BD_ADDR, buf, NULL);
	if(err) {
		REPORT_ERROR(err);
	}
}

uint8_t* ble_get_mac() {
	size_t count = 1;
	bt_id_get(addrs, &amp;amp;count);
	return addrs[0].a.val;
}

int ble_advertise() {
	uint8_t* mac = ble_get_mac();
	snprintk(ble_device_name, 30, &amp;quot;%02X%02X%02X%02X%02X%02X&amp;quot;, mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);

	struct bt_data adx[] = {
		BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
		BT_DATA(BT_DATA_NAME_COMPLETE, ble_device_name, strlen(ble_device_name)),
	};

	int err = bt_le_adv_start(BT_LE_ADV_CONN, adx, ARRAY_SIZE(adx), NULL, 0);
	if(err) {
		LOG_ERR(&amp;quot;Advertising failed to start (err %d)&amp;quot;, err);
	} else {
		LOG_INF(&amp;quot;Advertising started&amp;quot;);
	}
	return err;
}

void main(void) {
	int err = bt_enable(NULL);
	if(err) {
		LOG_ERR(&amp;quot;Failed to enable Bluetooth (err: %d)&amp;quot;, err);
		return;
	}
	
	bt_addr_t addr = {{0xFE, 0xCA, 0xA0, 0xAC, 0xDC, 0xBA}};
	ble_set_mac(&amp;amp;addr);

	settings_load();
	
	ble_advertise();
	
	LOG_INF(&amp;quot;Bluetooth initialized&amp;quot;);
	
	while(true) {
		k_msleep(100);
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h2 id="mcetoc_1fd7gov1u1"&gt;prj.conf&lt;pre class="ui-code" data-mode="text"&gt;# Config BT
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_APPEARANCE=833
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_MAX_CONN=1

CONFIG_BT_HCI_VS=y
CONFIG_BT_HCI_VS_EXT=y

# Config logger
CONFIG_LOG=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_LOG_BACKEND_RTT=y
CONFIG_LOG_BACKEND_UART=n

# Enable Settings
CONFIG_BT_SETTINGS=y
CONFIG_FLASH=y
CONFIG_FLASH_PAGE_LAYOUT=y
CONFIG_FLASH_MAP=y
CONFIG_NVS=y
CONFIG_SETTINGS=y
CONFIG_MPU_ALLOW_FLASH_WRITE=y&lt;/pre&gt;&lt;/h2&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/thread/320680?ContentTypeID=1</link><pubDate>Mon, 19 Jul 2021 12:12:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2969c65-555e-48a6-94ff-10b51363209c</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The developers got back to me now.&lt;/p&gt;
&lt;p&gt;They confirmed that what I suggested in my previous reply is possible, and that you just need to add an implementation of this in the hci_rpmsg driver. You can also use the vendor specific HCI command &amp;quot;Zephyr Write BD ADDR,&amp;nbsp;sdc_hci_cmd_vs_zephyr_write_bd_addr, to set the public address, which is supported by the SoftDevice Controller. To use this you must enable CONFIG_BT_HCI_VS and CONFIG_BT_HCI_VS_EXT. See&amp;nbsp;&lt;a title="http://developer.nordicsemi.com/nrf_connect_sdk/doc/latest/nrfxlib/softdevice_controller/doc/api.html#c.sdc_hci_cmd_vs_zephyr_write_bd_addr" href="http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/softdevice_controller/doc/api.html#c.sdc_hci_cmd_vs_zephyr_write_bd_addr" rel="noopener noreferrer" target="_blank"&gt;API documentation — nrfxlib 1.6.99 documentation (nordicsemi.com)&lt;/a&gt;&amp;nbsp;for more information.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/thread/320646?ContentTypeID=1</link><pubDate>Mon, 19 Jul 2021 09:46:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34c8070b-a32e-4366-93e4-9694fb24009f</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;They have not come back to me regarding other ways to change this yet, but I have asked them for an update.&lt;/p&gt;
&lt;p&gt;I do not believe we have a function to change the address directly from the application core. However, the network core has access to the memory of the application core, and the two cores communicate, using OpenAMP. It might be possible to create something where you send a message from the application core to the network core to make it change the address, but you would then have to change the HCI RPMsg sample as well. The HCI RPMsg sample use RPMsg, which is a part of OpenAMP. If you want to look at a sample specifically for how to use the RPMsg Service, you can look at Zephyr&amp;#39;s&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/ipc/rpmsg_service/README.html#rpmsg-service-sample-application"&gt;RPMsg Service sample Application&lt;/a&gt;. You can also find the repository for OpenAMP on github here:&amp;nbsp;&lt;a href="https://github.com/OpenAMP/open-amp/"&gt;OpenAMP&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I am sorry for the delayed answer, and for not having more to help you with right now. If you want to, you can provide additional details about your problem and I can forward it to our developers.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/thread/320475?ContentTypeID=1</link><pubDate>Fri, 16 Jul 2021 14:13:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a44687ce-b228-4c13-b53d-bc87df70c684</guid><dc:creator>Capn Odin</dc:creator><description>&lt;p&gt;Hello again, I was wondering if you had heard back from the developers? Maybe they would like some additional details about my problem?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/thread/319383?ContentTypeID=1</link><pubDate>Fri, 09 Jul 2021 12:52:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b52e6bd-e542-42ac-bfea-a10330a71b8e</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have asked our developers for a clarification about this. Since the function&amp;nbsp;bt_ctlr_set_public_addr() is part of the controller API, it should be called in the application running on the network core, HCI RPMsg, and not the application core. So&amp;nbsp;unfortunately you cannot use this from the application core.&amp;nbsp;They are going to check if there are other ways to change the public address on nRF5340. I will let you know when I hear back from them.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/thread/319081?ContentTypeID=1</link><pubDate>Thu, 08 Jul 2021 07:54:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c6031f5-9c6e-4d0b-b225-2feea76e52c9</guid><dc:creator>Capn Odin</dc:creator><description>&lt;p&gt;Thank you for replaying, I have tried using &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/softdevice_controller/doc/api.html#group__HCI__VS__API_1ga4c7d8056baa349eb61f83abfe2079fe4"&gt;sdc_hci_cmd_vs_zephyr_write_bd_addr()&lt;/a&gt; but I am not able to compile the project when I use the function I get the following &amp;quot;&lt;strong&gt;error undefined reference to `sdc_hci_cmd_vs_zephyr_write_bd_add&lt;/strong&gt;r&amp;#39;&amp;quot; even thought I included the same header files as are included in hci_driver.c. Are there any config flags I have to set to get the project generated in such a way that I can use the function, I have tried with CONFIG_BT_LL_SOFTDEVICE_VS_INCLUDE=y.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Setting the BLE Public Address on nRF5340</title><link>https://devzone.nordicsemi.com/thread/318990?ContentTypeID=1</link><pubDate>Wed, 07 Jul 2021 13:02:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c1d152b-f586-4268-91c3-ae240608df88</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The Bluetooth HCI RPMsg sample on the network core exposes the Bluetooth Controller for the application core, so I believe you should be able to use&amp;nbsp;bt_ctlr_set_public_addr() in the application to set the public address. The function can also be found in the HCI driver, &amp;lt;ncs_root&amp;gt;nrf/subsys/bluetooth/controller/hci_driver.c, where they simply use the function&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfxlib/softdevice_controller/doc/api.html#group__HCI__VS__API_1ga4c7d8056baa349eb61f83abfe2079fe4"&gt;sdc_hci_cmd_vs_zephyr_write_bd_addr()&lt;/a&gt;&amp;nbsp;to write the address to memory. Please try using this instead and see if that solves your issue.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>