Retained Memory Not Working Correctly

argon
boron
Tags: #<Tag:0x00007f03907c3c70> #<Tag:0x00007f03907c3978>

#1

I am attempting to use the retained memory feature on a boron and argon (Tested firmware 0.8.0-rc.26 and rc.27) but the results are not as expected. It appears that the values are initializing incorrectly, but are being stored correctly following an increment. I tested a variety of data types and they all exhibit the same pattern. However, if I flash the same code to a photon, then everything works as expected (Values start at 0 with a fresh power up and are incremented on each reset).
NOTE: I used the web IDE for the testing to rule out firmware issues on my end.

The code:

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY)); 

retained uint8_t retTest1 = 0;
retained int8_t retTest2 = 0;
retained uint16_t retTest3 = 0;
retained int16_t retTest4 = 0;
retained uint32_t retTest5 = 0;
retained int32_t retTest6 = 0;
retained float retTest7 = 0;

void setup() {
	Serial.begin();
	
	// Wait so we can catch the output
	delay(10000);
	
	// Output test retained variables
	Serial.println(retTest1++);
	Serial.println(retTest2++);
	Serial.println(retTest3++);
	Serial.println(retTest4++);
	Serial.println(retTest5++);
	Serial.println(retTest6++);
	Serial.println(retTest7); retTest7 += 1.5f;
	Serial.println("Done 3"); // Change this with each flash so I know it took
}

void loop() {
    Serial.println("Looping");
    delay(1000);
}

Here are the results. I first unplugged USB (No battery used), waiting a few seconds, plugged it back in, then clicked the “reset” button twice to get the following outputs.

// Power up
152
5
30116
-1189
209993728
-2047084961
ovf
Done 3
Looping
Looping
...

// Reset 1
153
6
30117
-1188
209993729
-2047084960
ovf
Done 3
Looping
Looping
...

// Reset 2
154
7
30118
-1187
209993730
-2047084959
ovf
Done 3
Looping
Looping
...

Any ideas?


#2

Currently Backup RAM isn’t even documented for the mesh devices, which suggests it’s not yet correctly implemented

https://docs.particle.io/reference/device-os/firmware/photon/#backup-ram-sram- (leads to the topic)
vs.
https://docs.particle.io/reference/device-os/firmware/argon/#backup-ram-sram- (doesn’t)

The Photon docs also talk about possible issues with initialisation when the VBAT pin is floating.

I think retained variables are somehow related to the not yet implemented sleep modes.


#3

Ah good eye!

On a related note, is it safe to assume the RTC will not restore its time correctly? Getting the clock to correctly maintain time across resets (With a battery plugged in and without network use) is what brought me down this path.


#4

I’d have to check that myself.