2024-09-26 10:29 PM
I would like to enable write protection via an option byte.
However, HAL_FLASH_OB_Launch() hangs, and even if the CPU is reset afterwards, the option byte is not rewritten.
This issue occurs with both combinations: my board + J-Link or Nucleo + ST-Link.
I have the following function to set the option bytes:
void set_write_protection(uint32_t WRPArea, uint32_t start, uint32_t end)
{
FLASH_OBProgramInitTypeDef OBInit;
HAL_StatusTypeDef status;
HAL_FLASH_Unlock();
HAL_FLASH_OB_Unlock();
OBInit.WRPArea = WRPArea;
HAL_FLASHEx_OBGetConfig(&OBInit);
if (OBInit.WRPStartOffset != start || OBInit.WRPEndOffset != end) {
OBInit.WRPStartOffset = start;
OBInit.WRPEndOffset = end;
OBInit.OptionType = OPTIONBYTE_WRP;
status = HAL_FLASHEx_OBProgram(&OBInit);
if (status != HAL_OK) {
return;
}
HAL_FLASH_OB_Launch();
}
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
}
void set_area1_write_protection(uint8_t enable)
{
if (enable)
set_write_protection(OB_WRPAREA_BANK1_AREAA, 0x00, 0x20);
else
set_write_protection(OB_WRPAREA_BANK1_AREAA, 0xFF, 0x00);
}
Is there any way to successfully enable Write Protection?
Solved! Go to Solution.
2024-09-27 06:47 AM
Does it work without the debugger connected? Run the code then connect afterwards and check with STM32CubeProgrammer on the option bytes.
2024-09-27 06:47 AM
Does it work without the debugger connected? Run the code then connect afterwards and check with STM32CubeProgrammer on the option bytes.
2024-10-13 04:25 PM
I checked, but it didn't work without the debugger attached. The problem is still not solved. I'll try some more.
2024-10-13 04:56 PM - edited 2024-10-13 04:58 PM
Which STM32?
> HAL_FLASH_OB_Launch() hangs
Where?
JW