<?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>Saving words in FDS memory ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/22283/saving-words-in-fds-memory</link><description>I was able to use the fds with the help of good people here , I am trying now to save a word into memory. 
 As I see in the docs, the only way to save data is by uint32_t chunks . 
 So I guess I am doing it wrong but I am trying this without success</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 19 Dec 2018 07:24:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/22283/saving-words-in-fds-memory" /><item><title>RE: Saving words in FDS memory ?</title><link>https://devzone.nordicsemi.com/thread/162409?ContentTypeID=1</link><pubDate>Wed, 19 Dec 2018 07:24:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41b69a69-1a7f-4a7c-bea7-ca55dd3f5308</guid><dc:creator>kiranj</dc:creator><description>&lt;p&gt;I am not able to store the whole string as in&amp;nbsp;&lt;span&gt;&amp;nbsp; my_text[] = &amp;quot;What a day, what a day!&amp;quot;;its giving error at time of writing,please help??&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving words in FDS memory ?</title><link>https://devzone.nordicsemi.com/thread/87616?ContentTypeID=1</link><pubDate>Fri, 26 May 2017 09:14:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3db2b3f3-3f7f-44ea-a81d-3e206ef20573</guid><dc:creator>Lola</dc:creator><description>&lt;p&gt;Thank you !&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving words in FDS memory ?</title><link>https://devzone.nordicsemi.com/thread/87615?ContentTypeID=1</link><pubDate>Fri, 26 May 2017 07:02:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37755de5-a503-4ac2-a131-84e30dc052b6</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;&lt;code&gt;my_text&lt;/code&gt; is an array, and an array variable is a variable that holds the address of the first element in the array. Therefore,  record_chunk.p_data can be assigned to &lt;code&gt;my_text&lt;/code&gt; one of the following ways, and they are equivalent:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;record_chunk.p_data = my_text;
record_chunk.p_data = &amp;amp;my_text[0];
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When calculating the length in words, using integer division, the result will always be &amp;quot;rounded&amp;quot; down to the whole integer. A data array of 21 bytes, is strictly speaking 5 words + 1 byte. However, the length should be in words, and thus 6 words are needed to store all the data. 21/4 = 5, (21+3)/4 = 6. For 20 bytes, 5 words are needed, in integer division 20/4 = (20+3)/4 =5.&lt;/p&gt;
&lt;p&gt;Yes, &lt;code&gt;my_text&lt;/code&gt; should be defined the following way: &lt;code&gt;static char const my_text[] = ...&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving words in FDS memory ?</title><link>https://devzone.nordicsemi.com/thread/87614?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 19:20:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2517031-2a77-44bb-b2b0-d80bd03ea578</guid><dc:creator>Lola</dc:creator><description>&lt;p&gt;By the way, I found out that the word you are about to save must be static, or global otherwise the system just lose it while it&amp;#39;s writing, and you read garbage. So If I drop the static I get garbage, if I add it it&amp;#39;s good. Also, if I set the my_text to be global and not static it&amp;#39;s also work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving words in FDS memory ?</title><link>https://devzone.nordicsemi.com/thread/87613?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 19:17:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e48f8b2-46cf-43ff-a3e3-b2ac77e63144</guid><dc:creator>Lola</dc:creator><description>&lt;p&gt;Thanks a lot, did you mean  &lt;code&gt;record_chunk.p_data= &amp;amp;my_text&lt;/code&gt; (with the address sign) ? it&amp;#39;s a pointer that should get an address no ?&lt;/p&gt;
&lt;p&gt;Also, why calculating the size with the 3/4 ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving words in FDS memory ?</title><link>https://devzone.nordicsemi.com/thread/87612?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 13:03:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6b05d56-6f46-4c53-8719-4d4c73a88929</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;I have updated the code to show how to store and retrieve a string.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving words in FDS memory ?</title><link>https://devzone.nordicsemi.com/thread/87611?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 06:54:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:101af845-6c10-4cf8-a757-55cb63407440</guid><dc:creator>Lola</dc:creator><description>&lt;p&gt;Hi, Kristen thanks a lot, but it wasn&amp;#39;t my question - that I already know. The question was how to save strings(char arrays), and read them. You can see in the first 3 lines of the question I am trying to save a string into memory as a set of Uint32 .&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Saving words in FDS memory ?</title><link>https://devzone.nordicsemi.com/thread/87610?ContentTypeID=1</link><pubDate>Wed, 24 May 2017 06:26:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:faa39412-8873-45c6-a56f-2a041b9c7311</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;The below code shows how to store and retrieve a string using FDS:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static ret_code_t fds_test_write(void)
{
	#define FILE_ID     0x1111
	#define REC_KEY     0x2222
	
	static char const my_text[]    = &amp;quot;What a day, what a day!&amp;quot;;
	
	fds_record_t        record;
	fds_record_desc_t   record_desc;
	fds_record_chunk_t  record_chunk;
	// Set up data.
	record_chunk.p_data         =  my_text; 
	record_chunk.length_words   =  (sizeof(my_text)+3)/4;  // When calculating the length in words, using integer division, the result will always be &amp;quot;rounded&amp;quot; down to the whole integer. A data array of 21 bytes, is strictly speaking 5 words + 1 byte. However, the length should be in words, and thus 6 words are needed to store all the data. 21/4 = 5, (21+3)/4 = 6. For 20 bytes, 5 words are needed, in integer division 20/4 = (20+3)/4 =5.
	// Set up record.
	record.file_id              = FILE_ID;
	record.key              		= REC_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)
	{
			return ret;
	}
	 NRF_LOG_INFO(&amp;quot;Writing Record ID = %d \r\n&amp;quot;,record_desc.record_id);
	return NRF_SUCCESS;
}

static ret_code_t fds_read(void)
{
	#define FILE_ID     0x1111
	#define REC_KEY     0x2222
	fds_flash_record_t  flash_record;
	fds_record_desc_t   record_desc;
	fds_find_token_t    ftok ={0};//Important, make sure you zero init the ftok token
	
	char     *p_data;
	uint32_t err_code;
	
	NRF_LOG_INFO(&amp;quot;Start searching... \r\n&amp;quot;);
	// Loop until all records with the given key and file ID have been found.
	while (fds_record_find(FILE_ID, REC_KEY, &amp;amp;record_desc, &amp;amp;ftok) == FDS_SUCCESS)
	{
			err_code = fds_record_open(&amp;amp;record_desc, &amp;amp;flash_record);
			if ( err_code != FDS_SUCCESS)
			{
				return err_code;		
			}
			
			NRF_LOG_INFO(&amp;quot;Found Record ID = %d\r\n&amp;quot;,record_desc.record_id);
			NRF_LOG_INFO(&amp;quot;Data = &amp;quot;);
			
			// Access the record through the flash_record structure.
			p_data = (char *) flash_record.p_data;
			NRF_LOG_INFO(&amp;quot; %s \r\n&amp;quot;, (uint32_t)p_data);
		
			
			// Close the record when done.
			err_code = fds_record_close(&amp;amp;record_desc);
			if (err_code != FDS_SUCCESS)
			{
				return err_code;	
			}
	}
	return NRF_SUCCESS;
	
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>