Skip to content

Commit 54b6389

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 3e413aa commit 54b6389

2 files changed

Lines changed: 5 additions & 11 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: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#include "usbd_desc.h"
2323
#include "utils.h"
2424
#include <variant.h>
25-
25+
#include "stm32yyxx_ll_utils.h"
26+
#include "stm32yyxx_ll_system.h"
2627
/* Private typedef -----------------------------------------------------------*/
2728
/* Private define ------------------------------------------------------------*/
2829

@@ -444,13 +445,9 @@ uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *le
444445
*/
445446
static void Get_SerialNum(void)
446447
{
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;
448+
uint32_t deviceserial0 = LL_GetUID_Word0();
449+
uint32_t deviceserial1 = LL_GetUID_Word1();
450+
uint32_t deviceserial2 = LL_GetUID_Word2();
454451

455452
deviceserial0 += deviceserial2;
456453

0 commit comments

Comments
 (0)