2023-08-29 10:15 PM
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 .
2023-08-30 06:23 AM - edited 2023-08-30 07:45 AM
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.
2023-08-30 09:23 AM
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?
2023-08-30 10:22 PM
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.
2023-08-30 10:26 PM
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.
2023-08-31 06:02 AM
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.
2023-09-03 06:15 AM
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.
Thanks.
2023-09-21 09:32 AM
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.