Skip to main content
Gahlen Feld
Associate III
February 22, 2023
Solved

Design flaw in HAL?

  • February 22, 2023
  • 2 replies
  • 1506 views

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!

This topic has been closed for replies.
Best answer by Patrice LF

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

2 replies

Patrice LF
Patrice LFBest answer
Technical Moderator
March 7, 2023

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 III
March 8, 2023

Hello Patrice, many thanks! This way it works fine :smiling_face_with_smiling_eyes: