读保护
void Flash_EnableReadProtection(void)
{FLASH_OBProgramInitTypeDef OBInit;__HAL_FLASH_PREFETCH_BUFFER_DISABLE();HAL_FLASHEx_OBGetConfig(&OBInit);if(OBInit.RDPLevel == OB_RDP_LEVEL_0){OBInit.OptionType |= OPTIONBYTE_RDP;OBInit.RDPLevel = OB_RDP_LEVEL_1;HAL_FLASH_Unlock();HAL_FLASH_OB_Unlock();HAL_FLASHEx_OBProgram(&OBInit);HAL_FLASH_OB_Launch();//必须添加这个,不然读保护设置不生效HAL_FLASH_OB_Lock();HAL_FLASH_Lock();}__HAL_FLASH_PREFETCH_BUFFER_ENABLE();}
解除读保护
用 JLinkSTM32.exe