2025-01-08 06:02 PM - last edited on 2025-01-08 06:05 PM by Andrew Neil
void EnableWriteProtect(uint8_t image)
{
FLASH_OBProgramInitTypeDef OBInit = {0};
FLASH_OBProgramInitTypeDef sOBPrev = {0};
uint32_t WRPSector;
/* Unlock the User Flash area */
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
/* Get the boot configuration status */
HAL_FLASHEx_OBGetConfig(&OBInit);
WRPSector = OBInit.WRPSector | BIT(0);
OBInit.Banks = FLASH_BANK_2;
OBInit.OptionType = OPTIONBYTE_WRP;
OBInit.WRPState = OB_WRPSTATE_ENABLE;
OBInit.WRPSector = WRPSector;
HAL_FLASHEx_OBProgram(&OBInit);
/* Launch Option bytes loading */
HAL_FLASH_OB_Launch();
/* Unlock the User Flash area */
HAL_FLASH_Lock();
HAL_FLASH_OB_Lock();
}
2025-01-08 07:56 PM
> Does HAL_FLASH_OB_Launch cause a system reset on STM32H563 MCU?
No, HAL_FLASH_OB_Launch sets FLASH_OPTCR_OPTSTART which reloads the option bytes but does not reset the chip.
The typical way of modifying option bytes is to only change them if needed. If WRP is already set correctly, no need to modify them.