To read the MAC addresses defined I use the following code (with CONFIG_BT_ID_MAX=2 in prj.conf):::
bt_addr_le_t addr[CONFIG_BT_ID_MAX]; //space for random address and public address
size_t count = 2; //request both addresses
bt_id_get(addr, &count); //count will contain the number of addresses returned
In reply, count is set to 1 hence only one address is defined. addr[0] contains an address of type random.
I order to define a public MAC address I got inspired by the following post:
https://devzone.nordicsemi.com/f/nordic-q-a/99585/config-for-using-sdc_hci_cmd-functions
This uses an hci command similar to setting TX power. I had to adapt it for a later version of SDK/Toolchain.
My code is as follows:
static int set_bd_addr(void)
{
int err = 0;
struct net_buf *buf;
struct bt_hci_cp_vs_write_bd_addr *cmd_params;
buf = bt_hci_cmd_create(BT_VS_CMD_BIT_WRITE_BDADDR , sizeof(*cmd_params));
if (!buf) {
printk("Could not allocate command buffer\n");
return -ENOMEM;
}
cmd_params = net_buf_add(buf, sizeof(*cmd_params));
cmd_params->bdaddr.val[0]= 0xCC;
cmd_params->bdaddr.val[1]= 0xCC;
cmd_params->bdaddr.val[2]= 0xCC;
cmd_params->bdaddr.val[3]= 0xCC;
cmd_params->bdaddr.val[4]= 0xCC;
cmd_params->bdaddr.val[5]= 0xCC;
err = bt_hci_cmd_send_sync(BT_VS_CMD_BIT_WRITE_BDADDR, buf, NULL);
printk("err: %d \n",err);
if (err) {
printk("err: %d \n",err);
return err;
}
printk("Successfully set bd addr \n");
return 0;
}
I call set_bd_addr() before bl_enable(NULL).
[00:06:03.052,322] <err> os: Data Access Violation
[00:06:03.052,326] <err> os: MMFAR Address: 0x12c1d
[00:06:03.052,336] <err> os: r0/a1: 0x00000000 r1/a2: 0x00000004 r2/a3: 0x00012c1d
[00:06:03.052,342] <err> os: r3/a4: 0x200063c8 r12/ip: 0x00000000 r14/lr: 0x0002259f
[00:06:03.052,347] <err> os: xpsr: 0x29000000
[00:06:03.052,351] <err> os: Faulting instruction address (r15/pc): 0x00022ca0
[00:06:03.052,369] <err> os: >>> ZEPHYR FATAL ERROR 19: Unknown error on CPU 0
[00:06:03.052,384] <err> os: Current thread: 0x20002ee0 (unknown)
[00:06:03.129,332] <err> os: Halting system
The project built without errors for nrf15l15dk/nrf15l15/cpuapp.
Executing function bt_hci_cmd_send_sync does not return since I get the following fatal error:
[00:06:03.052,316] <err> os: ***** MPU FAULT *****
[00:06:03.052,322] <err> os: Data Access Violation
[00:06:03.052,326] <err> os: MMFAR Address: 0x12c1d
[00:06:03.052,336] <err> os: r0/a1: 0x00000000 r1/a2: 0x00000004 r2/a3: 0x00012c1d
[00:06:03.052,342] <err> os: r3/a4: 0x200063c8 r12/ip: 0x00000000 r14/lr: 0x0002259f
[00:06:03.052,347] <err> os: xpsr: 0x29000000
[00:06:03.052,351] <err> os: Faulting instruction address (r15/pc): 0x00022ca0
[00:06:03.052,369] <err> os: >>> ZEPHYR FATAL ERROR 19: Unknown error on CPU 0
[00:06:03.052,384] <err> os: Current thread: 0x20002ee0 (unknown)
[00:06:03.129,332] <err> os: Halting system
The development board is dead. I needed do an erase via Segger J-Flash.
Hence my question: How does one specify a public MAC address and how can one signal that is should be used ?