Skip to main content
HZaib.1
Associate III
August 30, 2023
Question

Modifying linker to keep all ram after soft reset

  • August 30, 2023
  • 4 replies
  • 3698 views

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. 

https://interrupt.memfault.com/blog/noinit-memory 

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 .

This topic has been closed for replies.

4 replies

TDK
Super User
August 30, 2023

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""."
Tesla DeLorean
Guru
August 30, 2023

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 VenmoUp vote any posts that you find helpful, it shows what's working..
HZaib.1
HZaib.1Author
Associate III
August 31, 2023

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.

TDK
Super User
August 31, 2023

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""."
LCE
Principal II
August 31, 2023

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.

Garnett.Robert
Senior III
September 21, 2023

Hi,

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.

Regards

Rob

 

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