cancel
Showing results for 
Search instead for 
Did you mean: 

Design flaw in HAL?

Gahlen Feld
Associate II

I am using CubeIDE 1.11.2 with a STM32F3DISCOVERY board and have created an IDE project via the integrated CubeMX GUI.

I want to activate read protection via HAL_FLASHEx_OBProgram as well as the write protection for the FLASH area of my firmware (applying the same HAL function).

But HAL only allows one of the two features at a time.

The reason is that for every single action (write RDP and write WRP) HAL completely erases the OptionBytes via the FLASH peripheral (as you can see in the HAL source code).

It is important for us to enable RDP and WRP at the same time!

I could do it the bare metal way, but our project is intended for all our used STM32 MCUs and that's exactly what HAL was created for.

Please, can you tell me a way to enable both RDP and WRP with the HAL functions at the same time?

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrice LF
ST Employee

Hi @Gahlen Feld​ 

taking into account the current HAL FLASH driver and given the automatic user option bytes erase the recommended sequence to program RDP, WRP and other user data option bytes is as follows:

  • call HAL_FLASHEx_OBProgram() to program RDP level (all option bytes will be erased),  
  • call HAL_FLASHEx_OBProgram() to program write protection on desired pages (all option bytes except RDP will be erased),
  • call HAL_FLASHEx_OBProgram() to program user data option bytes (can be done in the same call than write protection or through several calls),
  • call HAL_FLASH_OB_Launch() to apply whole option bytes configuration.

Thanks to share your feedback on this proposition

Regards

Patrice

View solution in original post

2 REPLIES 2
Patrice LF
ST Employee

Hi @Gahlen Feld​ 

taking into account the current HAL FLASH driver and given the automatic user option bytes erase the recommended sequence to program RDP, WRP and other user data option bytes is as follows:

  • call HAL_FLASHEx_OBProgram() to program RDP level (all option bytes will be erased),  
  • call HAL_FLASHEx_OBProgram() to program write protection on desired pages (all option bytes except RDP will be erased),
  • call HAL_FLASHEx_OBProgram() to program user data option bytes (can be done in the same call than write protection or through several calls),
  • call HAL_FLASH_OB_Launch() to apply whole option bytes configuration.

Thanks to share your feedback on this proposition

Regards

Patrice

Gahlen Feld
Associate II

Hello Patrice, many thanks! This way it works fine 😊