2018-03-05 10:18 AM
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-protection2018-03-06 05:03 AM
Hi
hoanguyen71311
,Please refer to this example under the
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-
2018-03-07 10:08 AM
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