cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L412: Preserving certain sections of flash so that they are not erased when the MCU is reprogrammed?

MCocke.1
Associate

Hi Everybody,

Firstly, I would like to note that I am pretty new to embedded systems, so I am sorry if my terminology is off or if I am not communicating clearly, please forgive the (probably) gaping holes in my knowledge. I will do my best to communicate my problem as clearly as I can.

I am working with a STM32L412 on product development, the team I a part of would like to have a section of flash not be erased when the MCU is reprogrammed. The amount of information that we need to be preserved is small, maybe at most 200 bytes, enough space to store some information like a serial number, baud rate, etc.

To that end, I currently have sectioned off the last page (page 63) of flash in my L412 in the linker file to separate it from the rest of flash, so I can use it to contain this information.

   //This is what I have so far in the linker file. 
   RAM   (xrw)   : ORIGIN = 0x20000000,  LENGTH = 40K
   RAM2   (xrw)   : ORIGIN = 0x10000000,  LENGTH = 8K
   FLASH   (rx)   : ORIGIN = 0x8000000,  LENGTH = 126K
   DeviceInfo (rx)   : ORIGIN = 0x801F800,  LENGTH = 2K
 
 

Is there anything that I would need to do in the linker file to ensure that Device info wont get rewritten by the programmer tool?

In looking into different options on how to make this flash persist through reprogramming, I learned that it is possible to write protect certain sections of flash, but the documentation on write protection on page 98 of RM0394 Rev4 seems to imply that write protection will make any attempts to reprogram the MCU fail. Is this true or am I just being overly cautious as a new developer.

Part of my confusion on this topic lies with the two different tools that are available to reprogram the MCU. When I poke around STMCubeIDE, I am unable to find a settings page where I can control how the debugger tool controls the on MCU flash, so I don't know what exactly is happening when I re-flash the MCU 's during development.

In production, we will be using STMCubeProgrammer to flash the MCU's. I know CubeProgrammer has a tool that can let you selectively erase sections of flash, but I would prefer to wrap up the programming process to make things easier on our production department. I would rather make it so they do not need to know any of the intricacies of the program in order to make this product.

Thank you all for the help! I really appreciate any assistance I may get.

Best,

Matthew

1 ACCEPTED SOLUTION

Accepted Solutions
Sara BEN HADJ YAHYA
ST Employee

Hello @MCocke.1​ ,

Welcome to STCommunity and thanks for your feedback,

In order to protect page 63 using CubeProgrammer, you need to write the value "0x3F" in both WRP1A_STRT and WRP1A_END and finally click on Apply button.


_legacyfs_online_stmicro_images_0693W00000bhfS5QAI.pngWRP1A_STRT and WRP1A_END are respectively the addresses of the first page of the bank 1 WRP area and the last page of the bank1 WRP area. Since only 1 page needs protection in your case, the start and end addresses should be equal.

The value "0x3F" is calculated using the following formula which is mentioned in RM0394 section 3.5.3.

"The WRP “y�? area (y=A,B) is defined from the address: Flash memory Base address + [WRP1y_STRT x 0x800] (included) to the address: Flash memory Base address + [(WRP1y_END+1) x 0x800] (excluded)."

To remove the protection, the start address should be superior to the end address.

I hope this helps!

Sara.

View solution in original post

2 REPLIES 2
Sara BEN HADJ YAHYA
ST Employee

Hello @MCocke.1​ ,

Welcome to STCommunity and thanks for your feedback,

In order to protect page 63 using CubeProgrammer, you need to write the value "0x3F" in both WRP1A_STRT and WRP1A_END and finally click on Apply button.


_legacyfs_online_stmicro_images_0693W00000bhfS5QAI.pngWRP1A_STRT and WRP1A_END are respectively the addresses of the first page of the bank 1 WRP area and the last page of the bank1 WRP area. Since only 1 page needs protection in your case, the start and end addresses should be equal.

The value "0x3F" is calculated using the following formula which is mentioned in RM0394 section 3.5.3.

"The WRP “y�? area (y=A,B) is defined from the address: Flash memory Base address + [WRP1y_STRT x 0x800] (included) to the address: Flash memory Base address + [(WRP1y_END+1) x 0x800] (excluded)."

To remove the protection, the start address should be superior to the end address.

I hope this helps!

Sara.

I wouldn't tell the Linker about it..

Otherwise make sure it has NOLOAD or NOBITS flagging at the ELF Object level.

Can your app refer to it via a pointer/structure? Initialize to usable defaults in its absence?

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