Skip to content

Commit fb1cab4

Browse files
committed
Fixing 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**.
1 parent 5ff5414 commit fb1cab4

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎libraries/USBDevice/inc/usbd_desc.h‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,18 @@
2828
/* Exported constants --------------------------------------------------------*/
2929
#define DEVICE_ID1 (UID_BASE)
3030
#define DEVICE_ID2 (UID_BASE + 0x4U)
31-
#define DEVICE_ID3 (UID_BASE + 0x8U)
31+
/*
32+
* On STM32L0 and STM32L1 the three unique-ID words are NOT contiguous:
33+
* the reference manuals place bits 95:64 at offset 0x14, not 0x08
34+
* (RM0376/RM0377/RM0367/RM0451 "Unique device ID registers (96 bits)",
35+
* and RM0038 for STM32L1). UID_BASE + 0x8U is a reserved location there.
36+
* ST's own HAL_GetUIDw2() already uses 0x14U for these two families.
37+
*/
38+
#if defined(STM32L0xx) || defined(STM32L1xx)
39+
#define DEVICE_ID3 (UID_BASE + 0x14U)
40+
#else
41+
#define DEVICE_ID3 (UID_BASE + 0x8U)
42+
#endif
3243

3344
/*
3445
* USB Billboard Class USER string desc Defines Template

0 commit comments

Comments
 (0)