ble_addr.rst 2.6 KB

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