cancel
Showing results for 
Search instead for 
Did you mean: 

The NOLOAD section variable initializes with garbage value on hard reset.

DVasa.1
Associate II

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.

14 REPLIES 14
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

You'll need to use the RCC->CSR flags to get the functionality you want. The default startup scripts can not do this.

If you feel a post has answered your question, please click "Accept as Solution".

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.

Why doesn't using the BOR flag here work? Do you expect drops in voltage below 1.71V normally?
If you feel a post has answered your question, please click "Accept as Solution".
DVasa.1
Associate II

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.