Microchip® Advanced Software Framework

USB Dynamic Serial Number

In this use case, the USB serial strings are dynamic.

For a static serial string refer to Use USB Strings.

Setup Steps

Prior to implement this use case, be sure to have already applied 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 string 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 starting 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';
    }