<?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 use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/30867/how-to-use-fds-for-reading-and-writing-data</link><description>Hello everybody, 
 I used SDK14.2 S132 
 I defined fds_write and read function like that; 
 
 
 
 Also, I wrote a function to register particular data; 
 
 
 Then I used save_data like this; 
 
 Then I read data via fds_read 
 
 
 As a result; 
 
 0&amp;gt;</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 20 Mar 2018 08:10:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/30867/how-to-use-fds-for-reading-and-writing-data" /><item><title>RE: How to use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/thread/125096?ContentTypeID=1</link><pubDate>Tue, 20 Mar 2018 08:10:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9207bf9-b9f8-46dd-a419-79853252338e</guid><dc:creator>purgoufr</dc:creator><description>&lt;p&gt;Writing and reading operations using FDS are solved in the following link.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/32208/what-should-i-start-in-order-to-use-the-maximum-memory-space-in-fstorage"&gt;Solution Link&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/thread/122561?ContentTypeID=1</link><pubDate>Fri, 02 Mar 2018 08:38:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09efa5a7-f0ff-4d49-a3f6-9f6bd3aff586</guid><dc:creator>purgoufr</dc:creator><description>&lt;p&gt;How can I do data storing or printing without using CLI? Because I do not want to print data or anything else. I only want to store the data in an array that I write with fds_write.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I wil try to explain what I need;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Write&amp;nbsp;&amp;quot;&lt;strong&gt; uint8_t a[4] = { &amp;#39;a&amp;#39;, &amp;#39;b&amp;#39;, &amp;#39;c&amp;#39;, &amp;#39;\0&amp;#39; };&lt;/strong&gt; &amp;quot;&amp;nbsp; this array via FDS write&lt;/li&gt;
&lt;li&gt;Read &amp;quot;&lt;strong&gt;a[4]&lt;/strong&gt;&amp;quot; from FDS&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Store &amp;quot;&lt;strong&gt;a[4]&lt;/strong&gt;&amp;quot; into uint8_t &amp;quot;&lt;strong&gt;b[4]&lt;/strong&gt;&amp;quot; ;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;The value of the b[4] (read_data) should print like this&amp;nbsp;;&amp;nbsp; NRF_LOG_HEXDUMP_INFO(b, sizeof(b));&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Result must be;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;0&amp;gt; &amp;lt;info&amp;gt; app:&amp;nbsp; 61 62 63 00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |abc.&amp;nbsp; &amp;nbsp;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I want to do all of this without using cli.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/thread/122259?ContentTypeID=1</link><pubDate>Wed, 28 Feb 2018 10:58:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:432c8b9a-4432-44c1-adbe-ad56aa65267f</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;I&amp;#39;m still a little confused about the flow in your code. How about something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t * pointer_to_record_data;
pointer_to_record_data = (uint8_t *)frec.p_data;

uint8_t test_data_0[10];

if(frec.p_header-&amp;gt;record_key == A_RELEVANT_RECORD_KEY)
{
    for(uint8_t i = 0; i &amp;lt; 10; i++)
    {
        test_data_0[i] = *pointer_to_record_data;
        pointer_to_record_data++;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;to get the record data stored in your array.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/thread/122117?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 11:21:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4cf5b4b9-cb86-475b-bbd0-fbe430759601</guid><dc:creator>purgoufr</dc:creator><description>&lt;p&gt;Thank you so much for your solution. But I have to store data into uint8_t array[10]. It means, I want to write &amp;quot;abcdefghij&amp;quot; via nus_data . I can do this shown as below, there is no problem.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;strong&gt;0&amp;gt; &amp;lt;info&amp;gt; app: save_data&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: Writing Record ID = 1&amp;nbsp;&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; 0&amp;gt; &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; 0&amp;gt; 61 62 63 64 65 66 67 68|abcdefgh&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; 0&amp;gt; 69 6A |ij &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Then I want to read &amp;quot;abcdefghij&amp;quot; and store it in uint8_t array [10].&lt;/p&gt;
&lt;p&gt;That&amp;#39;s why I figure out your &amp;quot;convert_raw_data_to_human_readable&amp;quot; function as below:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void convert_raw_data_to_human_readable(uint8_t *out_data , uint32_t in_data)
{
    for(uint8_t i = 0; i &amp;lt; 4; i++)
	{
		out_data[i] = (uint8_t)(in_data &amp;gt;&amp;gt; (8 * i));
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And I put the function inside kls_fds_read() function like this;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t *data     = (uint32_t *) flash_record.p_data;
uint32_t const len = flash_record.p_header-&amp;gt;length_words * sizeof(uint32_t);
				
for(uint32_t i; i &amp;lt; len / 4; i++)
{
    convert_raw_data_to_human_readable(read_data, *data);
    data++;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Finally, I&amp;#39;m trying to write on my destination array(&lt;strong&gt;dest_data_0[10]&lt;/strong&gt;);&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void first_Setup(void)
{
	NRF_LOG_INFO(&amp;quot;first_Setup Start&amp;quot;);
	uint8_t dest_data_0[10]  = {0};

	
	while (flag_write_fds == 0);
	kls_fds_read(FILE_ID, RECORD_KEY, dest_data_0);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But I did not get the data I wrote.&lt;/p&gt;
&lt;p&gt;RTT Viewer output:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;strong&gt;&amp;nbsp;0&amp;gt; &amp;lt;info&amp;gt; app: first_Setup Start&lt;/strong&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;strong&gt;0&amp;gt; &amp;lt;info&amp;gt; app: Found Record ID = 1&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; 0&amp;gt; &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: Data = &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: dest_data_0 : &lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: 00 00 00 00 00 00 00 00|........&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: 00 00 |..&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/thread/122079?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 09:37:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3a1d8ee4-b945-4972-a3d3-34c49a30ccad</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Printing is done in&amp;nbsp;print_data_cmd() in cli.c.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/thread/122076?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 09:36:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8599f1f0-b819-4877-af16-dae1960a3baa</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;I got carried away and made an example. I based it on the&amp;nbsp;&lt;a title="Flash Data Storage Example" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/fds_example.html?cp=4_0_0_4_6_8"&gt;Flash Data Storage Example&lt;/a&gt;&amp;nbsp;and changed cli.c and main.c a little so that you can print out record details&amp;nbsp;as well as&amp;nbsp;the actual data. Use the&amp;nbsp;&lt;a title="Command Line Interface library" href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/lib_cli.html?cp=4_0_0_3_10"&gt;Command Line Interface library&lt;/a&gt;&amp;nbsp;to write and print records. Have a look at the attached files to see the changes I made and how it can be done.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-7ea07c2b78724b64b124ef9c8f0d911d/main.c"&gt;devzone.nordicsemi.com/.../main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-7ea07c2b78724b64b124ef9c8f0d911d/main.diff"&gt;devzone.nordicsemi.com/.../main.diff&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-7ea07c2b78724b64b124ef9c8f0d911d/cli.c"&gt;devzone.nordicsemi.com/.../cli.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-7ea07c2b78724b64b124ef9c8f0d911d/cli.diff"&gt;devzone.nordicsemi.com/.../cli.diff&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/thread/122049?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 07:37:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5be0997b-7607-43fd-835c-8217897de705</guid><dc:creator>purgoufr</dc:creator><description>&lt;p&gt;Yes, you are exactly right. Because&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;strong&gt;void&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;const * p_data;&amp;nbsp; &amp;nbsp; //!&amp;lt; Location of the record data in flash.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It means, I read the location, not Data itself. So&amp;nbsp;how can I read Data itself?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/thread/122040?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 06:08:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f9ced616-403f-40aa-963c-9793a4dd8c78</guid><dc:creator>purgoufr</dc:creator><description>&lt;p&gt;I tried to fds_write uint8_t some_array[10] variable. Then I tried to read same array which has uint8_t type. But&amp;nbsp;data is equal to (uint32_t *) flash_record.p_data . I think it is not avaliable for uint8_t type variable. So, How to save array that is uint8_t type variable and how to read the same array.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/thread/121968?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2018 13:59:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:971f3b7f-ee24-4c85-acdd-7feee5fd6ee4</guid><dc:creator>purgoufr</dc:creator><description>&lt;p&gt;Hi Martin,&lt;/p&gt;
&lt;p&gt;I printed like this;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void first_Setup(void)
{
    NRF_LOG_INFO(&amp;quot;first_Setup Start&amp;quot;);
    uint8_t dest_data_0[10]  = {0};
	
	while (flag_write_fds == 0);
	kls_fds_read(FILE_ID_SSN, RECORD_KEY_SSN, dest_data_0);
	
	NRF_LOG_INFO(&amp;quot;dest_data_0 : &amp;quot;);
	NRF_LOG_HEXDUMP_INFO(dest_data_0, 10);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I wrote the function &amp;quot;kls_fds_read&amp;quot; at the top, you can look at it from there. In&amp;nbsp;&lt;span&gt;a part of &amp;quot;Kls_fds_read&amp;quot; function&lt;/span&gt;&lt;span&gt;&amp;nbsp;I used this code to print out;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;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;);
				
data = (uint32_t *) flash_record.p_data;
for (uint8_t i=0;i&amp;lt;flash_record.p_header-&amp;gt;length_words;i++)
{
	NRF_LOG_INFO(&amp;quot;0x%8x &amp;quot;,data[i]);
	read_data[i] = data[i] ; 
}
NRF_LOG_INFO(&amp;quot;\r\n&amp;quot;);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;data = (uint32_t *) flash_record.p_data;&amp;nbsp; ------&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;nbsp; Does not that mean the data itself?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I try to read data with use &amp;quot;uint8_t read_data&amp;quot;&amp;nbsp; but fds used &amp;quot;uint32_t *data;&amp;quot; , and I try to copy the data into read_data via&amp;nbsp; &amp;quot;read_data[i] = data[i] ; &amp;quot;. Although I do not get any errors, maybe it is not logical to choose two different variable types.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use FDS for reading and writing data?</title><link>https://devzone.nordicsemi.com/thread/121952?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2018 12:30:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:138ea8f3-9a80-4a62-9e5d-82911125368b</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Can you show us how you print out your data? And maybe post more of your code?&lt;/p&gt;
&lt;p&gt;Values like&amp;nbsp;&lt;span&gt;0x20005CC8&lt;/span&gt;&lt;span&gt;&amp;nbsp;look like addresses in RAM, so it might be that you are simply printing out the &lt;em&gt;location&lt;/em&gt; of your data, and not the data itself.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>