P100脱机下载器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 lines
1.9 KiB

#include "sys.h"
#include "delay.h"
#include "led.h"
#include "UID_Encryption.h"
/* 实验目的:
演示如何将脱机下载器的UID自定义加密功能添加到用户的代码中
*/
/* 实验现象:
验证通过现象:LED1和LED2以1000ms的频率交替闪烁
验证不通过现象:LED1和LED2以100ms的频率交替闪烁
*/
/******************* UID自定义加密参数定义 *******************/
/*
* 当前芯片UID所在地址(注意:根据不同的芯片的地址各不一样,用户得按需修改)
* 如果芯片的UID不连续的话,请用户将UID拼凑到一段连续的内存里面方可使用UID_Encryption_Key_Check()接口
*/
#define UID_BASE 0x1FFF7A10
/*
* 密钥在当前芯片中的存储地址
*(注意:用户使用时必须按需修改该值,避免占用用户代码的位置及超过芯片flash的范围并且与上位机配置秘钥存储地址一致)
*/
#define KEY_BASE 0x08020000
/* 用户自的定义ID */
const uint8_t custom_id[12] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC};
int main(void)
{
Stm32_Clock_Init(336,8,2,7);//设置时钟,168Mhz
delay_init(168); //初始化延时函数
LED_Init(); //初始化LED时钟
/* 验证UID自定义加密的密钥是否正确 */
if(UID_Encryption_Key_Check((void*)KEY_BASE,
(void*)UID_BASE,
(void*)custom_id,
LENGTH_12,
LITTLE_ENDIA,
ALGORITHM_4))
{/* 验证不通过 */
while(1) //LED快闪
{
LED0=0; //DS0亮
LED1=1; //DS1灭
delay_ms(100);
LED0=1; //DS0灭
LED1=0; //DS1亮
delay_ms(100);
}
}
else
{/* 验证通过 */
}
while(1)//LED慢闪
{
LED0=0; //DS0亮
LED1=1; //DS1灭
delay_ms(1000);
LED0=1; //DS0灭
LED1=0; //DS1亮
delay_ms(1000);
}
}