Zephyr retention module not working; can't read back

Hi,

I'm troubling using the retention module of Zephyr with NCS 2.6.1 on an NRF52840. I've read the Retention System Documentation of Zephyr but it is not working for me. Here is what I've done:

I've enabled in proj.conf:

CONFIG_RETENTION=y
CONFIG_RETAINED_MEM=y
CONFIG_RETENTION_MUTEX_FORCE_DISABLE=y
CONFIG_RETAINED_MEM_MUTEX_FORCE_DISABLE=y

My decive tree overlay:

/ {
	sram@2003FC00 {
			compatible = "zephyr,memory-region", "mmio-sram";
			reg = <0x2003FC00 DT_SIZE_K(1)>;
			zephyr,memory-region = "RetainedMem";
			status = "okay";

			retainedmem {
					compatible = "zephyr,retained-ram";
					status = "okay";
					#address-cells = <1>;
					#size-cells = <1>;

					/* This creates a 256-byte partition */
					retention0: retention@0 {
							compatible = "zephyr,retention";
							status = "okay";
							reg = <0x0 0x400>;
					};

			};
	};
};

&sram0 {
	reg = <0x20000000 DT_SIZE_K(255)>;
};

My code:

const static struct device *retention0 = DEVICE_DT_GET(DT_NODELABEL(retention0));

int main(void) {
	static uint32_t retention_var = 1234;
	LOG_INF("Print variable before write: %d", retention_var);

	int rc = retained_mem_write(retention0, 0, (uint8_t*) &retention_var, 4);
	if(rc) {
		LOG_INF("Error write: %d", rc);
	}
	LOG_INF("Print variable after write but before read: %d", retention_var);

	rc = retained_mem_read(retention0, 0, (uint8_t*) &retention_var, 4);
	if(rc) {
		LOG_INF("Error read: %d", rc);
	}
	LOG_INF("Print variable after read: %d", retention_var);
}

The output is:
[00:00:00.027,648] <inf> app: Print variable before write: 1234
[00:00:00.028,137] <inf> app: Print variable after write but before read: 0
[00:00:00.028,625] <inf> app: Error read: -134
[00:00:00.029,022] <inf> app: Print variable after read: 0

So it seams the variable is cleared on writing, and I cannot read it back due to an error

The error -134 in errno.h means:
#define ENOTSUP 134     /* Not supported */


Can anyone help me pls; I'm no sure what I'm doing wrong.

Thanks and Best Regards,
Phobios

Related