Showing results for 
Search instead for 
Did you mean: 

Modifying linker to keep all ram after soft reset

Associate III

Hi, everyone.


I am using stm32l496 and I my application requires me to keep all data in ram after reset. Now i followed these instructions in this link. 

it works, like I expected but the thing is I want to not lose any data that is in the ram after softreset. 

Now I one solution could be to write  __attribute_((section(".noinit"))) to every variable, but I think it is so trivial and better solutions are out there. So please guide me.

I also tried to modify data and bss section but that completely breaks the code so I stopped messing with it.

right now this is the section i made which works

.noinit (NOLOAD): { /* place all symbols in input sections that start with .noinit */ KEEP(*(*.noinit*)) } >RAM

instead of making separate memmory location I kept this section in ram .


In your startup file, add code right after Reset_Handler which checks if it's a soft reset and, if so, skips memory initialization.

Wouldn't be surprised if something breaks due to this.

Leave the linker file alone since, on the first power-up, you do want everything to be initialized.

If you feel a post has answered your question, please click "Accept as Solution".

All data has been maintained when you enter Reset_Handler, what you do with it after that is up to you.

Review the code in startup.s and understand the startup process and the expectations of the C Runtime Environment.

As @TDK indicates, unless you have the first clue about the mechanics here, you're likely to build something that breaks, because usually you have statics you set to specific values, or memory that is zeroed out.

Why do you need this behaviour? Can you isolate it to a specific block of variables, or a section of memory you don't tell the linker about?

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

Well, all the variables are initialized in my own init inside the code, and there are specific structures in the code that need to retain value after reset. It does not matter if they have random value after powerup the reason is that during initialization I check the crc for those structures, if that crc does not match than that means that structure is not correct and I initialize that structure if the system softreset than that crc matchs so than I do not initialize that structure. This is the way things are working right now.


As the others said, I think it's safer to put data into a no init section.
Add a flag so you can find out if it has been initialized before, unless you are using your CRC method anyway.

Do you check the CRC of SystemCoreClock and other variables that your code doesn't know about it? Marking your own variables as NOINIT is one thing, marking everything is another.

If you feel a post has answered your question, please click "Accept as Solution".
Associate III

you are right about that, never thought about variables like SystemCoreClock and other stuff, I was thinking about it one dimensional. I guess it is safer to put variables manually inside noinit. 


Senior III


I have had similar issues and I use noinit sections in the linker script. When using the CubeIDE the Build Analyzer displays all of these sections very nicely.




PS, Although I have fiddled with the startup file just because I could.