Hi guys, we are having trouble updating a batch of devices where we have significantly changed SRAM variables. After update they tend to panic reset. We can catch this and boot to safe mode but of course SRAM is retained. As they are located around the country plus covid, it will be difficult to power them off. Is there an easy way to programmatically clear the SRAM and start afresh?
Ideally looking for something similar to EEPROM.clear()
Otherwise do you think something like this should work?
Before using the data you check that retainedData.magic == RETAINED_MAGIC. If data was uninitialized, the magic won’t match and you know you need to reinitialize. When you update the firmware, you change the magic bytes to make sure the data get reinitialized.
It’s also not a bad idea to put the sizeof(RetainedData) in the struct, which takes care of the case that you added a retained member and forgot to change the magic bytes.
@rickkas7 Oh that is a fine solution! Plus it helps to keep track of all the retained variables scattered around the code.
Then to reset, it would be a case of using memset(&retainedData, 0, sizeof(retainedData)); right?
I’m sure there will be times we forget to change the magic number. I hesitate to attempt to improve it by setting it to __system_product_version so it changes automatically
Or/and use a checksum variable like @ScruffR suggested.