Is retained memory supported on Gen 3 devices? It is not mentioned in the Gen 3 docs, but appears to work although not as described in the Gen 2 docs and there is no longer any VBAT pin. Any risks if I use it? I am hoping to use @rickkas7 PublishQueueAsyncRK library on a Boron and this relies on retained memory.
Retained memory and Gen 3 has been mentioned previously but with no follow up for a few months:
- https://community.particle.io/t/retained-memory-not-working-correctly/46869
- https://community.particle.io/t/issue-workbench-intellisense-no-storage-class/44620
As an example, the following code continues incrementing the prior loopCount after a reset, but starts with a random number (not the declared 0) after a power down. The initialisation is not really a problem as it can be initialised separately by checking the reset reason.
#include "Particle.h"
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
SerialLogHandler logHandler;
retained uint8_t loopCount = 0;
const unsigned long PERIOD_MS = 3000;
unsigned long lastCount = 0;
void setup() {
Serial.begin();
}
void loop() {
if (millis() - lastCount >= PERIOD_MS) {
lastCount = millis();
loopCount++;
Log("Loops: %i", loopCount);
}
}