STM32CubeMX USB Serial Number String from UID
Hello,
I have a device based on STM32F1 series that's using the USB CDC interface. TrueSTUDIO project is generated with STM32CubeMX. Everything is working fine except one last thing: Setting the serial number string from code. I can set the serial number string from STM32CubeMX or by overriding the define in Code
#define USBD_SERIALNUMBER_STRING_FS '00000000001A'�?
But I need the string to be unique per device, so using the MCU UID to generate an unique number would be the best solution. Generated parts are:
[...]
USBD_DescriptorsTypeDef FS_Desc =
{
USBD_FS_DeviceDescriptor
, USBD_FS_LangIDStrDescriptor
, USBD_FS_ManufacturerStrDescriptor
, USBD_FS_ProductStrDescriptor
, USBD_FS_SerialStrDescriptor
, USBD_FS_ConfigStrDescriptor
, USBD_FS_InterfaceStrDescriptor
};
[...]
uint8_t * USBD_FS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
{
if(speed == USBD_SPEED_HIGH)
{
USBD_GetString((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
}
else
{
USBD_GetString((uint8_t *)USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
}
return USBD_StrDesc;
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
[...]�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
I see no way to insert user code into theUSBD_FS_SerialStrDescriptor function, since there is no USER CODE field. What is the
STM32CubeMX
way to use a serial number from the UID? Am I missing something here? #usb-cdc #usb-device #stm32cubemx