cancel
Showing results for 
Search instead for 
Did you mean: 

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

DLyum.1
Associate II

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!

1 ACCEPTED SOLUTION

Accepted Solutions
FBL
ST Employee

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.

View solution in original post

4 REPLIES 4

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thank you!

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

FBL
ST Employee

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.

Thank you!