generate the serial number same as DFU
This commit is contained in:
parent
de31924be3
commit
991530f88b
@ -166,28 +166,29 @@ uint8_t *USBD_HID_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *l
|
|||||||
*/
|
*/
|
||||||
uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
uint8_t *USBD_HID_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||||
{
|
{
|
||||||
|
// Match the same alg as the DFU to make serial number
|
||||||
volatile uint8_t * UUID = (volatile uint8_t *)0x1FFF7590;
|
volatile uint8_t * UUID = (volatile uint8_t *)0x1FFF7590;
|
||||||
uint8_t uuid[12];
|
const char hexdigit[] = "0123456789ABCDEF";
|
||||||
uint8_t uuid_str[25];
|
uint8_t uuid[6];
|
||||||
char c;
|
uint8_t uuid_str[13];
|
||||||
|
uint8_t c;
|
||||||
int i;
|
int i;
|
||||||
uuid_str[24] = 0;
|
uuid_str[12] = 0;
|
||||||
memmove(uuid,(uint8_t *)UUID,12);
|
|
||||||
|
uuid[0] = UUID[11];
|
||||||
|
uuid[1] = UUID[10] + UUID[2];
|
||||||
|
uuid[2] = UUID[9];
|
||||||
|
uuid[3] = UUID[8] + UUID[0];
|
||||||
|
uuid[4] = UUID[7];
|
||||||
|
uuid[5] = UUID[6];
|
||||||
|
|
||||||
// quick method to convert to hex string
|
// quick method to convert to hex string
|
||||||
for (i = 0; i < 12; i++)
|
for (i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
c = uuid[i] & 0x0f;
|
c = (uuid[i]>>4) & 0x0f;
|
||||||
if (c < 0x0a)
|
uuid_str[i * 2 + 0] = hexdigit[ c ];
|
||||||
uuid_str[i * 2 + 1] = c + '0';
|
c = (uuid[i]>>0) & 0x0f;
|
||||||
else
|
uuid_str[i * 2 + 1] = hexdigit[ c ];
|
||||||
uuid_str[i * 2 + 1] = c + 'A' - 0x0a;
|
|
||||||
|
|
||||||
c = (uuid[i] & 0xf0) >> 4;
|
|
||||||
if (c < 0x0a)
|
|
||||||
uuid_str[i * 2] = c + '0';
|
|
||||||
else
|
|
||||||
uuid_str[i * 2] = c + 'A' - 0x0a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user