|
楼主 |
发表于 2012-6-25 12:00:53
|
显示全部楼层
使用程序修改 OptionsByte的例子:
//OPT 数组从STVP得到
unsigned char OPT[9]={0,0,0x80,0,0,0,0,0,0x55};
void Write_OPT(void)
{
do{
FLASH_DUKR = 0xae;
FLASH_DUKR = 0x56;
}
while(!(FLASH_IAPSR & 0x08)); //解锁Flash
FLASH_CR2 = 0x80; //对选项字节进行写操作被使能
FLASH_NCR2 = 0x7f; //互补控制寄存器
*((unsigned char *)0x4800) = OPT[0]; //OPT0 Read-out Protection
*((unsigned char *)0x4801) = OPT[1]; //OPT1 User boot code
*((unsigned char *)0x4802) = ~OPT[1]; //OPT1N Complementary of User boot code
*((unsigned char *)0x4803) = OPT[2]; //OPT2 Alternate function remapping
*((unsigned char *)0x4804) = ~OPT[2]; //OPT2N Complementary of Alternate function
*((unsigned char *)0x4805) = OPT[3]; //OPT3 Watchdog option
*((unsigned char *)0x4806) = ~OPT[3]; //OPT3N Complementary of Watchdog option
*((unsigned char *)0x4807) = OPT[4]; //OPT4 Clock Option
*((unsigned char *)0x4808) = ~OPT[4]; //OPT4N Complementary of Clock Option
*((unsigned char *)0x4809) = OPT[5]; //OPT5 HSE Clock Startup
*((unsigned char *)0x480A) = ~OPT[5]; //OPT5N Complementary of HSE Clock Startup
*((unsigned char *)0x480D) = OPT[7]; //OPT7 Flash wait states
*((unsigned char *)0x480E) = ~OPT[7]; //OPT7N Complementary of Flash wait states
*((unsigned char *)0x487e) = OPT[8]; //OPTBL Bootloader
*((unsigned char *)0x487f) = ~OPT[8]; //OPTBL Complementary of Bootloader
} |
|