From fb1cab46ae9b4d46055cbd2d9628cff5996c2c6d Mon Sep 17 00:00:00 2001 From: "aron.cserkaszky" Date: Thu, 17 Sep 2026 19:14:27 +0200 Subject: [PATCH] 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**. --- libraries/USBDevice/inc/usbd_desc.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libraries/USBDevice/inc/usbd_desc.h b/libraries/USBDevice/inc/usbd_desc.h index aa832b2772..a1b84608fb 100644 --- a/libraries/USBDevice/inc/usbd_desc.h +++ b/libraries/USBDevice/inc/usbd_desc.h @@ -28,7 +28,18 @@ /* Exported constants --------------------------------------------------------*/ #define DEVICE_ID1 (UID_BASE) #define DEVICE_ID2 (UID_BASE + 0x4U) - #define DEVICE_ID3 (UID_BASE + 0x8U) + /* + * On STM32L0 and STM32L1 the three unique-ID words are NOT contiguous: + * the reference manuals place bits 95:64 at offset 0x14, not 0x08 + * (RM0376/RM0377/RM0367/RM0451 "Unique device ID registers (96 bits)", + * and RM0038 for STM32L1). UID_BASE + 0x8U is a reserved location there. + * ST's own HAL_GetUIDw2() already uses 0x14U for these two families. + */ + #if defined(STM32L0xx) || defined(STM32L1xx) + #define DEVICE_ID3 (UID_BASE + 0x14U) + #else + #define DEVICE_ID3 (UID_BASE + 0x8U) + #endif /* * USB Billboard Class USER string desc Defines Template