USB Serial number

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB Serial number

1,116 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Muis on Tue Jan 22 13:05:53 MST 2013
In the current release of NXPUSBlib (0.98) the device returns no USB serial number to the host. This can be annoying because Windows tries to generate an unique serial number based on PID/VID/Port, and will show the 'new device' message every time you plug it into a different port. For devices like Virtual Serial ports this is even more annoying because a different comm-port number get assigned every time.

Could the next release of NXPUSBlib read the UUID of the uC via IAP and place it in the descriptor?

Labels (1)
0 Kudos
Reply
1 Reply

1,029 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by danhauck on Fri Mar 15 02:17:08 MST 2013
Ive solved it

you only have to add the index (in my case 0x04) in the usb descriptor and add the following code in CALLBACK_USB_GetDescriptor

switch (DescriptorNumber)...
case 0x04:
Address = SerialNoStringPtr;
Size    = pgm_read_byte(&SerialNoStringPtr->Header.Size);

then you have to add the string

uint8_t SerialNoString[] =
{
  USB_STRING_LEN(12),
  DTYPE_String,
  WBVAL('U'),
  WBVAL('C'),
  WBVAL('R'),
  WBVAL('0'),
  WBVAL('0'),
  WBVAL('0'),
  WBVAL('0'),
  WBVAL('0'),
  WBVAL('0'),
  WBVAL('0'),
  WBVAL('0'),
  WBVAL('0'),
};
USB_Descriptor_String_t *SerialNoStringPtr = (USB_Descriptor_String_t*)SerialNoString;

and then you have to add and call a init function (in my case USB_DescriptorInit) which reads the UID

void DescriptorInit(void){
unsigned int *pd = IO_IAP_GetDeviceUID();       // Eindeutige einmalige ID des Prozessors laden
unsigned int p = pd[0]^pd[1]^pd[2]^pd[3];       // 128bit sind mir zuviel ich mach 32bit draus
char b[8];
mysprintf(b,"%08x",p);                  // In String wandeln
// In den Deskriptor laden
SerialNoString[10] = b[0];     
SerialNoString[12] = b[1];     
SerialNoString[14] = b[2];    
SerialNoString[16] = b[3];    
SerialNoString[18] = b[4];    
SerialNoString[20] = b[5];     
SerialNoString[22] = b[6];     
SerialNoString[24] = b[7];
}

The IO_IAP_GetDeviceUID-function you can find in the attachment

regards

daniel
0 Kudos
Reply