Skip to main content
DLyum.1
Associate
March 1, 2023
Solved

STM32L15xx microcontroller can internal FLASH Read Protection be enabled inside flashed SW?

  • March 1, 2023
  • 2 replies
  • 1531 views

Hi,

My project is based on STM32L15xx microcontroller. I know, that internal FLASH Read Protection may be enabled during programming an image by STMFlashLoader with --erp option. My question is: can I compile my image with internal FLASH read protection enabled by some tweak so that I don't have to use "--erp" option on downloading my image to the target?

Thanks in advance!

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

Hello @DLyum.1​ ,

You need to Unlock the Flash and OB to enable the flash control register access.

Here is an example:

FLASH_OBProgramInitTypeDef obProgram = { 0 };

obProgram.OPTIONBYTE_RDP = OB_RDP_LEVEL_1;

FLASH_OB_RDPConfig

HAL_FLASHEx_OBGetConfig(&obProgram);

...

if (obProgram.RDPLevel == OB_RDP_LEVEL_1)

...

The function FLASH_OB_RDPConfig(); could be used.

Hope this helps!

2 replies

Tesla DeLorean
Guru
March 1, 2023

Should be able to check the state of the option bytes, and change them.​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
DLyum.1
DLyum.1Author
Associate
March 1, 2023

Thank you!

The Option Bytes are described in PM0062 (Flash and EEPROM Programming Manual) application notes.

FBLBest answer
Technical Moderator
March 1, 2023

Hello @DLyum.1​ ,

You need to Unlock the Flash and OB to enable the flash control register access.

Here is an example:

FLASH_OBProgramInitTypeDef obProgram = { 0 };

obProgram.OPTIONBYTE_RDP = OB_RDP_LEVEL_1;

FLASH_OB_RDPConfig

HAL_FLASHEx_OBGetConfig(&obProgram);

...

if (obProgram.RDPLevel == OB_RDP_LEVEL_1)

...

The function FLASH_OB_RDPConfig(); could be used.

Hope this helps!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.Best regards,FBL
DLyum.1
DLyum.1Author
Associate
March 1, 2023

Thank you!