FLASH->CR1 = FLASH_CR1_RESET_VALUE;
FLASH->CR2 = FLASH_CR2_RESET_VALUE;
FLASH->NCR2 = FLASH_NCR2_RESET_VALUE;
FLASH->IAPSR &= (uint8_t)(~FLASH_IAPSR_DUL);
FLASH->IAPSR &= (uint8_t)(~FLASH_IAPSR_PUL);
(void) FLASH->IAPSR; /* Reading of this register causes the clearing of status flags */
#ifdef USE_ROP_ENABLE
//Flash Data区解密
FLASH->DUKR = FLASH_RASS_KEY2; /* Warning: keys are reversed on data memory !!! */
FLASH->DUKR = FLASH_RASS_KEY1;
//编写选项字ROP
/* Enable write access to option bytes */
FLASH->CR2 |= FLASH_CR2_OPT;
FLASH->NCR2 &= (uint8_t)(~FLASH_NCR2_NOPT);
*((NEAR uint8_t*)0x4800) = 0xAA;//ROP的位写
while((uint8_t)(FLASH->IAPSR & (uint8_t)(FLASH_IAPSR_EOP |
FLASH_IAPSR_WR_PG_DIS)) == 0);
/* Disable write access to option bytes */
FLASH->CR2 &= (uint8_t)(~FLASH_CR2_OPT);
FLASH->NCR2 |= FLASH_NCR2_NOPT;
// FLASH_ProgramOptionByte(0x4800, 0x00);
//Flash Data区加密
FLASH->IAPSR &= (uint8_t)FLASH_MEMTYPE_DATA;
#endif
上一篇:关于stm8l05RB的usart1串口复用A2,A3配置
下一篇:stm8开发环境配置及测试
推荐阅读最新更新时间:2024-11-04 20:33