cancel
Showing results for 
Search instead for 
Did you mean: 

The option bytes are not being written in STM32L433

Seiji_Hiraki
Associate II

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
TDK
Guru

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

If you feel a post has answered your question, please click "Accept as Solution".

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

Which STM32?

> HAL_FLASH_OB_Launch() hangs

Where?

JW