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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

You can look at the RCC->CSR register to determine the source of the reset and handle them differently, if you want.

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

View solution in original post

14 REPLIES 14

>>What am I missing here?

Ordering, what startup.s is actually doing, and the scope of the beginning/ending symbols in reality.

Watch also for where stack falls, or other code running, ie loader or system loader.

Content will be random at power-up.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

What does a soft reset vs hard reset mean here? RAM won't be preserved on a power cycle.

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

Hi Tesla DeLorean,

"Content will be random at power-up."

So, the content of that variable will be garbage at power-up, right?

Is there any way to prevent that from happening? Can we initialize it on power-up or something?

DVasa.1
Associate II

Hi TDK,

What I mean by hard reset is the power cycle of the MCU. And by soft reset, I mean that giving reset pulse on the MCU using the reset switch.

You can write whatever value you want to it. But then it's not really NOLOAD any longer. If you need it to default to a value on powerup, NOLOAD is not what you want.
If you feel a post has answered your question, please click "Accept as Solution".
TDK
Guru

You can look at the RCC->CSR register to determine the source of the reset and handle them differently, if you want.

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

Is it possible to initialize a variable on the power cycle, but preserve it on soft resets in RAM memory only?

Is there any other way than NOLOAD?

And regarding the RCC->CSR register;

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.

Am I missing something here?

>>Is it possible to initialize a variable on the power cycle, but preserve it on soft resets in RAM memory only? Is there any other way than NOLOAD?

Not via magic. NOLOAD means that the linker/startup code leave it alone..

You could use a signature and check over the content to determine if you want to keep the data or memset() it to zero.

What's the end-goal/purpose you're trying to achieve here? Any NV/BKP RAM in this part? Battery backup for RTC/BKP in design?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
DVasa.1
Associate II

What we want here is that a variable should be initialized with a specific value at every power cycle. At run time the value of the variable will be updated. But at every soft reset( i.e; pulse on NRST pin of the MCU), it should be preserved.