<?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>A nice place to keep a small amount of state data</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/4130/a-nice-place-to-keep-a-small-amount-of-state-data</link><description>Hello Nordic users and employees, 
 I&amp;#39;m having a small dilemma. The device I&amp;#39;m building runs on the nRF51822 and needs to store a small number of bytes off to the side and some will occasionally be modified. However, flash is very precious in my application</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 27 Sep 2016 23:20:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/4130/a-nice-place-to-keep-a-small-amount-of-state-data" /><item><title>RE: A nice place to keep a small amount of state data</title><link>https://devzone.nordicsemi.com/thread/14775?ContentTypeID=1</link><pubDate>Tue, 27 Sep 2016 23:20:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08dcb3e8-5f25-427d-be29-108eabc7b034</guid><dc:creator>shaba</dc:creator><description>&lt;p&gt;This is exactly what we did with our old project as well. Figured it would be similar with the NRF :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A nice place to keep a small amount of state data</title><link>https://devzone.nordicsemi.com/thread/14774?ContentTypeID=1</link><pubDate>Mon, 15 Dec 2014 23:50:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:405e9605-578b-44dc-840c-c7dbb2123666</guid><dc:creator>Moloch</dc:creator><description>&lt;p&gt;Thanks for the replies, somehow I disabled email notifications so I didn&amp;#39;t realize I had any follow-ups! Here&amp;#39;s some resolution:&lt;/p&gt;
&lt;p&gt;I really have two different types of data here.&lt;/p&gt;
&lt;p&gt;The first type is what we call &amp;quot;production values&amp;quot;, like the serial number and hardware revision. These are burned-in at the factory during manufacturing and don&amp;#39;t ever change during normal use. If we accidentally erase these values during development with a prototype, that is unfortunate but not critical. We ended up placing a small memory segment containing these values at a high address above our bootloader in flash, making use of the &amp;quot;slop&amp;quot; between the end of the bootloader and the beginning of the next page of flash.&lt;/p&gt;
&lt;p&gt;The second type of data, which is kind of a &amp;quot;boot mode&amp;quot; flag and some associated data is more volatile, though it has to persist through resets. While it would have made some things easier to keep it in flash, the use of an entire page to store several dozen bytes was too wasteful.&lt;/p&gt;
&lt;p&gt;To keep this data, we carved up a small piece of RAM, just above the S110&amp;#39;s section, and located a struct there holding our values. We also used a &amp;quot;magic number&amp;quot; signature and a checksum, updated at every write to this section, to guarantee the data was valid.&lt;/p&gt;
&lt;p&gt;Then we designed to bootloader to verify a checksum over the application space before executing the application. That way, if we completely lose power and RAM while the application is being updated we know not to execute the corrupt application and instead ask for an OTA update. What this means is we have a fail-safe if the boot mode flags are lost and the system is in a bad state.&lt;/p&gt;
&lt;p&gt;I hope this helps anybody else in a similar situation :).&lt;/p&gt;
&lt;p&gt;Oh, and we would have used the UICR for the static production values, but we determined flash was simpler and we had some available anyway...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A nice place to keep a small amount of state data</title><link>https://devzone.nordicsemi.com/thread/14773?ContentTypeID=1</link><pubDate>Tue, 21 Oct 2014 19:45:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb4ddc63-d050-4aec-90a2-7f144650ae9e</guid><dc:creator>Dan Danknick</dc:creator><description>&lt;p&gt;My first answer was to use the GPREGRET register as Stefan mentioned but, of course, it is just one byte and the Nordic bootloader uses it. It is RAM backed.&lt;/p&gt;
&lt;p&gt;A sneaky but similar technique is to use GPIO configuration registers for unassigned pins. They are preserved on sleep as long as power is not removed.&lt;/p&gt;
&lt;p&gt;Dan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A nice place to keep a small amount of state data</title><link>https://devzone.nordicsemi.com/thread/14772?ContentTypeID=1</link><pubDate>Tue, 21 Oct 2014 14:39:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5003c8c-75f0-48b6-abde-799299da5f43</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I do not think it is possible to use the UICR to store application data that occasionally needs to be updated. You can write once to the &amp;quot;user reserved data&amp;quot; region of the UICR (addresses 0x10001080 - 0x100010FC), but in order to write again, you need to erase the whole UICR. As described in the nRF51 Reference Manual, chapter for NVMC, when erasing UICR, you also delete the whole code area, i.e. application and bootloader.&lt;/p&gt;
&lt;p&gt;The only retained register is the GPREGRET, which can store one byte. In fact this register is used by the latest bootloader in nRF51 SDK v6.1.0. The latest heart rate example in SDK 6.1.0 includes a bootloader service that you can write to in order to enable bootloader mode from a central device, which is convenient for devices that do not have a button to enable the bootloader mode. The application will write 0xB1 (if I remember correctly) to the GPREGRET register and then restart the device. The bootloader check for value 0xB1 when it starts up and goes into bootloader mode if the value is there.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 22.10.2014&lt;/strong&gt;
So I guess the conclusion is that the only place to store nonvolatile storage is the 256kB of flash. Have you already utilized all the flash, so there is no space left for these few bytes? Have you compressed the bootloader and your application, in order to consume less flash space?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>