In this article, we’ll discuss the STM32 unique ID (UID) which is a unique 96-bit value assigned to each STM32 microcontroller IC, how to read this UID value, and what are the possible applications and use cases for the STM32 UID. Without further ado, let’s get right into it!
Table of Contents
STM32 Unique ID UID (96-Bit)
What is The STM32 Unique ID?
STM32 microcontrollers have an embedded hard-coded unique identifier (UID), a unique 96-bit number assigned to each microcontroller IC during fabrication time. The 96-bit unique ID is a combination of the following fabrication-specific parameters:
- UID[31:0]: X & Y coordinates on the wafer expressed in BCD format
- UID[63:40]: LOT_NUM[23:0] Lot number (ASCII encoded)
- UID[39:32]: WAF_NUM[7:0] Wafer number (8-bit unsigned number)
- UID[95:64]: LOT_NUM[55:24] Lot number (ASCII encoded)
Applications of The STM32 UID
The UID number can be used in various embedded security applications, networking/IoT, as a serial number, or as a key for security applications.
How To Read STM32 Unique ID UID (96-Bit)
There is an API function in the HAL library that reads the UID for you. Given that the STM32 UID is a 96-bit value, it’s going to be read in 3 separate 32-bit words. And here is how to do it in code.
1 2 3 4 5 |
uint32_t UID[3]; UID[0] = HAL_GetUIDw0(); UID[1] = HAL_GetUIDw1(); UID[2] = HAL_GetUIDw2(); |
And here is the debugging result showing the 3-word content of the UID of my blue pill’s STM32F103 microcontroller.
Not all STM32 microcontrollers have a UID fused on the flash memory. While other STM23 parts have the UID base address in an MPU-protected region in the flash causing read attempts to fire a hard fault. So you should seek help or ask an ST staff if you’re not able to read the UID using the provided code example in this article.
Required Parts For STM32 Examples
All the example Code/LABs/Projects in this STM32 Series of Tutorials are done using the Dev boards & Electronic Parts Below:
QTY. | Component Name | Amazon.com | AliExpress | eBay |
1 | STM32-F103 BluePill Board (ARM Cortex-M3 @ 72MHz) | Amazon | AliExpress | eBay |
1 | Nucleo-L432KC (ARM Cortex-M4 @ 80MHz) | Amazon | AliExpress | eBay |
1 | ST-Link V2 Debugger | Amazon | AliExpress | eBay |
2 | BreadBoard | Amazon | AliExpress | eBay |
1 | LEDs Kit | Amazon & Amazon | AliExpress | eBay |
1 | Resistors Kit | Amazon & Amazon | AliExpress | eBay |
1 | Capacitors Kit | Amazon & Amazon | AliExpress & AliExpress | eBay & eBay |
1 | Jumper Wires Pack | Amazon & Amazon | AliExpress & AliExpress | eBay & eBay |
1 | Push Buttons | Amazon & Amazon | AliExpress | eBay |
1 | Potentiometers | Amazon | AliExpress | eBay |
1 | Micro USB Cable | Amazon | AliExpress | eBay |
★ Check The Links Below For The Full Course Kit List & LAB Test Equipment Required For Debugging ★
Wrap Up
In conclusion, we’ve explored how to read the STM32 unique ID (UID) 96-bit value and what are the possible use cases (applications) for this UID value.
If you’re just getting started with STM32, you need to check out the STM32 Getting Started Tutorial here.
Follow this STM32 Series of Tutorials to learn more about STM32 Microcontrollers Programming.