hal stm32f031 设置读保护
作者:互联网
void ROP(void) { static FLASH_OBProgramInitTypeDef OptionsBytesStruct; HAL_FLASH_Unlock(); //解锁Flash HAL_FLASH_OB_Unlock(); //解锁选项字节区 HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct); //读取选项字节设置 //检测RDP的设置是否低于LEVEL 1 if (OptionsBytesStruct.RDPLevel < OB_RDP_LEVEL_1) { OptionsBytesStruct.OptionType = OPTIONBYTE_RDP; //重写选项字 OptionsBytesStruct.RDPLevel = OB_RDP_LEVEL_1; //如果写入没成功 if (HAL_FLASHEx_OBProgram(&OptionsBytesStruct) != HAL_OK) { //自己加个led什么的提示 } else { HAL_FLASH_OB_Launch(); } } HAL_FLASH_OB_Lock(); //锁定选项字节 HAL_FLASH_Lock(); }
标签:OptionsBytesStruct,HAL,RDP,LEVEL,FLASH,OB,设置,hal,stm32f031 来源: https://www.cnblogs.com/jnhs/p/15825905.html