<?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>how to save data in flash memory?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/63625/how-to-save-data-in-flash-memory</link><description>I am using SDK v16, SEGGER to program on my nrf52832 SOC for our project. I need to save a few variables to the flash memory. These variables will hold the status of the device and they keep on getting updated once a day at least so that when the network</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 10 Jul 2020 13:30:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/63625/how-to-save-data-in-flash-memory" /><item><title>RE: how to save data in flash memory?</title><link>https://devzone.nordicsemi.com/thread/259463?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2020 13:30:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63f8f589-12fc-4966-85be-34499722844b</guid><dc:creator>snoopy20</dc:creator><description>&lt;p&gt;Are you using softdevice? If so the routines are async. Be aware the flash has about a 10,000 write limit.&lt;br /&gt;&lt;br /&gt;Assuming you&amp;#39;re using softdevice you have to first block of a page of memory in your flash_placement.xml at the appropriate space. Check out the memory map documentation for your device to pick it.&lt;br /&gt;&lt;br /&gt;&amp;lt;ProgramSection load=&amp;quot;No&amp;quot; keep=&amp;quot;Yes&amp;quot; name=&amp;quot;.appSettings&amp;quot; start=&amp;quot;$(FLASH_APPSETTINGS_START)&amp;quot; size=&amp;quot;$(FLASH_APPSETTINGS_END)-$(FLASH_APPSETTINGS_START)&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;The values of FLASH_APPSETTINGS_END and FLASH_APPSETTINGS_START go into your preprocessor definition in Project settings.&lt;br /&gt;&lt;br /&gt;I think most use fstorage to do the flash operations as under the hood it takes care of the async method for softdevice (which is a queue). Follow the project in sdk examples to get started. Basically its:&lt;br /&gt;&lt;br /&gt;NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) = {&lt;br /&gt;&lt;br /&gt;&amp;nbsp; .evt_handler = fstorage_evt_handler,&lt;br /&gt;&amp;nbsp; .start_addr = FLASH_APPSETTINGS_START,&lt;br /&gt;&amp;nbsp; .end_addr&amp;nbsp;&amp;nbsp; = FLASH_APPSETTINGS_END,&lt;br /&gt;};&lt;/p&gt;
&lt;p&gt;inline void CONFIG_Init (void) {&lt;br /&gt;&lt;br /&gt;&amp;nbsp; (void) nrf_fstorage_init(&amp;amp;fstorage, &amp;amp;nrf_fstorage_sd, NULL);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;void writer (void) {&lt;/p&gt;
&lt;p&gt;&amp;nbsp; (void) nrf_fstorage_erase(&amp;amp;fstorage, fstorage.start_addr, 1, NULL);&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp; (void) nrf_fstorage_write(&amp;amp;fstorage, fstorage.start_addr, &amp;amp;config, sizeof(config), NULL);&lt;/p&gt;
&lt;p&gt;}&lt;br /&gt;&lt;br /&gt;In your main loop decide what to do while the op is working, like stop accepting new commands, reset a ble char flag to let the app know it can continue etc.&lt;br /&gt;&lt;br /&gt;while(1) { if (nrf_fstorage_is_busy(&amp;amp;fstorage)) { ... }&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to save data in flash memory?</title><link>https://devzone.nordicsemi.com/thread/259460?ContentTypeID=1</link><pubDate>Fri, 10 Jul 2020 13:26:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f22ec0e-f4be-47ba-9cdf-50eaa530229e</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;For that purpose, I would suggest to use the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Flib_fds.html"&gt;Flash Data Storage (FDS)&lt;/a&gt; module from the SDK. Your use case sounds like exactly the use case that FDS was made for.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>