From 6f8f4725c7c94a86fa7bfcc1f2798f6c9c8f901b Mon Sep 17 00:00:00 2001 From: "aron.cserkaszky" Date: Thu, 17 Sep 2026 19:14:27 +0200 Subject: [PATCH] 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 --- libraries/USBDevice/inc/usbd_desc.h | 3 --- libraries/USBDevice/src/usbd_desc.c | 13 +++++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/libraries/USBDevice/inc/usbd_desc.h b/libraries/USBDevice/inc/usbd_desc.h index aa832b2772..56e3b7aefc 100644 --- a/libraries/USBDevice/inc/usbd_desc.h +++ b/libraries/USBDevice/inc/usbd_desc.h @@ -26,9 +26,6 @@ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ - #define DEVICE_ID1 (UID_BASE) - #define DEVICE_ID2 (UID_BASE + 0x4U) - #define DEVICE_ID3 (UID_BASE + 0x8U) /* * USB Billboard Class USER string desc Defines Template diff --git a/libraries/USBDevice/src/usbd_desc.c b/libraries/USBDevice/src/usbd_desc.c index 942f6c5475..b22655f6f5 100644 --- a/libraries/USBDevice/src/usbd_desc.c +++ b/libraries/USBDevice/src/usbd_desc.c @@ -22,7 +22,8 @@ #include "usbd_desc.h" #include "utils.h" #include - +#include "stm32yyxx_ll_utils.h" +#include "stm32yyxx_ll_system.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ @@ -444,13 +445,9 @@ uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *le */ static void Get_SerialNum(void) { - uint32_t deviceserial0; - uint32_t deviceserial1; - uint32_t deviceserial2; - - deviceserial0 = *(uint32_t *)DEVICE_ID1; - deviceserial1 = *(uint32_t *)DEVICE_ID2; - deviceserial2 = *(uint32_t *)DEVICE_ID3; + uint32_t deviceserial0 = LL_GetUID_Word0(); + uint32_t deviceserial1 = LL_GetUID_Word1(); + uint32_t deviceserial2 = LL_GetUID_Word2(); deviceserial0 += deviceserial2;