jianghuai/SYSTEM/chipid.c
2024-05-07 09:36:09 +08:00

70 lines
1.6 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*************************************
* 文件名 xxx.c
* 描述 获取CPU的ID函数每个芯片都有唯一的 96_bit unique ID
* 实验平台MINI STM32开发板 基于STM32F103C8T6
* 硬件连接:无
* 库版本 ST3.0.0
**********************************************************************************/
#include "chipid.h"
#include "led.h"
u32 ChipUniqueID[3];
#define UID_BASE 0x1FF80050
/* 获取芯片ID */
void Get_ChipID(void)
{
ChipUniqueID[0] = *(__IO u32 *)(0X1FFFF7F0); // 高字节
ChipUniqueID[1] = *(__IO u32 *)(0X1FFFF7EC); //
ChipUniqueID[2] = *(__IO u32 *)(0X1FFFF7E8); // 低字节
if(ChipUniqueID[0]==0xFFFFFFFF)
{
ChipUniqueID[0] = (uint32_t)(*((uint32_t *)UID_BASE));
ChipUniqueID[1] = (uint32_t)(*((uint32_t *)(UID_BASE + 0x04)));
ChipUniqueID[2] = (uint32_t)(*((uint32_t *)(UID_BASE + 0x14)));
}
}
u32 ChipUniqueIDdecodeflag;
uint8_t ChipUniqueIDCompare(void)
{
if((SysParaPileD.ChipUniqueID[0] == ChipUniqueID[0])&&(SysParaPileD.ChipUniqueID[1] == ChipUniqueID[1])
&& (SysParaPileD.ChipUniqueID[2] == ChipUniqueID[2]))
{
return 1;
}
else
{
MCU_LED(1);
while (1)
{
MCU_LED(1);
IWDG_Feed();
ChipUniqueIDdecodeflag =1;
if(ChipUniqueIDdecodeflag==1)
{
ChipUniqueIDdecodeflag =0;
SysParaPileD.ChipUniqueID[0] = ChipUniqueID[0];
SysParaPileD.ChipUniqueID[1] = ChipUniqueID[1];
SysParaPileD.ChipUniqueID[2] = ChipUniqueID[2];
Delay_MS(5);
SysParaPileD.bluetooth_passward[4]=0x35;
SysParaPileD.bluetooth_passward[5]=0x36;
SysWriteSysParm();
Delay_MS(5);
break;
}
}
}
}