官方文档:

at32_unique_id

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "at32f435_437_wk_config.h"
#include "wk_system.h"
#include "wk_usart.h"

#include <stdio.h>

#define STORAGE_INFO 0x1FFFF7E0 // 闪存大小(单位:KByte)
#define UNIQUE_ID 0x1FFFF7E8
#define UNIQUE_ID_0_31 0x1FFFF7E8
#define UNIQUE_ID_32_63 0x1FFFF7EC
#define UNIQUE_ID_64_95 0x1FFFF7F0

struct mcu_info_t {
uint32_t flash_size;
uint8_t unique_id[12];
} mcu_info;

void get_mcu_info(void)
{
mcu_info.flash_size = *(uint32_t *)STORAGE_INFO;

printf("Flash: %d KByte\n", mcu_info.flash_size);

for (uint8_t i=0; i<12; i++) {
mcu_info.unique_id[i] = *(uint8_t*)(UNIQUE_ID+i);
printf(" %02x", mcu_info.unique_id[i]);
}
printf("\n");
}

int main(void)
{
wk_system_clock_config();

wk_periph_clock_config();

wk_nvic_config();

wk_timebase_init();

wk_usart1_init();

get_mcu_info();

while (1) {
}
}

串口打印结果 (AT32F437ZGT7):

1
2
3
[2025-01-04 21:04:22.813] Flash: 1024 KByte  
[2025-01-04 21:04:22.813] 41 c0 30 a0 00 c0 f5 04 17 97 20 0e (96位唯一ID,8x【12字节】)
[2025-01-04 21:04:22.813]