Unique Device ID Module
This module provides access to the STM32 microcontroller's 96-bit unique identifier. Each STM32 chip has a unique ID programmed during manufacturing, useful for:
- Device identification and registration
- License/authentication systems
- Generating unique serial numbers
- Hardware-based encryption keys
Key Features:
- Read 96-bit unique ID as three 32-bit words
- Convert to hexadecimal string representation
- Guaranteed unique per chip (factory programmed)
- Read-only hardware register (cannot be modified)
Usage Example:
import nimphea_uniqueid # Get unique ID as three 32-bit values var uid = getUniqueId() echo "Device ID: ", uid.w0.toHex(8), "-", uid.w1.toHex(8), "-", uid.w2.toHex(8) # Get as formatted hex string let serialNumber = getUniqueIdString() echo "Serial: ", serialNumber # e.g. "1A2B3C4D-5E6F7890-ABCDEF01"
Technical Details:
- Unique ID is stored in read-only memory at factory
- Location: STM32H7 UID base address (0x1FF1E800)
- Format: 96 bits = 3 x 32-bit words
- Guaranteed unique across all STM32 devices
Procs
proc `$`(uid: UniqueId): string {....raises: [], tags: [], forbids: [].}
-
Convert UniqueId to string representation.
Parameters:
- uid: The UniqueId object
Returns: String in format "UniqueId(0xXXXXXXXX-0xXXXXXXXX-0xXXXXXXXX)"
Example:
let uid = getUniqueId() echo uid # UniqueId(0x1A2B3C4D-0x5E6F7890-0xABCDEF01)
Source Edit proc `==`(a, b: UniqueId): bool {.inline, ...raises: [], tags: [], forbids: [].}
-
Compare two UniqueId objects for equality.
Parameters:
- a: First UniqueId
- b: Second UniqueId
Returns: true if all three words match, false otherwise
Example:
let uid1 = getUniqueId() let uid2 = getUniqueId() assert uid1 == uid2 # Same device always returns same ID
Source Edit proc getUniqueId(): UniqueId {....raises: [], tags: [], forbids: [].}
-
Read the 96-bit unique ID from the microcontroller.
Returns: UniqueId object containing three 32-bit words
Example:
let uid = getUniqueId() echo "Word 0: 0x", uid.w0.toHex(8) echo "Word 1: 0x", uid.w1.toHex(8) echo "Word 2: 0x", uid.w2.toHex(8)
Source Edit proc getUniqueIdString(): string {....raises: [], tags: [], forbids: [].}
-
Read the unique ID and format as hyphen-separated hex string.
Returns: String in format "XXXXXXXX-XXXXXXXX-XXXXXXXX" (24 hex digits + 2 hyphens)
Example:
let serial = getUniqueIdString() echo "Device Serial Number: ", serial # Output: Device Serial Number: 1A2B3C4D-5E6F7890-ABCDEF01
Source Edit