1Configure device address 2------------------------ 3 4A BLE device needs an address to do just about anything. For information 5on the various types of Bluetooth addresses, see the `NimBLE Host 6Identity Reference :doc:`<../ble_hs/ble_hs_id/ble_hs_id>`. 7 8There are several methods for assigning an address to a NimBLE device. 9The available options are documented below: 10 11Method 1: Configure nRF hardware with a public address 12~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13 14When Mynewt is running on a Nordic nRF platform, the NimBLE controller 15will attempt to read a public address out of the board's FICR or UICR 16registers. The controller uses the following logic while trying to read 17an address from hardware: 18 191. If the *DEVICEADDRTYPE* FICR register is written, read the address 20 programmed in the *DEVICEADDR[0]* and *DEVICEADDR[1]* FICR registers. 212. Else if the upper 16 bits of the *CUSTOMER[1]* UICR register are 0, 22 read the address programmed in the *CUSTOMER[0]* and *CUSTOMER[1]* 23 UCI registers. 243. Else, no address available. 25 26Method 2: Hardcode a public address in the Mynewt target 27~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 28 29The NimBLE controller package exports a 30:doc:`syscfg <../../../os/modules/sysinitconfig/sysinitconfig>` setting 31called ``BLE_PUBLIC_DEV_ADDR``. This setting can be overridden at the 32application or target level to configure a public Bluetooth address. For 33example, a target can assign the public address *11:22:33:44:55:66* as 34follows: 35 36:: 37 38 syscfg.vals: 39 BLE_PUBLIC_DEV_ADDR: '(uint8_t[6]){0x66, 0x55, 0x44, 0x33, 0x22, 0x11}' 40 41This setting takes the form of a C expression. Specifically, the value 42is a designated initializer expressing a six-byte array. Also note that 43the bytes are reversed, as an array is inherently little-endian, while 44addresses are generally expressed in big-endian. 45 46Note: this method takes precedence over method 1. Whatever is written to 47the ``BLE_PUBLIC_DEV_ADDR`` setting is the address that gets used. 48 49Method 3: Configure a random address at runtime 50~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 51 52Random addresses get configured through the NimBLE host. The following 53two functions are used in random address configuration: 54 55- :doc:`ble_hs_id_gen_rnd <../ble_hs/ble_hs_id/functions/ble_hs_id_gen_rnd>`: 56 Generates a new random address. 57- :doc:`ble_hs_id_set_rnd <../ble_hs/ble_hs_id/functions/ble_hs_id_set_rnd>`: 58 Sets the device's random address. 59 60For an example of how this is done, see the :doc:`<../../../os/tutorials/ibeacon>`. 61 62*Note:* A NimBLE device can be configured with multiple addresses; at 63most one of each address type. 64