cancel
Showing results for 
Search instead for 
Did you mean: 

Do RAM may have old data after energized

emre ozdemir
Associate III

Hi everyone ,

We are using our custom bootloader firmware to update our main firmware.To do that we set a flag at a specific location at RAM and reset the MCU.The flag size is 1 byte.

At the bootloader firmware read the data from RAM and if this data macthes our flag then entering update fırmware function.

After update we clear the data at this RAM location.All this sequence energy is allways ON .

We think when turn off the power all RAM data will be cleared.But some of our devices read this flag after energized.

Is this because of bootloader firmware use this RAM location and set the data same as our Flag or it holds the old data ?

1 ACCEPTED SOLUTION

Accepted Solutions
Danish1
Lead II

At power-on RAM may contain anything. There are no guarantees.

At its lowest level, RAM is just a flip-flop, and it depends which transistor turns on fastest as to which state each bit ends up.

Sometimes (if power was only recently removed and charge has not fully leaked away) some of the bits may contain their pre-power-down values. Others may contain random values, and the probability of 1 or 0 differs from bit to bit, and from chip to chip.

Perhaps you could look at RCC->CSR to see if you had a power-on-reset, and if so ignore your flag in RAM. (But remember to set the value of your flag appropriately before clearing the reset state). For stm32f4 there was an explicit bit RCC_CSR_PORRSTF but I don't see it in stm32l4 so I have to use RCC_CSR_BORRSTF for those devices.

Hope this helps,

Danish

View solution in original post

5 REPLIES 5
Danish1
Lead II

At power-on RAM may contain anything. There are no guarantees.

At its lowest level, RAM is just a flip-flop, and it depends which transistor turns on fastest as to which state each bit ends up.

Sometimes (if power was only recently removed and charge has not fully leaked away) some of the bits may contain their pre-power-down values. Others may contain random values, and the probability of 1 or 0 differs from bit to bit, and from chip to chip.

Perhaps you could look at RCC->CSR to see if you had a power-on-reset, and if so ignore your flag in RAM. (But remember to set the value of your flag appropriately before clearing the reset state). For stm32f4 there was an explicit bit RCC_CSR_PORRSTF but I don't see it in stm32l4 so I have to use RCC_CSR_BORRSTF for those devices.

Hope this helps,

Danish

You can use the RTC backup registers instead of RAM.

Bob S
Principal

Use more than 1 byte for your flag. Perhaps a 32-bit word. Or even better, two 32-bit words, where the 2nd word is the bit-inverse of the first 32-bit word.

And better yet invalidate the content explicitly so it is a one-time use. The code I've been posting here for the best part of a decade does that.

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

Thank you so much for usefull advices.Helped a lot.Have a nice day.