how to set USB serialnumber as the ble mac address

Hi,

    my product now is base on the nrf5340,  I want to set the USB's serialnumber same as the ble mac address.

    when I use the nrf52840,  I can set it as follows simply.

    

int32_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
{
    uint16_t serial_num_high_bytes = sys_cpu_to_be16(((NRF_FICR->  DEVICEADDR[1]) & 0xffff) | 0xC000);
    uint32_t serial_num_low_bytes  = sys_cpu_to_be32(NRF_FICR->DEVICEADDR[0]);

    memcpy(buffer, (uint8_t *)&serial_num_high_bytes, 2);
    memcpy(buffer + 2, (uint8_t *)&serial_num_low_bytes, 4);
    return 6;
}

    I found the DEVCIEADDR in the network core,  but it is not accessible from the application core. 

    is there another way to set the USB serialnumber dynamically?

Parents
  • Hi,

    I apologize for the late response.

    You can get the DEVICEADDR on the application core by including hci_vs.h:

    #include <bluetooth/hci_vs.h>

    Then use a hci command to read the static addresses:

    struct net_buf * rsp;
    err = bt_hci_cmd_send_sync(BT_HCI_OP_VS_READ_STATIC_ADDRS, NULL, &rsp);
    if (err) {
    	printk("Failed to read DEVICEADDR Err: %d\n", err);
    }

    Let me know if you have any issues.

  • Hi,

    thanks for your reply. I have try it, but the bt_hci_cmd_send_sync() command can't work.

    I guess that because the z_impl_hwinfo_get_device_id() function is called in the usb_device_init()  which running in the system init

    SYS_INIT(usb_device_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);

    and the bt_hci_cmd_send_sync() maybe work after bt_enable().

    I've used a not good way to solve this problem,

    that is using  flash to store the special information after bt_enable()  and reset the MCU. then  z_impl_hwinfo_get_device_id() can read the information from the special flash page.

    maybe, is there a better way?

  • That sounds like a perfectly viable way to handle it. I asked a colleague as well, and neither of us can immediately see any issue with your approach.

Reply Children
Related