Skip to content

Commit 46f019b

Browse files
acseka360fpistm
authored andcommitted
fix(usb): unique id DEVICE_ID3 on STM32L0 and STM32L1
On STM32L0 and STM32L1, `DEVICE_ID3` points at a reserved memory location instead of the third word of the 96-bit unique device ID. The USB serial number string is therefore derived from only 64 bits of the ID plus a constant, and **devices from the same production lot and wafer enumerate with byte-identical USB serial numbers**. Signed-off-by: aron.cserkaszky <aron.cserkaszky@360.world>
1 parent 5ff5414 commit 46f019b

2 files changed

Lines changed: 3 additions & 10 deletions

File tree

‎libraries/USBDevice/inc/usbd_desc.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626

2727
/* Exported types ------------------------------------------------------------*/
2828
/* Exported constants --------------------------------------------------------*/
29-
#define DEVICE_ID1 (UID_BASE)
30-
#define DEVICE_ID2 (UID_BASE + 0x4U)
31-
#define DEVICE_ID3 (UID_BASE + 0x8U)
3229

3330
/*
3431
* USB Billboard Class USER string desc Defines Template

‎libraries/USBDevice/src/usbd_desc.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,9 @@ uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *le
444444
*/
445445
static void Get_SerialNum(void)
446446
{
447-
uint32_t deviceserial0;
448-
uint32_t deviceserial1;
449-
uint32_t deviceserial2;
450-
451-
deviceserial0 = *(uint32_t *)DEVICE_ID1;
452-
deviceserial1 = *(uint32_t *)DEVICE_ID2;
453-
deviceserial2 = *(uint32_t *)DEVICE_ID3;
447+
uint32_t deviceserial0 = LL_GetUID_Word0();
448+
uint32_t deviceserial1 = LL_GetUID_Word1();
449+
uint32_t deviceserial2 = LL_GetUID_Word2();
454450

455451
deviceserial0 += deviceserial2;
456452

0 commit comments

Comments
 (0)