I'm trying to use the nRF52840 with the nRF Connect SDK 2.2.0 to create a BLE device that supports both Central and Peripheral. This basically works, but there is a problem when trying to set a public MAC address. The function `bt_ctlr_set_public_addr()` works when I'm using either CONFIG_BT_CENTRAL or CONFIG_BT_PERIPHERAL, but seems to do nothing when using both CONFIG_BT_CENTRAL and CONFIG_BT_PERIPHERAL. In the latter case there are no error messages but when calling `bt_enable()` a static random address is used instead of the public address manually set. I can reproduce the error with following code:
# prj.conf
CONFIG_BT=y CONFIG_BT_CENTRAL=y CONFIG_BT_PERIPHERAL=y # Some other stuff to enable Logging via RTT and Debugging
# main.c
void main(void) {
static const uint8_t _dbg_mac[6] = {0x01, 0x00, 0x00, 0x25, 0x80, 0x00};
bt_ctlr_set_public_addr(_dbg_mac);
int err = bt_enable(NULL);
if (err) {
LOG_ERR("Bluetooth init failed (err %d)", err);
}
while (1) {
k_sleep(K_MSEC(500));
}
}Some more information:
* `bt_ctlr_set_public_addr()` calls the correct function in `nrf/subsys/bluetooth/controller/hci_driver.c` and seems to call into the SoftDevice
* `bt_id_init()` in `zephyr/subsys/bluetooth/host/id.c` calls `bt_id_read_public_addr()` (via `bt_setup_public_id_addr()`) which then reads the address via HCI. The HCI command does not report an error and returns an all zero address. This sets `bt_dev.id_count` to zero.
* `bt_id_init()` then calls `bt_setup_random_id_addr()` because no public address was set. This sets the static random address.
The error does not occur if I only enable CONFIG_BT_CENTRAL or CONFIG_BT_PERIPHERAL. The error also does not occur in version 2.0.2 or 2.1.3 of the nRF Connect SDK, but does occur in 2.2.0 and 2.2.99-dev3.