Skip to content

Commit

Permalink
Merge pull request #9 from yn/master
Browse files Browse the repository at this point in the history
Generate unique serial codes for the USB device from the ST32 UUID
  • Loading branch information
Eric Evenchick committed Mar 14, 2017
2 parents 0edc30e + 521a44d commit 78a5896
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions Src/usbd_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,26 @@ uint8_t * USBD_FS_ManufacturerStrDescriptor( USBD_SpeedTypeDef speed , uint16_t
return USBD_StrDesc;
}

#define STM32_UUID ((uint32_t *)0x1FFFF7AC)
static void IntToAscii (uint32_t value , uint8_t *pbuf , uint8_t len)
{
uint8_t idx = 0;

for( idx = 0 ; idx < len ; idx ++)
{
if( ((value >> 28)) < 0xA )
{
pbuf[ idx ] = (value >> 28) + '0';
}
else
{
pbuf[ idx ] = (value >> 28) + 'A' - 10;
}

value = value << 4;
pbuf[ idx + 1] = 0;
}
}
/**
* @brief USBD_FS_SerialStrDescriptor
* return the serial number string descriptor
Expand All @@ -237,14 +257,11 @@ uint8_t * USBD_FS_ManufacturerStrDescriptor( USBD_SpeedTypeDef speed , uint16_t
*/
uint8_t * USBD_FS_SerialStrDescriptor( USBD_SpeedTypeDef speed , uint16_t *length)
{
if(speed == USBD_SPEED_HIGH)
{
USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
}
else
{
USBD_GetString (USBD_SERIALNUMBER_STRING_FS, USBD_StrDesc, length);
}
uint8_t s[0x100];
IntToAscii(STM32_UUID[0], &s[0], 8);
IntToAscii(STM32_UUID[1], &s[8], 8);
IntToAscii(STM32_UUID[2], &s[16], 8);
USBD_GetString (s, USBD_StrDesc, length);
return USBD_StrDesc;
}

Expand Down

0 comments on commit 78a5896

Please sign in to comment.