2021-02-23 09:03 AM
Hi Team,
I want to retain a value of variable after software reset
i tried __no_init but variable was resetting to zero
Is there any way i can write into Flash during runtime and fetch it back after reset
Thanks,
Krupashankar
Solved! Go to Solution.
2021-02-23 10:26 AM
It works with gcc like this:
in .c:
int no_init __attribute__ ((section (".no_init")));
in linker description file .ld add a section before heap+stack:
.no_init :
{
*(.no_init)
} > RAM
For testing:
printf("no_init: %d\n", no_init );
no_init++;
HAL_Delay(100);
NVIC_SystemReset();
Redirect printf to an UART or such and watch no_init variable being incremented after each reset.
hth
KnarfB
2021-02-23 09:53 AM
The processor doesn't clear the memory.
Check what your startup.s code is doing, and perhaps shrink the memory visible to the linker if you need to place it outside that scope.
Yes you can write data into FLASH, there are examples in the HAL trees for assorted boards. Memory will need to be erased prior to writing, so often better to journal the variable, or structure holding retained data, across the flash page/sector.
2021-02-23 10:26 AM
It works with gcc like this:
in .c:
int no_init __attribute__ ((section (".no_init")));
in linker description file .ld add a section before heap+stack:
.no_init :
{
*(.no_init)
} > RAM
For testing:
printf("no_init: %d\n", no_init );
no_init++;
HAL_Delay(100);
NVIC_SystemReset();
Redirect printf to an UART or such and watch no_init variable being incremented after each reset.
hth
KnarfB
2021-03-02 08:14 PM
Thank you:smiling_face_with_smiling_eyes: