UID总共96位,即12个字节,标记为Byte0-Byte11,起始地址为0x1FFEF7E8
最后一个字节Byte11为芯片型号,在用户手册上都能查到,已知型号为:
0x02:AT32F403
0x04:AT32F413
0x05:AT32F415
0x07:AT32F403A
0x08:AT32F407
0x09:AT32F421
0x0D:AT32F435
0x0E:AT32F437
0x0F:AT32F425
倒数第3个字节即Byte9的bit[6:4]共3位表示芯片的版本,取值0-7,对应版本A、B、C...
如果嫌96位作为基序列号太长,可以将96位压缩为32位,按位取值为:[87:79][33:28][16:0],按字节取为:
Byte10的全部位[87:80]
Byte9的最高位[79]
Byte4的低两位[33:32]
Byte3的高半字节[31:28]
Byte2的最低位[16]
Byte1的全部位[15:8]
Byte0的全部位[7:0]
AT32读取MCU型号的函数:
const char *AT32_GetMcuSeries(void)
{
const uint8_t *p = (const uint8_t *)UNIQUE_ID_ADDR;
char *model = NULL;
switch(p[11])
{
case 0x02:
model = "AT32F403";
break;
case 0x04:
model = "AT32F413";
break;
case 0x05:
model = "AT32F415";
break;
case 0x07:
model = "AT32F403A";
break;
case 0x08:
model = "AT32F407";
break;
case 0x09:
model = "AT32F421";
break;
case 0x0D:
model = "AT32F435";
break;
case 0x0E:
model = "AT32F437";
break;
case 0x0F:
model = "AT32F425";
break;
default:
model = "UNKNOWN";
break;
}
return model;
}
AT32读取MCU硬件版本的函数:
char AT32_GetMcuRevision(void)
{
const uint8_t *p = (const uint8_t *)UNIQUE_ID_ADDR;
return 'A' + (((p[9]&0x70))>>4);
}
从96位UID获取32位UID的函数:
uint32_t AT32_GetUID32(void)
{
const uint8_t *p = (const uint8_t *)UNIQUE_ID_ADDR;
return ((uint32_t)p[10]<<24) | ((uint32_t)p[1]<<8) | p[0]
| (((p[9]&0x80)|((p[4]&0x03)<<5)|((p[3]&0xF0)>>3)|(p[2]&0x01))<<16);
}
其它厂家,似乎对96位UID的意义都没有详细文档描述。
|