Hi,
I'm trying to declare a variable that can survive a watchdog reset.
I'm using Keil uVision with the MDK-ARM compiler V6.19 with an STM32L0xx microcontroller.
There's a NoInit section of the RAM set up in the project variant options:
I've set the options on the file that has the variable definition to use the NoInit RAM section:
The scatter file for the project is changed to add a .bbs.NoInit section for IRAM2:
; *************** ; * Scatter-Loading Description File generated by uVision * ; *************** LR_IROM1 0x08000000 0x00007FF0 { ; load region size_region ER_IROM1 0x08000000 0x00007FF0 { ; load address = execution address *.o (RESET, +First) *(InRoot$$Sections) .ANY (+RO) .ANY (+XO) } RW_IRAM1 0x20000000 0x00001FF0 { ; RW data .ANY (+RW +ZI) } RW_IRAM2 0x20001FF0 UNINIT 0x00000010 { ; No init section *(.bss.NoInit) } }
And the variable is declared like: uint8_t infLoopIdentifier __attribute__((section(".bss.NoInit")));
But the variable is always initialised as 0 after the WDG reset.
I've checked the map file and the variable is being put into the NoInit section:
infLoopIdentifier 0x20001ff0 Data 1 lto-llvm-7a9e85.o(.bss.NoInit)
Can anyone help and point out what I'm doing wrong?
Thanks
Stu
HI Ronan,
Brilliant, your suggestions helped to fix it. I hadn't thought to use the debugger as the code was running in low power mode and I didn't think it would work correctly. It was my own fault. haha. A seemingly innocent function call prior to checking the variable actually called another function and deep in there was a line which set the variable to 0. A few lines of code and everything now works perfectly.
I have also turned link-time optimization off (not sure why it was on, some default thing? it wasn't in the older V5 compiler as far as I can see.)
And I re-added the volatile qualifier that I'd taken out previously.
Many, many thanks for your suggestions, you've saved me a ton of time trying to figure it out.
Happy to help. Glad to hear you are working again.
If LTO isn't the cause of the issue, it might be sensible to re-enable it if performance becomes an issue.
Basically it groups all objects into one big object, and so allows for additional cross-object optimization.
Regards, Ronan
I've re-enabled the LTO and it's still working perfectly.