Code protection in flash
The FPROT register can be set to protect regions in the flash memory from accidental programing or erasing.
Three separate memory regions, one growing upward from global address 0x0000 in the flash memory, called the lower region;
one growing downward from global address 0x7FFF in the flash memory, called the higher region;
and the remaining addresses in the flash memory, can be activated for protection.
The flash memory addresses covered by these protectable regions are shown in the flash memory map.
During the reset sequence, the FPROT register is loaded with the contents of the flash protection byte in the flash configuration field at global address 0x040D in flash memory.
The protection functions depend on the configuration of bit settings in FPROT register.
可以设置FPROT寄存器来保护闪存中的区域免受意外编程或擦除。
三个独立的内存区域,
一个从闪存中的全局地址0x0000向上生长的区域,称为下部区域;
一个从闪存中的全局地址0x7FFF向下生长的区域,称为较高区域;
最后一个是 Flash 存储器中的其余地址,可激活进行保护。
这些可保护区域覆盖的闪存地址在闪存映射中显示。
在复位序列期间,FPROT寄存器将闪存配置字段中闪存保护字节的内容加载到闪存的全局地址0x040D中。
保护功能取决于FPROT寄存器中位设置的配置。
void Flash_bootloader_protect(void)
{
//Flash Protection Operation Enable
FTMRE->FPROT |= FTMRE_FPROT_FPOPEN_MASK;
//Flash Protection Higher Address Range Disable
FTMRE->FPROT |= FTMRE_FPROT_FPHDIS_MASK;
//Flash Protection Lower Address Range Disable
FTMRE->FPROT &= ~FTMRE_FPROT_FPLDIS_MASK;
//Flash Protection Lower Address Size, from 0 to 0x3FFF
FTMRE->FPROT |= FTMRE_FPROT_FPLS_MASK;
}
上述程序保护的范围为0x3FFF-0x7FFF,升级程序时,0x3FFF-0x7FFF处于被保护