Skip to main content
Visitor II
September 27, 2024
Solved

The option bytes are not being written in STM32L433

  • September 27, 2024
  • 2 replies
  • 877 views

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?

 

    This topic has been closed for replies.
    Best answer by TDK

    Does it work without the debugger connected? Run the code then connect afterwards and check with STM32CubeProgrammer on the option bytes.

    2 replies

    TDKAnswer
    Super User
    September 27, 2024

    Does it work without the debugger connected? Run the code then connect afterwards and check with STM32CubeProgrammer on the option bytes.

    Visitor II
    October 13, 2024

    I checked, but it didn't work without the debugger attached. The problem is still not solved. I'll try some more.

    Super User
    October 13, 2024

    Which STM32?

    > HAL_FLASH_OB_Launch() hangs

    Where?

    JW