2021-07-29 06:05 AM
Hi ST team,
I want to define a new section in the ld script so I can use that for variables that have to keep their values in case of soft resets.
I have made some changes in the script as follows,
.noinit (NOLOAD):
{
. = ALIGN(4);
_noinit = .;
*(.noinit .noinit.*)
. = ALIGN(4) ;
_end_noinit = .;
} >RAM
I have also defined a variable of this kind in the following way,
uint32_t tempVar __attribute__ ((section(".noinit"))) = 0;
At every soft reset, the value of this variable is preserved. However, at every hard reset, the variable is initialized with some garbage value.
What am I missing here?
Thank you.
Solved! Go to Solution.
2021-08-02 06:46 AM
If you write to RAM, it'll stay there until you change it or it loses power. Many sections of RAM are initialized on startup and the NOLOAD is a way of skipping that initialization. You could do what NOLOAD does manually, or put the variable in a place in RAM which isn't touched or known about by the linker. However, if NOLOAD solves your problem, I don't know why you'd avoid using it.
2021-08-02 06:50 AM
You'll need to use the RCC->CSR flags to get the functionality you want. The default startup scripts can not do this.
2021-08-02 07:07 AM
We are using STM32l562CEU6. So in our case, there is no POR-related flag. But there is a BORRST flag. And default value of the VDD cut-off for BOR is 1.71V.
I kept a check of the previous reset condition using the RCC_FLAG_SFTRST and RCC_FLAG_BORRST with __HAL_RCC_GET_FLAG(__FLAG__) API. But If I give a pulse on the NRST pin of the MCU or power cycle the MCU, I can not differentiate using the flag check.
2021-08-02 07:18 AM
2021-08-03 01:30 AM
Using the RCC->CSR register flags, we were able to handle the scenario properly. What we were missing here was clearing the reset flags.
Thank you.