|
楼主有没有看过ST官方库的USB例程代码
在每个例子的hw_config.c文件里面有这样一段
/*******************************************************************************
* 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);
}
}
这段代码的意思是把序列号字符串用芯片的唯一ID来替换
你只需要把芯片ID换成你想要的字符就行了 |
|