ID是放在Flash特定地址的一些数据
知道地址后直接读取就可以了
下面这个是ST库里面读芯片ID的代码
/*******************************************************************************
* Function Name : Get_SerialNum.
* Description : Create the serial number string descriptor.
* Input : None.
* Output : None.
* Return : None.
*******************************************************************************/
void Get_SerialNum(void)
{
u32 Device_Serial0, Device_Serial1, Device_Serial2;
Device_Serial0 = *(u32*)(0x1FFFF7E8);
Device_Serial1 = *(u32*)(0x1FFFF7EC);
Device_Serial2 = *(u32*)(0x1FFFF7F0);
if (Device_Serial0 != 0)
{
Speaker_StringSerial[2] = (u8)(Device_Serial0 & 0x000000FF);
Speaker_StringSerial[4] = (u8)((Device_Serial0 & 0x0000FF00) >> 8);
Speaker_StringSerial[6] = (u8)((Device_Serial0 & 0x00FF0000) >> 16);
Speaker_StringSerial[8] = (u8)((Device_Serial0 & 0xFF000000) >> 24);
Speaker_StringSerial[10] = (u8)(Device_Serial1 & 0x000000FF);
Speaker_StringSerial[12] = (u8)((Device_Serial1 & 0x0000FF00) >> 8);
Speaker_StringSerial[14] = (u8)((Device_Serial1 & 0x00FF0000) >> 16);
Speaker_StringSerial[16] = (u8)((Device_Serial1 & 0xFF000000) >> 24);
Speaker_StringSerial[18] = (u8)(Device_Serial2 & 0x000000FF);
Speaker_StringSerial[20] = (u8)((Device_Serial2 & 0x0000FF00) >> 8);
Speaker_StringSerial[22] = (u8)((Device_Serial2 & 0x00FF0000) >> 16);
Speaker_StringSerial[24] = (u8)((Device_Serial2 & 0xFF000000) >> 24);
}
}
在ST的库中没这个函数印象,看了楼主提供的函数命名,不像ST的命名风格。DevID怎么通过全局变量返回呢?
“Speaker_StringSerial” ?
这个是ST的USB库里面Speaker的部分代码
写这个函数只是为说明ST自己是怎么来用他的芯片ID的
没有这个头文件,为何要这个头文件?自己就三行,楼顶的已经给出了,自己加
Device_Serial0 = *(u32*)(0x1FFFF7E8);
Device_Serial1 = *(u32*)(0x1FFFF7EC);
Device_Serial2 = *(u32*)(0x1FFFF7F0);