2019-05-27 03:05 AM
Dear CubeMX developers!
I would like to suggest you to add an user code section around the function body of the Get_SerialNum in the usbd_desc.c file generated with the CubeMX for the STM32F1 family:
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);
}
}
As seen in the snipplet above the current implementation puts the die ID to the serial number.
I think it is widespread to program an own unique serial number to the device at the manufacturing stage. In this case the user needs to override this function which got overwritten each time when the CubeMX generates code. Introducing a new user section here would solve this use case. Example snipplet (after adding custom serial number:)
static void Get_SerialNum(void)
{
/* USER CODE BEGIN Get_SerialNum */
uint16_t length;
USBD_GetString((uint8_t *)serialNumberStr, USBD_StringSerial, &length);
/* USER CODE END Get_SerialNum */
}
Thanks in advance!
2019-05-27 05:18 AM
Hello @martonmiklos ,
This is reported internally for further check.
Best Regards,
Khouloud.
2019-05-27 05:21 AM
Cool, thanks!
2020-03-31 08:02 AM
I just seen that there is an USBD_FS_SerialStrDescriptor section there, so I consider this issue partially solved. For the shake of optimalization I would suggest to move the Get_SerialNum(); call to the user section. In this case if the end user wants to use their own serial number (which is not dependant on the device's ID) could easily replace it and it won't consume program memory.