cancel
Showing results for 
Search instead for 
Did you mean: 

Enable and disable write protection stm32l4

Hoa Nguyen
Associate
Posted on March 05, 2018 at 19:18

I am new to stm32 micro-controller.  I have a question regards to how to enable and disable write protection with stm32l4 chip.  My goal is first I will check if user application is write protected or not, if it is then I need to disable write protection to write into that section.  Any examples will help me a lot

Thank you in advance.

#fft-stm32l4 #read-write-protection
2 REPLIES 2
Nesrine M_O
Lead II
Posted on March 06, 2018 at 14:03

Hi

hoanguyen71311

,

Please refer to this example under the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-mcu-packages/stm32cubel4.html

firmware package that describe how to configure and use the FLASH HAL API to enable and disable the write protection of the internal Flash memory.

STM32Cube_FW_L4_V1.0\Projects\STM32L476G-EVAL\Examples\FLASH\FLASH_WriteProtection

-Nesrine-

Hoa Nguyen
Associate
Posted on March 07, 2018 at 19:08

Hi

ELMHIRI.Syrine

,

I have looked at the example but I don't really get deep understanding about disable and enable write protection. Disable and enable are almost the same code and I don't know how the specific region is disable, or at least check the if that region is write protected or not to disable or enable. Below is a part of the code from the example which I don't understand.

HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct);

HAL_FLASHEx_OBGetConfig(&OptionsBytesStruct2);

#ifdef WRITE_PROTECTION_DISABLE

/* Check if desired pages are already write protected ***********************/

if ((OptionsBytesStruct.WRPStartOffset == StartPage) && (OptionsBytesStruct.WRPEndOffset == EndPage))

{

/* Current area correspond to the area to disable */

OptionsBytesStruct.OptionType = OPTIONBYTE_WRP; //does this line of code disable the region?

OptionsBytesStruct.WRPStartOffset = 0xFF;

OptionsBytesStruct.WRPEndOffset = 0;

}

else if ((OptionsBytesStruct.WRPStartOffset == StartPage) && (OptionsBytesStruct.WRPEndOffset > EndPage))

{

/* Current area is bigger than the area to disable : */

/* - End of area is bigger than the last page to un-protect */

OptionsBytesStruct.OptionType = OPTIONBYTE_WRP;

OptionsBytesStruct.WRPStartOffset = EndPage + 1; //why is it only added by 1?

}

if you can give me a brief explanation for the code above I will highly appropriate. Thank you