nRF5340 - custom USB SerialNumber

Hi,
running the USB hid sample project and sending from host terminal
$ journalctl -k -n 10
I get
[ 2231.751311] usb 1-1.3: SerialNumber: D0766E074450A9F0

I want to change the exposed SerialNumber to "2022070001"
How to do that ?
Looking around somewhere I've found a reference to NRF_FICR->DEVICEADDR[1:0].
Unfortunately, attempting to read this variable gets the compiler complaining NRF_FICR_Type has no member named DEVICEADDR.

What's the solution ?

Parents
  • Yes I did.

    If I do not use CONFIG_USB_DEVICE_SN then I get
    [ 2231.751311] usb 1-1.3: SerialNumber: D0766E074450A9F0

    If I use CONFIG_USB_DEVICE_SN="2022070001" then I get
    [ 2231.751311] usb 1-1.3: SerialNumber: 074450A9F0

    The displayed string is the same, only it is truncated to the lenght of CONFIG_USB_DEVICE_SN

  • Looks like this only allocate a placeholder for the serial number string yes.

    I don't see a way around this without modifying usb_descriptor.c in some way, you can either manipulate directly usb_fix_ascii_sn_string_descriptor(), but it may also look like the implementation of usb_update_sn_string_descriptor() is weak, which should mean that if you write a new usb_update_sn_string_descriptor() somewhere in your project that is included by include files at top of usb_descriptor.c/h, then it will fetch the serial number from there (instead of the default weak implementation you can find of usb_update_sn_string_descriptor() in usb_descriptor.c)

    I can find that for instance the \connectivity_bridge\src\main.c does this by:

    /* Overriding weak function to set iSerialNumber at runtime. */
    uint8_t *usb_update_sn_string_descriptor(void)
    {
        snprintk(usb_serial_str, sizeof(usb_serial_str), USB_SERIALNUMBER_TEMPLATE,
                    (uint32_t)(NRF_FICR->DEVICEADDR[1] & 0x0000FFFF)|0x0000C000,
                    (uint32_t)NRF_FICR->DEVICEADDR[0]);

        return usb_serial_str;
    }

    Best regards,
    Kenneth

Reply
  • Looks like this only allocate a placeholder for the serial number string yes.

    I don't see a way around this without modifying usb_descriptor.c in some way, you can either manipulate directly usb_fix_ascii_sn_string_descriptor(), but it may also look like the implementation of usb_update_sn_string_descriptor() is weak, which should mean that if you write a new usb_update_sn_string_descriptor() somewhere in your project that is included by include files at top of usb_descriptor.c/h, then it will fetch the serial number from there (instead of the default weak implementation you can find of usb_update_sn_string_descriptor() in usb_descriptor.c)

    I can find that for instance the \connectivity_bridge\src\main.c does this by:

    /* Overriding weak function to set iSerialNumber at runtime. */
    uint8_t *usb_update_sn_string_descriptor(void)
    {
        snprintk(usb_serial_str, sizeof(usb_serial_str), USB_SERIALNUMBER_TEMPLATE,
                    (uint32_t)(NRF_FICR->DEVICEADDR[1] & 0x0000FFFF)|0x0000C000,
                    (uint32_t)NRF_FICR->DEVICEADDR[0]);

        return usb_serial_str;
    }

    Best regards,
    Kenneth

Children
Related