<?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>FDS not saving variables</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60941/fds-not-saving-variables</link><description>NRF52832 on SDK 16.0.0, softdevice s132 (using SES) When writing constant value with FDS it saves normally, but when I try to write variable it saves some garbage. Here is my write function: 
 Any ideas how to fix it?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 03 May 2020 13:39:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60941/fds-not-saving-variables" /><item><title>RE: FDS not saving variables</title><link>https://devzone.nordicsemi.com/thread/247739?ContentTypeID=1</link><pubDate>Sun, 03 May 2020 13:39:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:764d83c7-9503-492e-9e58-ae11ca677e05</guid><dc:creator>zwer97</dc:creator><description>&lt;p&gt;Thanks for your reply! I solved this issue initializing static variable out of write function and now it works. Here is the code&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define FILE_ID     0x1111
#define FILE_KEY     0x2222

static uint32_t data_to_write[3] = {0, 0, 0};

static fds_record_t const m_dummy_record =
{
    .file_id           = FILE_ID,
    .key               = FILE_KEY,
    .data.p_data       = &amp;amp;data_to_write,
    /* The length of a record is always expressed in 4-byte units (words). */
    .data.length_words = (sizeof(data_to_write) + 3) / sizeof(uint32_t),
};

static ret_code_t fds_write_U32()
{
        data_to_write[0] = var1;
        data_to_write[1] = var2;
        data_to_write[2] = var3;
        
		fds_record_desc_t   record_desc;
                				
		ret_code_t ret = fds_record_write(&amp;amp;record_desc, &amp;amp;m_dummy_record);
		if (ret != NRF_SUCCESS)
		{
				return ret;
		}
		NRF_LOG_INFO(&amp;quot;Writing Record ID = %d \r\n&amp;quot;,record_desc.record_id);
		return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS not saving variables</title><link>https://devzone.nordicsemi.com/thread/247734?ContentTypeID=1</link><pubDate>Sun, 03 May 2020 08:46:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7deceaa4-083f-4e90-8366-bc3ff37bd649</guid><dc:creator>Turbo J</dc:creator><description>&lt;p&gt;How do you read the records?&lt;/p&gt;
&lt;p&gt;When&amp;nbsp;fds_record_write() was called twice, you will end up whith &lt;em&gt;two&lt;/em&gt; identical (in id and key) records with possibly different data.&lt;/p&gt;
&lt;p&gt;That is why there is a fds_record_update() function...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Edit: Your m_data[] buffer must not be on the stack, as fds_record_write() is a function with &lt;em&gt;delayed&lt;/em&gt; execution (using softdevice). Due to m_data being on the stack it will be overwritten by the time the softdevice actually writes to flash.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>