<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Retained register</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/124058/retained-register</link><description>Hi, 
 I need to save a 16 bit counter into a retained register. 
 I cannot use the 2 GPRETREG since they are already used and I cannot write internal flash. 
 I cannot use RAM retained. 
 Is there any other register suitable for this purpose?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 07 Jan 2026 20:53:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/124058/retained-register" /><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/558215?ContentTypeID=1</link><pubDate>Wed, 07 Jan 2026 20:53:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74f35978-9a15-407b-a70e-840bd0813c77</guid><dc:creator>Gmrck</dc:creator><description>&lt;p&gt;Thanks a lot, Einar! It works for me this way.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/557936?ContentTypeID=1</link><pubDate>Mon, 05 Jan 2026 14:03:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8289de80-5a34-4600-8db0-14af25c40c09</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I see. That should not matter though, and I also have no problems when I test like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/* main.c - Application main entry point */

/*
 * Copyright (c) 2015-2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr/types.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;
#include &amp;lt;zephyr/sys/util.h&amp;gt;

#include &amp;lt;zephyr/bluetooth/bluetooth.h&amp;gt;
#include &amp;lt;zephyr/bluetooth/hci.h&amp;gt;

#include &amp;lt;hal/nrf_power.h&amp;gt;

int main(void)
{
	int err;

	printk(&amp;quot;Starting Beacon Demo\n&amp;quot;);

	/* Initialize the Bluetooth Subsystem */
	err = bt_enable(NULL);
	if (err) {
		printk(&amp;quot;Bluetooth init failed (err %d)\n&amp;quot;, err);
	}

	printk(&amp;quot;GPREGRET0: 0x%08X\n&amp;quot;, nrf_power_gpregret_get(NRF_POWER, 0));
	printk(&amp;quot;GPREGRET1: 0x%08X\n&amp;quot;, nrf_power_gpregret_get(NRF_POWER, 1));

	return 0;
}

static int retention_registers_increment(void)
{
	uint32_t gpregret0_val = nrf_power_gpregret_get(NRF_POWER, 0);
	uint32_t gpregret1_val = nrf_power_gpregret_get(NRF_POWER, 1);

	gpregret0_val++;
	gpregret1_val++;

	nrf_power_gpregret_set(NRF_POWER, 0, gpregret0_val);
	nrf_power_gpregret_set(NRF_POWER, 1, gpregret1_val);

	return 0;
}

SYS_INIT(retention_registers_increment, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/557601?ContentTypeID=1</link><pubDate>Tue, 23 Dec 2025 19:43:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:48bd6ae8-a3ff-462d-b9cb-070d050b6645</guid><dc:creator>Gmrck</dc:creator><description>&lt;p&gt;Hi, Einar,&lt;br /&gt;&lt;br /&gt;Thanks for your answer. I think the only difference of your code and mine is that you access the registers in your main function on the APPLICATION stage, but in my case I&amp;#39;ve accessed them in a function which is run on a PRE_KERNEL_1 stage.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/557244?ContentTypeID=1</link><pubDate>Wed, 17 Dec 2025 15:20:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c78dd9d-308b-4916-9d02-f99750b8caf2</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am sorry for the late reply.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Normally both GPREGRET registers are available and usable. I tested with a modified beacon sample from SDK 3.2 with updated main function like this and see that both are&amp;nbsp;incremented as expected after reset, without any errors. If this still do not work on your end, we need to look more closely at what you do in your design.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;hal/nrf_power.h&amp;gt;

int main(void)
{
	int err;

	printk(&amp;quot;Starting Beacon Demo\n&amp;quot;);

	uint32_t gpregret0_val = nrf_power_gpregret_get(NRF_POWER, 0);
	uint32_t gpregret1_val = nrf_power_gpregret_get(NRF_POWER, 1);

	/* Initialize the Bluetooth Subsystem */
	err = bt_enable(bt_ready);
	if (err) {
		printk(&amp;quot;Bluetooth init failed (err %d)\n&amp;quot;, err);
	}

	printk(&amp;quot;GPREGRET0: 0x%08X\n&amp;quot;, gpregret0_val);
	printk(&amp;quot;GPREGRET1: 0x%08X\n&amp;quot;, gpregret1_val);

	gpregret0_val++;
	gpregret1_val++;

	nrf_power_gpregret_set(NRF_POWER, 0, gpregret0_val);
	nrf_power_gpregret_set(NRF_POWER, 1, gpregret1_val);

	return 0;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556593?ContentTypeID=1</link><pubDate>Tue, 09 Dec 2025 17:14:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:923b5e64-4a09-41bc-941e-4dff44455963</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;As an aside, note there are other registers which are retained and could be used for data when the associated peripheral is not used on a particular design (taking care to avoid side-effects of course). Some mapping is required as the bits within the registers are not contiguous. Retained registers on the nRF52832:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;GPIO: The PIN_CNF registers are retained registers&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;LPCOMP: All LPCOMP registers, including ENABLE, are classified as retained registers when the LPCOMP is enabled. However, when the device wakes up from System OFF, all LPCOMP registers will be reset&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556542?ContentTypeID=1</link><pubDate>Tue, 09 Dec 2025 10:08:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3bf5b68f-d6ec-4de3-a306-242e66f136c8</guid><dc:creator>Gmrck</dc:creator><description>&lt;p&gt;Hi, Einar,&lt;br /&gt;&lt;br /&gt;Thanks for the hint. It indeed makes sense to have a single API function for that. &lt;br /&gt;Quick question though: the reg number is 0 and 1, right? Where 0 stands for GPREGRET1 and 1 for GPREGRET2? Seems logical, but wanted to confirm.&lt;br /&gt;Are there any restrictions on when GPREGRET2 becomes available boot cycle-wise? I&amp;#39;ve tried the direct access to it at PRE_KERNEL_1 stage, and it wasn&amp;#39;t available - the app hung, while the GPREGRET1 was accessible and I was able to write into it. As far as I know the GPREGRET1 is used by the DFU, while GPREGRET2 is free for use with no chance of it being used by any internal nordic things, like DFU, correct?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556521?ContentTypeID=1</link><pubDate>Tue, 09 Dec 2025 08:09:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b3f0ec0-1798-497e-8200-75c4ab9c3545</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I see. That is not the case, though. If you compare the old&amp;nbsp;nrf_power_gpregret_set() and&amp;nbsp;nrf_power_gpregret2_set() you can see it takes two parameters. The new &lt;a href="https://docs.nordicsemi.com/bundle/nrfx-apis-3.1.1/page/group_nrf_power_hal.html#ga29711581b57c9223bb2286d39690ef65"&gt;nrf_power_gpregret_set()&lt;/a&gt;&amp;nbsp;takes three parameters, where one is the register number. So instead of having separate API functions for each GPREGRET register, the same is used for all.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556496?ContentTypeID=1</link><pubDate>Mon, 08 Dec 2025 16:11:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e697ac6-4047-433f-b836-24d7d1a7c7e3</guid><dc:creator>Gmrck</dc:creator><description>&lt;p&gt;Thanks for the confirmation, Einar. It is just confusing, that we do have nrfx functions for one, but not for another, which made me thinking the support for the GPREGRE2 was dropped. Especially, that there is a line &lt;br /&gt;&amp;quot;&lt;span&gt;This register is not available in all MCUs.&lt;/span&gt;&amp;quot; &lt;br /&gt;in the&amp;nbsp;&lt;a id="" href="https://docs.nordicsemi.com/bundle/ncs-2.0.1/page/nrfx/drivers/power/hal.html"&gt;https://docs.nordicsemi.com/bundle/ncs-2.0.1/page/nrfx/drivers/power/hal.html&lt;/a&gt;&amp;nbsp;documentation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556492?ContentTypeID=1</link><pubDate>Mon, 08 Dec 2025 15:46:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:912b8420-ab9f-4d68-b19c-c99e7a0c896e</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;It does not specifically mention gpregret1 or gpregret2 in the API documentation, but both are there (gpregret2 &lt;a href="https://github.com/zephyrproject-rtos/hal_nordic/blob/0dbbf4794156ca09dc2d4bad8c42dcdb54acd662/nrfx/bsp/stable/mdk/nrf52_bitfields.h#L7700-L7703"&gt;here&lt;/a&gt;).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556490?ContentTypeID=1</link><pubDate>Mon, 08 Dec 2025 15:35:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a4360038-0c5e-4ed3-821d-f759bdde2c0e</guid><dc:creator>Gmrck</dc:creator><description>&lt;p&gt;This documentation doesn&amp;#39;t have any mentioning of the GPREGRET2:&lt;br /&gt;&lt;br /&gt;&lt;a id="" href="https://docs.nordicsemi.com/bundle/nrfx-apis-latest/page/group_nrf_power_hal.html"&gt;https://docs.nordicsemi.com/bundle/nrfx-apis-latest/page/group_nrf_power_hal.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;While&amp;nbsp;the earlier version of SDK documentation has it mentioned here&lt;br /&gt;&lt;a id="" href="https://docs.nordicsemi.com/bundle/ncs-2.0.1/page/nrfx/drivers/power/hal.html"&gt;https://docs.nordicsemi.com/bundle/ncs-2.0.1/page/nrfx/drivers/power/hal.html&lt;/a&gt;&lt;br /&gt;as functions to access the value:&lt;br /&gt;&lt;span class="pre"&gt;NRF_STATIC_INLINE&lt;/span&gt;&lt;span class="w"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="kt"&gt;&lt;span class="pre"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span class="w"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="sig-name descname"&gt;&lt;span class="n"&gt;&lt;span class="pre"&gt;nrf_power_gpregret2_set&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="sig-paren"&gt;(&lt;/span&gt;&lt;span class="n"&gt;&lt;span class="pre"&gt;NRF_POWER_Type&lt;/span&gt;&lt;/span&gt;&lt;span class="w"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="p"&gt;&lt;span class="pre"&gt;*&lt;/span&gt;&lt;/span&gt;&lt;span class="n"&gt;&lt;span class="pre"&gt;p_reg&lt;/span&gt;&lt;/span&gt;&lt;span&gt;,&amp;nbsp;&lt;/span&gt;&lt;span class="n"&gt;&lt;span class="pre"&gt;uint8_t&lt;/span&gt;&lt;/span&gt;&lt;span class="w"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="n"&gt;&lt;span class="pre"&gt;val&lt;/span&gt;&lt;/span&gt;&lt;span class="sig-paren"&gt;)&lt;/span&gt;&lt;br /&gt;and&lt;br /&gt;&lt;span class="pre"&gt;NRF_STATIC_INLINE&lt;/span&gt;&lt;span class="w"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="n"&gt;&lt;span class="pre"&gt;uint8_t&lt;/span&gt;&lt;/span&gt;&lt;span class="w"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="sig-name descname"&gt;&lt;span class="n"&gt;&lt;span class="pre"&gt;nrf_power_gpregret2_get&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="sig-paren"&gt;(&lt;/span&gt;&lt;span class="n"&gt;&lt;span class="pre"&gt;NRF_POWER_Type&lt;/span&gt;&lt;/span&gt;&lt;span class="w"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="k"&gt;&lt;span class="pre"&gt;const&lt;/span&gt;&lt;/span&gt;&lt;span class="w"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="p"&gt;&lt;span class="pre"&gt;*&lt;/span&gt;&lt;/span&gt;&lt;span class="n"&gt;&lt;span class="pre"&gt;p_reg&lt;/span&gt;&lt;/span&gt;&lt;span class="sig-paren"&gt;)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;This is where the confusion comes, as in the latest documentation of SDK or nrfx I am not able to see any mentioning of gpregret2 as a register or any mentioning of a function to use to write to this register.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556488?ContentTypeID=1</link><pubDate>Mon, 08 Dec 2025 15:20:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65d1ccb3-7077-472b-a25e-298489384bfb</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;From what I can see&amp;nbsp;&lt;span&gt;GPREGRET2 is defined also in the latest SDK version.&amp;nbsp;&lt;/span&gt;Can you clarify exactly where you see&amp;nbsp;GPREGRET2 missing (file and line) and which versions you are comparing?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556485?ContentTypeID=1</link><pubDate>Mon, 08 Dec 2025 15:08:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ecc025d-3dd7-42e5-b5a5-fbb0b2f3f494</guid><dc:creator>Gmrck</dc:creator><description>&lt;p&gt;Einar, btw, what has changed to the GPREGRET2 in the nrfx library? I no longer see it or its functions there in the latest version. Though, the board files have both gpregret and gpregret2 as the devices available in the device tree.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556465?ContentTypeID=1</link><pubDate>Mon, 08 Dec 2025 13:51:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33ee25e3-a8e7-418b-b619-96619ebc8c62</guid><dc:creator>Gmrck</dc:creator><description>&lt;p&gt;Thanks, Einar. I guess this is exactly what I was looking for.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556430?ContentTypeID=1</link><pubDate>Mon, 08 Dec 2025 09:55:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3adab1e7-c82d-43e7-b241-54ce5a5deb8f</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please see &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/124732/does-nrf-connect-sdk-support-gpregret-on-nrf5340dk/550609"&gt;this post&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/556402?ContentTypeID=1</link><pubDate>Sun, 07 Dec 2025 12:11:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7800a21-3bee-4e88-ac32-d97e11703def</guid><dc:creator>Gmrck</dc:creator><description>&lt;p&gt;Hi, Einar! Are there any examples of how to write &amp;amp; read to &amp;amp; from the GPREGRET2 register the best way in nrfConnect SDK 3.0?&lt;br /&gt;This works for me:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;NRF_POWER&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;GPREGRET&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gpregretValue;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;However, as soon as it is:&lt;br /&gt;&lt;br /&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;NRF_POWER&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;GPREGRET2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;gpregretValue;&lt;br /&gt;&lt;br /&gt;The program doesn&amp;#39;t go into the main loop, so I guess it is failing with this one. I am on nrf52840DK the latest revision.&lt;br /&gt;I do this on&amp;nbsp;PRE_KERNEL_1 level.&lt;br /&gt;&lt;br /&gt;Could you please share the best practices of handling these registers? The nrfx HAL contained some functions for that, but I believe they were dropped closer to SDK 3.0. And I can&amp;#39;t find anything in the latest documentation on it.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Retained register</title><link>https://devzone.nordicsemi.com/thread/547487?ContentTypeID=1</link><pubDate>Tue, 02 Sep 2025 12:56:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5db5ea13-644d-457e-bd11-f6d1e378e8e8</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The GPREGRET registers are the only supported way to retain data that is not in flash during a reset. Other than that, the only approach that works reliably is to store the data in flash. However, you can also store data data in non-initialized RAM together with a checksum and read that data after reset. If the checksum is valid, it can be used. In most cases this will be fine, as the RAM content is never cleared by a reset, it is just not guaranteed to be intact. Note however that if you have a bootloader that runs first, you must make sure that this does not use the same memory region as that would overwrite it during boot. See &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/108439/avoid-nonit-region-to-be-overridden-by-mcuboot/470158"&gt;this thread&lt;/a&gt; for details about that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>