cancel
Showing results for 
Search instead for 
Did you mean: 

CUBE MX usbd_dec.c unique Serial Number

Egemen
Associate II

Hi,

I am using STM32G491 for the project. For USB HID class the Cube MX generates usbd_dec.c file. In this file, there is a Get_SerialNum function

static void Get_SerialNum(void)

{

  uint32_t deviceserial0, deviceserial1, deviceserial2;

 

  deviceserial0 = *(uint32_t *) DEVICE_ID1;

  deviceserial1 = *(uint32_t *) DEVICE_ID2;

  deviceserial2 = *(uint32_t *) DEVICE_ID3;

 

  deviceserial0 += deviceserial2;

 

  if (deviceserial0 != 0)

  {

    IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8);

    IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4);

  }

}

so, is this code shall generates %100 unique serial numbers for every product?

If it is not is there any alternative that shall generate a unique serial number?

Best regards.

1 ACCEPTED SOLUTION

Accepted Solutions
Alan PORTE
ST Employee

Hi Egemen,

Let me share here the answer I provided to you last month through our direct OLS support platform.

First of all, if you look into the usbd_desc.h you will see that DEVICE_IDx is defined with UID_BASE value.
The UID (Unique Device Identifier) is composed of:
- X and Y coordinates on the wafer
- Lot number
- Wafer number

Thus, yes the UID is unique for each device.
Moreover, the UID bits cannot be altered by the user.
More information can be found in the Reference Manual RM0440 (section 48 - rev7):
https://www.st.com/resource/en/reference_manual/rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf#page=2108

 

However, as you mentioned, function Get_SerialNum() will not give you a unique Serial Number.
In fact, it is up to you to modify this section if you want to implement your own unique ID, based on the UID or not.
Because, ST can only guarantee the unicity of the UID. As soon as UID is modified/shortened, then we cannot guarantee anymore that the result will be unique.

Since we need to respect a specific size for the USB Serial Number, that's why we proposed by default this solution with the sum operation.

You can use the "USER CODE" section located in the function USBD_HID_SerialStrDescriptor() in order to implement your own code.

 

Best Regards,
Alan Porte
ST MCU Support Team

View solution in original post

2 REPLIES 2
Egemen
Associate II

Hi, is there any progress on this question?

Alan PORTE
ST Employee

Hi Egemen,

Let me share here the answer I provided to you last month through our direct OLS support platform.

First of all, if you look into the usbd_desc.h you will see that DEVICE_IDx is defined with UID_BASE value.
The UID (Unique Device Identifier) is composed of:
- X and Y coordinates on the wafer
- Lot number
- Wafer number

Thus, yes the UID is unique for each device.
Moreover, the UID bits cannot be altered by the user.
More information can be found in the Reference Manual RM0440 (section 48 - rev7):
https://www.st.com/resource/en/reference_manual/rm0440-stm32g4-series-advanced-armbased-32bit-mcus-stmicroelectronics.pdf#page=2108

 

However, as you mentioned, function Get_SerialNum() will not give you a unique Serial Number.
In fact, it is up to you to modify this section if you want to implement your own unique ID, based on the UID or not.
Because, ST can only guarantee the unicity of the UID. As soon as UID is modified/shortened, then we cannot guarantee anymore that the result will be unique.

Since we need to respect a specific size for the USB Serial Number, that's why we proposed by default this solution with the sum operation.

You can use the "USER CODE" section located in the function USBD_HID_SerialStrDescriptor() in order to implement your own code.

 

Best Regards,
Alan Porte
ST MCU Support Team