STM32F107 Read Out Protection by Code HAL

Viewed 1070

i want to enable the normal Read Out Protection, currently I do it in the ST Link Utility but better will be in code. I found some old snippets which are for the old Std Lib, not for HAL:

 if (FLASH_OB_GetRDP() != SET) {

  FLASH_OB_Unlock();

  FLASH_OB_RDPConfig(OB_RDP_Level_1);

  // Start the Option Bytes programming process
  if (FLASH_OB_Launch() != FLASH_COMPLETE) {
    // User can add here some code to deal with this error
  }

  FLASH_OB_Lock();
}

Does anybody have the right Code which is working for HAL Lib?

Thanks!

2 Answers
  HAL_FLASH_Unlock();
  HAL_FLASH_OB_Unlock();
  pOBInit_for_readprot.OptionType = OPTIONBYTE_RDP;
  pOBInit_for_readprot.RDPLevel = OB_RDP_LEVEL_1;
  HAL_FLASHEx_OBProgram(&pOBInit_for_readprot);
  HAL_FLASH_OB_Launch();
  HAL_FLASH_OB_Lock();
  HAL_FLASH_Lock();

There is a working procedure to programm RDP. Prooved by my stm32f4 project.

Related