2019-04-18 05:19 AM
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 ?
Solved! Go to Solution.
2019-04-18 05:40 AM
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
2019-04-18 05:40 AM
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
2019-04-18 05:42 AM
You can use the RTC backup registers instead of RAM.
2019-04-18 07:32 AM
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.
2019-04-18 08:09 AM
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.
2019-04-19 12:39 AM
Thank you so much for usefull advices.Helped a lot.Have a nice day.