<?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 initial state</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20664/fds-initial-state</link><description>Hi,
Id like to understand the FDS state after flashing the device. Im trying to check if the record exists then I use it, otherwise I write a valid info into the record.
For some reason after flashing the record always exists, but obviously with some</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Mar 2017 09:01:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20664/fds-initial-state" /><item><title>RE: FDS initial state</title><link>https://devzone.nordicsemi.com/thread/80572?ContentTypeID=1</link><pubDate>Wed, 29 Mar 2017 09:01:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c70fc72-82b5-4daf-b795-62d4350fcd60</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Where in your code will &amp;quot;FDS init completed&amp;quot; be printed? If you run the chip in debug mode, you can check the program flow, and perhaps get some more insight in why &amp;quot;FDS init completed&amp;quot; is printed twice.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS initial state</title><link>https://devzone.nordicsemi.com/thread/80575?ContentTypeID=1</link><pubDate>Tue, 28 Mar 2017 15:08:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae871ce6-bec1-44d0-9f75-961dc3539442</guid><dc:creator>Sergy</dc:creator><description>&lt;p&gt;Thanks Kristen, first question is clear. For the second one you can see lines &amp;quot;FDS Init completed1&amp;quot; twice so callback was called twice?&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS initial state</title><link>https://devzone.nordicsemi.com/thread/80574?ContentTypeID=1</link><pubDate>Tue, 28 Mar 2017 07:29:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4195782c-9d5a-486e-a12c-801dd1d74711</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; &lt;em&gt;then the printout always shows the first BT address that I wrote in memory, but not the second one&lt;/em&gt;:&lt;/p&gt;
&lt;p&gt;Do you mean that the printout always shows the oldest record and not the one that was newly written? If you want to update the data of a record, you should use fds_record_update(). If you write to a FILE with a given RECORD_KEY, and that file and record key already exists, there will be two records with the same record key in the same file. From what I can see in fdsRead(), it only calls fds_record_find() once, so it will only find the first instance for a given record key.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; How do you see that the FDS init callback gets called twice?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS initial state</title><link>https://devzone.nordicsemi.com/thread/80576?ContentTypeID=1</link><pubDate>Sat, 25 Mar 2017 22:03:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:170f3959-dd50-4b9c-9443-575e499afdb3</guid><dc:creator>Sergy</dc:creator><description>&lt;p&gt;Hi Kristin,&lt;/p&gt;
&lt;p&gt;I attached a printout from my program. It waits till FDS is initialized then it writes to a record and then it reads from it, Question is Why FDS Init callback gets called twice? Actually its called once at the first program run and after I reboot device it gets called twice. Any idea?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS initial state</title><link>https://devzone.nordicsemi.com/thread/80573?ContentTypeID=1</link><pubDate>Thu, 23 Mar 2017 20:22:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4eb9b78f-ed1d-4f1e-8fbb-fb63778eb3fc</guid><dc:creator>Sergy</dc:creator><description>&lt;p&gt;Getting some strange result. Here is a part of main, the only place where I use fdsWrite:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;char bt[7]={0x06,0xBD,0x38,0x5B,0x48,0x91,0x20};
		fdsWrite(SETTINGS_FILE, REC_NFC_BT_ADDRESS,bt,7);
		fdsRead(SETTINGS_FILE, REC_NFC_BT_ADDRESS, &amp;amp;settingsNFCbtAddress, &amp;amp;len);
		NRF_LOG_DEBUG(&amp;quot;SETTINGS NFC BT ADDRESS (len: %d):&amp;quot;, len);
		NRF_LOG_HEXDUMP_INFO(settingsNFCbtAddress, len);
		NRF_LOG_DEBUG(&amp;quot;\r\n&amp;quot;);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and here are the functions:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    uint8_t fdsWrite(uint16_t FILE_ID, uint16_t RECORD_KEY, char * data, uint8_t dataLen)
{
	fds_record_t        record;
  fds_record_desc_t   record_desc;
  fds_record_chunk_t  record_chunk;

// Set up data.
record_chunk.p_data         = data;
record_chunk.length_words   = (dataLen+4-1)/4;
	
	NRF_LOG_INFO(&amp;quot;Writing FDS:&amp;quot;);
	NRF_LOG_HEXDUMP_INFO(record_chunk.p_data, dataLen);
	NRF_LOG_INFO(&amp;quot;\r\n&amp;quot;);
// Set up record.
record.file_id                  = FILE_ID;
record.key               = RECORD_KEY;
record.data.p_chunks     = &amp;amp;record_chunk;
record.data.num_chunks   = 1;
    
ret_code_t ret = fds_record_write(&amp;amp;record_desc, &amp;amp;record);
if (ret != FDS_SUCCESS)
{
	NRF_LOG_DEBUG(&amp;quot;FDS Write ERROR: %d\r\n&amp;quot;, ret);
}

return 0;
}

uint8_t fdsRead(uint16_t FILE_ID, uint16_t RECORD_KEY, char **data, uint8_t *dataLen)
{
	
	 fds_flash_record_t  flash_record;
 fds_record_desc_t   record_desc;
 fds_find_token_t    ftok;
	memset(&amp;amp;ftok, 0x00, sizeof(fds_find_token_t));
// Loop until all records with the given key and file ID have been found.
if (fds_record_find(FILE_ID, RECORD_KEY, &amp;amp;record_desc, &amp;amp;ftok) == FDS_SUCCESS)
{
    if (fds_record_open(&amp;amp;record_desc, &amp;amp;flash_record) != FDS_SUCCESS)
    {
        // Handle error.
			data = NULL;
			*dataLen=0;
			return 1;
    }
		else
		{
			NRF_LOG_INFO(&amp;quot;Reading FDS (len: %d):&amp;quot;, flash_record.p_header-&amp;gt;tl.length_words*4);
	NRF_LOG_HEXDUMP_INFO(flash_record.p_data, flash_record.p_header-&amp;gt;tl.length_words*4);
	NRF_LOG_INFO(&amp;quot;\r\n&amp;quot;);
			
			*dataLen = flash_record.p_header-&amp;gt;tl.length_words*4;
			
		  *data=malloc(flash_record.p_header-&amp;gt;tl.length_words*4);
		  memcpy(*data, flash_record.p_data, flash_record.p_header-&amp;gt;tl.length_words*4);
		}
    // Access the record through the flash_record structure.
    // Close the record when done.
		
		
    if (fds_record_close(&amp;amp;record_desc) != FDS_SUCCESS)
    {
        return 2;
    }
		else  return 0;
		
}
return 3;
}


// Simple event handler to handle errors during initialization.
static void fds_evt_handler(fds_evt_t const * const p_fds_evt)
{
    switch (p_fds_evt-&amp;gt;id)
    {
        case FDS_EVT_INIT:
            if (p_fds_evt-&amp;gt;result != FDS_SUCCESS)
            {
                NRF_LOG_DEBUG(&amp;quot;FDS Init failed\r\n&amp;quot;);
            }
            break;
				case FDS_EVT_GC:
    
        NRF_LOG_DEBUG(&amp;quot;GC completed\r\n&amp;quot;);
				break;
        default:
            break;
    }
}


void fdsInit()
{
ret_code_t ret = fds_register(fds_evt_handler);
if (ret != FDS_SUCCESS)
{
    // Registering of the event handler has failed.
}
ret = fds_init();
if (ret != FDS_SUCCESS)
{
    // Handle error.
}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then the printout always shows the first BT address that I wrote in memory, but not the second one:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;0&amp;gt; :INFO:Writing FDS::INFO:
 0&amp;gt; 06 BD 38 5B 48 91 20                             ..8[H.          
 0&amp;gt; :INFO:
 0&amp;gt; :INFO:Reading FDS (len: 8)::INFO:
 0&amp;gt; 06 2A 51 5B 48 91 20 00                          .*Q[H. .        
 0&amp;gt; :INFO:
 0&amp;gt; APP:DEBUG:SETTINGS NFC BT ADDRESS (len: 8):APP:INFO:
 0&amp;gt; 06 2A 51 5B 48 91 20 00                          .*Q[H. .
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS initial state</title><link>https://devzone.nordicsemi.com/thread/80571?ContentTypeID=1</link><pubDate>Wed, 22 Mar 2017 11:48:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c657413-8ca8-4ed4-9f67-e2fccd88c2df</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;The data in flash will only be erased if you specifically do so. Re-programming chip will not erase flash.&lt;/p&gt;
&lt;p&gt;When using FDS, data in flash will only be erased from flash if you do a garbage collection. When deleting a record using FDS, the record itself will not immediately be deleted, but instead its record key will be set to &amp;#39;zero&amp;#39; only. When doing garbage collection, the records with the record key &amp;#39;zero&amp;#39; will be deleted.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>