USB dynamic serial number

In this use case, the USB serial strings is dynamic. For a static serial string refer to Use USB strings.

Setup steps

Prior to implement this use case, be sure to have already apply the UDI module "basic use case".

Usage steps

Example code

Content of conf_usb.h:

#define USB_DEVICE_SERIAL_NAME
#define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number
#define USB_DEVICE_GET_SERIAL_NAME_LENGTH 12
extern uint8_t serial_number[];

Add to application C-file:

uint8_t serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH];
void init_build_usb_serial_number(void)
{
serial_number[0] = 'A';
serial_number[1] = 'B';
...
serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH-1] = 'C';
}

Workflow

  1. Ensure that conf_usb.h is available and contains the following parameters required to enable a USB serial number strings dynamically:
    • #define USB_DEVICE_SERIAL_NAME // Define this empty
      #define USB_DEVICE_GET_SERIAL_NAME_POINTER serial_number // Give serial array pointer
      #define USB_DEVICE_GET_SERIAL_NAME_LENGTH 12 // Give size of serial array
      extern uint8_t serial_number[]; // Declare external serial array
  2. Before start USB stack, initialize the serial array
    • uint8_t serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH];
      void init_build_usb_serial_number(void)
      {
      serial_number[0] = 'A';
      serial_number[1] = 'B';
      ...
      serial_number[USB_DEVICE_GET_SERIAL_NAME_LENGTH-1] = 'C';
      }


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:18:00