<?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>Writing Files to Flash Memory Using Flash FDS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/75878/writing-files-to-flash-memory-using-flash-fds</link><description>I&amp;#39;m writing a program that receives a time from an RTC over TWI then writes that time into flash memory using the example from the flash FDS library. The problem I&amp;#39;m running into is that I receive my clock data as an array that holds values for the time</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Jun 2021 20:34:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/75878/writing-files-to-flash-memory-using-flash-fds" /><item><title>RE: Writing Files to Flash Memory Using Flash FDS</title><link>https://devzone.nordicsemi.com/thread/313216?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 20:34:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5d0b01d-6c27-4c8c-ae41-cf24593dab27</guid><dc:creator>jake11212</dc:creator><description>&lt;p&gt;Update: Got it working, the alignment was the error.&amp;nbsp; The changes I made were to lines 10, 11, 16, and 17.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void writeTime()
{
   #define FILE_ID         0x0005  /* The ID of the file to write the records into. */
   #define RECORD_KEY_1    0x5555  /* A key for the first record. */

   ret_code_t rc = NULL;

   uint8_t* rx_data = clockTime(); //get the pointer to the array that holds the clockTime
   
    static char intermediate[50] = {0};
    __ALIGN(4) static char m_timeStart[50] = {0};


   //generate a char array that holds the start time from the array
  
   snprintf(intermediate, sizeof(intermediate), &amp;quot;%x:%x:%x on %x/%x/%x&amp;quot;, rx_data[2], rx_data[1], rx_data[0], rx_data[5], rx_data[4], rx_data[6]);
   memcpy(m_timeStart, intermediate, sizeof(intermediate));


   fds_record_t        record;
   fds_record_desc_t   record_desc;


   // Set up record.

   record.file_id           = FILE_ID;
   record.key               = RECORD_KEY_1;
   record.data.p_data       = &amp;amp;m_timeStart;
   /* The following calculation takes into account any eventual remainder of the division. */
   record.data.length_words = (sizeof(m_timeStart) + 3) / 4;
   rc = fds_record_write(&amp;amp;record_desc, &amp;amp;record);
   
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It was actually a combination of the question you linked as well as the alignment issue.&amp;nbsp; I first tried just using one variable m_timeStart that was aligned but writing to it with snprintf broke the alignment and I got the alignment error again.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So I created an intermediate container called intermediate and wrote the string I wanted into it.&amp;nbsp; I then copied the desired string into the aligned m_timeStart which kept the alignment and allowed me to write the string to memory.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing Files to Flash Memory Using Flash FDS</title><link>https://devzone.nordicsemi.com/thread/313213?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 19:45:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d52eea5d-baff-48ea-8530-8cc0d1f4e003</guid><dc:creator>jake11212</dc:creator><description>&lt;p&gt;I checked out that example and tried repeating what they did to fix it by declaring an intermediate container and then using that to write to the variable that will be written to memory.&amp;nbsp; Unfortunately this didn&amp;#39;t work with a static uint8_t array like the person in that post used or with a static character array.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The only datatype that I&amp;#39;ve successfully written to memory is static const character array but I don&amp;#39;t think there&amp;#39;s a way to get data from an array at runtime in C (getting my RTC data over TWI) then write it to a static const array is there?&amp;nbsp; If there is that would solve the problem.&amp;nbsp; I&amp;#39;m also not sure why I&amp;#39;m only able to write static const types to the memory.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I also checked the ret code of the write function which returned 0x8602 which correlates to FDS_ERR_UNALIGNED_ADDR.&amp;nbsp; Looking into this now but maybe declaring the variable as a constant automatically aligns the word, and I have to align manually if not using a constant datatype?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing Files to Flash Memory Using Flash FDS</title><link>https://devzone.nordicsemi.com/thread/313064?ContentTypeID=1</link><pubDate>Wed, 02 Jun 2021 11:10:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e49c2e8-a77e-4945-b753-72e2835eabe2</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I don&amp;#39;t see how this should fail, you may check out:&lt;br /&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/125086#125086"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/32208/what-should-i-start-in-order-to-use-the-maximum-memory-space-in-fstorage/125086#125086&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have in mind though that the write operation may take some time, so you can&amp;#39;t read it back before it&amp;#39;s stored to flash.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>