Retained variables are not supported on core

Hello,

I’m trying to get the attached code using retained variables to compile, but it is giving me a “retained variables are not supported on the core” error:

SYSTEM_MODE(MANUAL);

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));

retained int value = 10;

void setup() {
Serial.begin(9600);
}

void loop() {
delay(5000);
Serial.println(“I’m awake!”);
Serial.println(value);
value = value + 1;
delay(2000);
Serial.println(“I’m going to sleep!”);
System.sleep(SLEEP_MODE_DEEP, 10);
}

I’m working in the web IDE, and have double checked that the firmware both targeted and on the device is 0.5.3. Here’s the error I’m getting:

…/hal/src/core/platform_headers.h:27:18: error: static assertion failed: retained variables are not supported on the Core
#define retained static_assert(1==0, “retained variables are not supported on the Core”);
^

Well, that pretty much says it anyway.

The Spark Core does not support retained variables, since it also has no VBAT pin to buffer the retained RAM.

You won’t find such a link for the Core
https://docs.particle.io/reference/firmware/photon/#backup-ram-sram-
https://docs.particle.io/reference/firmware/electron/#backup-ram-sram-

2 Likes

Thanks for ScruffR.

What’s the difference between Spark Core and Electron? This code was working fine earlier yesterday, but now nothing with retained variables compiles (I get the same error for all code fragments with retained variables). Is there a setting telling the compiler to use Core instead of Electron?

In case it’s useful, I’m trying to get this code running on the Electron.

The Electron, Photon and P1 are based on an STM32F205RG µC while the Spark Core uses an STM32F103CB which doesn’t sport that feature.

So no compiler switch will be able to alter the hardware.
But the target device setting tells the compiler what hardware (Core, Photon, P1, Electron, RPi, …) to build for and hence what features are available or not.

That’s the confusing thing. I only have Electrons (no Spark Cores), which I’ve confirmed by navigating to the devices tab in the Web IDE and only seeing only Electrons listed.

The code was compiling (and working fine) yesterday on my Electrons, but I’m now receiving compiler errors saying the target hardware isn’t an Electron.

Can you post a screenshot of your Web IDE with the targets drawer open?

Sure thing.

There should be a star symbol next to your devices (unless you inly have one) and the star of the target device should be golden.
Like here

To tag a device, hover with the mouse just left of the device name, which should reveal the star and then click it.

Ah ha–that did the trick. Thanks ScruffR!

I really appreciate your help on this.