Overview of Core Differences
| Feature | PDID (Part Device ID) | CPUID (Core Peripheral ID) | UID (Unique ID) |
|---|---|---|---|
| Chinese Name | Device Model Identifier | Processor Core Identifier | Unique Device Identifier |
| Function | Distinguishes theproduct model and version | Identifies theCPU core‘s architecture, version, and features | Differentiateseach physical chip under the same model |
| Uniqueness | Not Unique: The values are identical for the same model MCUs | Not Unique: The values are identical for the same core MCUs | Unique: Every chip globally is different |
| Content | Manufacturer-defined model code, memory size, package, version number, etc. | Architecture information defined by core manufacturers (e.g., Cortex-M4), version number, implementer | A string of random or serialized numbers programmed by the manufacturer |
| Query Method | Read frommanufacturer-defined memory-mapped registers | Read through ARM’s <span>CPUID</span> system register (e.g., MRS instruction) |
Read frommanufacturer-defined memory-mapped registers |
| Main Uses | 1. Software compatibility across different model chips2. Confirm chip model and version | 1. Compiler/OS adaptation to CPU features2. Debugging tools identify the core | 1. Encryption key generation2. Device identity authentication3. Generate serial numbers |
Detailed Explanation and Code Examples
1. UID (Unique ID / Unique Device ID)
- What is it: Aglobally unique identifier programmed into the chip by the manufacturer during production. It is similar to the chip’s “ID number” or “MAC address of a network card.”
- Significance: Used to distinguish physically different chips, even if they come from the same wafer and model.
- Typical Application Scenarios:
- Encryption: Used as a seed for encryption algorithms to generate device-specific keys.
- Secure Boot: Tied to software to ensure firmware runs only on this device.
- Device Authentication: In IoT, servers use UID to identify and authenticate device identity.
- Generate Serial Numbers: Serves as the basis for product serial numbers.
Example: UID in STM32 In STM32, the UID is typically a 96-bit (12-byte) number stored at three fixed memory addresses. Different series may have different addresses, so refer to the datasheet.
// Read UID of STM32F4 (reference address, please refer to specific chip manual)
#define UID_BASE 0x1FFF7A10U
void get_stm32_uid(uint32_t *uid) {
uid[0] = *(volatile uint32_t*)(UID_BASE);
uid[1] = *(volatile uint32_t*)(UID_BASE + 4);
uid[2] = *(volatile uint32_t*)(UID_BASE + 8);
}
int main() {
uint32_t my_uid[3];
get_stm32_uid(my_uid);
// Now my_uid[0], [1], [2] contains the globally unique 96-bit ID of this chip
printf("UID: %08X-%08X-%08X\n", my_uid[0], my_uid[1], my_uid[2]);
return 0;
}
2. CPUID (Core Peripheral ID)
- What is it: This is astandard feature provided by the ARM Cortex-M series core, which is acore-level register. It is used to identify information about the CPU core itself, independent of specific chip manufacturers (e.g., ST, NXP).
- Significance: Allows software (such as compilers, operating systems, debuggers) to automatically recognize the CPU’s core architecture, version, and supported features (e.g., whether it has FPU, MPU, etc.), enabling corresponding optimizations and configurations.
- Content: Includes Implementer (e.g., ARM), Variant, Revision, Part number (e.g., the part number for Cortex-M4 is 0xC24).
Example: Reading CPUID of ARM Cortex-M In ARM Cortex-M, the CPUID register address is fixed at <span>0xE000ED00</span>.
#include <stdint.h>
// CPUID register address
#define CPUID (*(volatile uint32_t *)0xE000ED00)
void print_cpuid_info(void) {
uint32_t cpuid_val = CPUID;
uint8_t implementer = (cpuid_val >> 24) & 0xFF; // Implementer, ARM is 0x41
uint8_t variant = (cpuid_val >> 20) & 0x0F; // Variant
uint8_t partno = (cpuid_val >> 4) & 0xFFF; // Part number
uint8_t revision = (cpuid_val >> 0) & 0x0F; // Revision
printf("Implementer: 0x%02X\n", implementer);
printf("Part No: 0x%03X (Cortex-M%x)\n", partno, partno == 0xC24 ? 4 : 0); // Example judgment
printf("Revision: r%dp%d\n", variant, revision);
}
Output may look like:
Implementer: 0x41 // 'A' for ARM
Part No: 0xC24 // Cortex-M4 core
Revision: r1p1 // Variant 1, Patch 1
3. PDID (Part Device ID) / DBGMCU_IDCODE
- What is it: This is aregister defined by the chip manufacturer (e.g., Microchip, Nuvoton) used to identify the specific MCU product model. It is usually found in the debugging module (DBGMCU).
- Significance: Allows software (especially programming tools, debuggers, and Bootloaders) to automatically identify what model of chip it is connected to, thus loading the corresponding configuration (e.g., memory layout, peripheral addresses, Flash algorithms, etc.).
- Content: Typically includes manufacturer ID, product line, memory size, package, version revision, etc. The format varies completely between different manufacturers.
Example: PDID of Nuvoton M0 Series
// Assume PDID register address is 0x50000100 (please refer to specific model's datasheet)
#define PDID_REG (*(volatile uint32_t *)0x50000100)
void check_chip_type(void) {
uint32_t pdid = PDID_REG;
// Parse PDID's bit fields according to the datasheet
uint16_t part_number = (pdid >> 16) & 0xFFFF;
uint8_t revision = (pdid >> 0) & 0xFF;
printf("Part Number: 0x%04X\n", part_number);
printf("Revision: 0x%02X\n", revision);
if (part_number == 0x0005) {
printf("This is a NUC100 series chip.\n");
} elseif (part_number == 0x00B0) {
printf("This is a M051 series chip.\n");
}
// ... other model judgments
}
Summary and Analogy
- UID (Unique Device Identifier): Like yourID number. It is yourunique identifier, used to strictly distinguish you from others.
- CPUID (Core Processor Identifier): Like youruniversity diploma. It indicates your educational background (CPU architecture is Cortex-M4), graduation year (revision version r1p1). All those who graduated in the same major and year have identical certificate content.
- PDID (Part Device Identifier): Like your company’s ID badge. It identifies which company you work for (chip manufacturer), which department (product line), and what position you hold (specific model). All colleagues in the same department and position have identical badge content.