STM芯片烧写和加密解密
STM32 芯片烧写和加密、解密
连接
yurenchen 2013/3/4
Target -> Connect
(还可以设置 JLink script)
烧写
打开要烧写的文件,如 keil 编译生成的 hex 文件, 点烧写即可.
加密
加密后将不可通过 JTAG 读写 flash, 需要解密才可以.
解密
解密后 flash 会被全部清空成 0xFF
//0x00A5
OB 地址 0x1FFFF800 OB 结构 typedef struct {
__IO uint16_t RDP; __IO uint16_t USER; __IO uint16_t Data0; __IO uint16_t Data1; __IO uint16_t WRP0; __IO uint16_t WRP1; __IO uint16_t WRP2; __IO uint16_t WRP3; } OB_TypeDef;
(摘自 refrence.pdf)
(摘自 programingManual.pdf)
flash 加密的实质: 标记 Information Block 段的 Option Bytes 某字节, 通过 JTAG 接口访问 Flash 时先 检查此字节的标志. 通常的 flash 读写都不修改 Information Block.
加密解密操作同函数
FLASH_ReadOutProtection(ENABLE) FLASH_ReadOutProtection(DISABLE) 只是通过这个函数 需要代码执行一次后才能完成密. 操作: OB->RDP
ENABLE: OB->RDP = 0x00;
DISABLE: OB->RDP = RDP_Key;