2023-12-11 03:24 AM - edited 2023-12-11 06:03 AM
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.
Solved! Go to Solution.
2024-01-22 02:06 AM
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
2023-12-15 03:01 AM
Hi, is there any progress on this question?
2024-01-22 02:06 AM
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