<?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 swap page not found</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/51037/fds-swap-page-not-found</link><description>nRF5 SDK v15.2.0, nRF52840 
 This issue occurs on reset, most often after cycling power. 
 There are 4 pages reserved and 4 data pages are found. Since a swap page isn&amp;#39;t found, the initialization of FDS fails. 
 Changes made to debug this issue: 
 fds</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 22 Aug 2019 08:08:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/51037/fds-swap-page-not-found" /><item><title>RE: FDS swap page not found</title><link>https://devzone.nordicsemi.com/thread/205467?ContentTypeID=1</link><pubDate>Thu, 22 Aug 2019 08:08:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:166b6287-4821-4ee8-a3bc-c01134fe7da4</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="ahedin25"]static fds_page_t m_pages[3];&amp;nbsp; //&amp;nbsp;FDS_DATA_PAGES == 3,&amp;nbsp;FDS_VIRTUAL_PAGES == 4[/quote]
&lt;p&gt;&amp;nbsp;Of course. I see.&lt;/p&gt;
&lt;p&gt;I suggest that you look at the functions gc_swap_erase() and gc_page_erase() in fds.c. Since you have a data page (not swap), the gc_page_erase() is probably the closest. Alternatively, use nrf_fstorage_erase() directly, like it is done in gc_page_erase(). You may want to avoid the state machine in fds, so maybe avoid setting the state, like it does in nrf_fstorage_erase(), but you do want to wait for the page erase to finish. fs_event_handler should be called when this is done, with the p_evt-&amp;gt;id == NRF_FSTORAGE_EVT_ERASE_RESULT, and hopefully p_evt-&amp;gt;result == NRF_SUCCESS.&lt;/p&gt;
&lt;p&gt;When this has returned, the page is erased. From here, you can either try to initiate FDS once more (It should repair itself if it has N-1 Data pages and one empty page, where N = FDS_VIRTUAL_PAGES). Alternatively, in case the fds state machine is difficult to deal with, you can run NVIC_SystemReset(); to reset the application, which then will run fds_init() again. Now with the empty page it should repair itself.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS swap page not found</title><link>https://devzone.nordicsemi.com/thread/205403?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 22:20:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f50aef64-3bc1-49a5-b3a8-78343c8acbd3</guid><dc:creator>ahedin25</dc:creator><description>&lt;p&gt;What function(s) do you recommend using for deleting the page?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS swap page not found</title><link>https://devzone.nordicsemi.com/thread/205402?ContentTypeID=1</link><pubDate>Wed, 21 Aug 2019 22:19:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6667f803-48d9-4f8c-8612-b3240d030548</guid><dc:creator>ahedin25</dc:creator><description>&lt;p&gt;I am not increasing the page size or the number of pages.&lt;/p&gt;
&lt;p&gt;Let me try to explain the problem again.&lt;/p&gt;
&lt;p&gt;static fds_page_t m_pages[3];&amp;nbsp; //&amp;nbsp;FDS_DATA_PAGES == 3,&amp;nbsp;FDS_VIRTUAL_PAGES == 4&lt;/p&gt;
&lt;p&gt;// when all three pages and swap look like a data page&lt;/p&gt;
&lt;p&gt;line ~695 m_pages[3].page_type =&amp;nbsp;FDS_PAGE_DATA;&amp;nbsp; // this is bad because m_pages only has locations 0, 1, and 2.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS swap page not found</title><link>https://devzone.nordicsemi.com/thread/204628?ContentTypeID=1</link><pubDate>Mon, 19 Aug 2019 06:32:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bfc5c11e-1fd0-408b-8b9d-0373b3e72f71</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I see. Well. Increasing the page size here is probably a bit sketchy, because it will increase the number of pages for this startup, and the next time it tries to initialize the FDS, if the swap page is within the first 4 pages, this page will not be included, right? If so, you may miss some records, right?&lt;/p&gt;
&lt;p&gt;I suggest that if you find yourself in the situation with 4 FDS pages where all of them are data pages, and none of them are flash pages, you look for a data page that doesn&amp;#39;t have any records (the rest of the page is 0xFF&amp;#39;s), and then delete this page. Then do a reboot, or call fds_init() again. Then this empty page without any tags will be initialized as a swap page on the next call to fds_init().&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS swap page not found</title><link>https://devzone.nordicsemi.com/thread/204519?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2019 13:07:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2d2d9ac-02f8-46f6-b806-b15dc759fd75</guid><dc:creator>ahedin25</dc:creator><description>&lt;p&gt;I have always had 4 data pages.&lt;/p&gt;
&lt;p&gt;In this specific case the problem with the code is on line ~695.&amp;nbsp; If the swap page is seen as a data page, then m_pages[page] can reference memory that is beyond what was allocated.&amp;nbsp; That is why I added the +1.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It doesn&amp;#39;t change the number of pages because that is controlled by the defines, but it&amp;nbsp;makes the variable big enough to handle this error condition.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FDS swap page not found</title><link>https://devzone.nordicsemi.com/thread/204434?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2019 09:17:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7fa1204-75eb-48dc-9580-24e5ae3e6891</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Is it possible to send a flash dump of the chip?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]If there is an empty page, can it be converted to a swap page?&amp;nbsp; There are 3 empty pages in my case.[/quote]
&lt;p&gt;&amp;nbsp;You mean data pages that doesn&amp;#39;t have any data except from the data tag?&lt;/p&gt;
&lt;p&gt;If so, that would be the suggested procedure yes.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;According to the flow diagram for the FDS this is a situation that really shouldn&amp;#39;t happen, but we have seen similar cases earlier. It is likely caused by a garbage collection that is not finished due to a power cut.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We recommend to not call fds_gc() except if a fds function returns a return value indicating that the fds pages are full. It is not(!) recommended to run fds_gc() on startup. This will beat up the flash, and use up the number of flash write/erase cycles faster than necessary. In addition, it increases the risk of this happening.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;However, if you find yourself in the situation where you have 4 data pages and no swap pages, I recommend that you find one that is empty, delete it, and set it as swap page.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]Is there a reason&amp;nbsp;FDS_PAGE_TAG_SWAP and&amp;nbsp;FDS_PAGE_TAG_DATA only differ by one bit?[/quote]
&lt;p&gt;&amp;nbsp;It is not by coincidence. The reason is that it is only possible to set 1&amp;#39;s to 0&amp;#39;s in the flash without erasing an entire flash page. (flash page != fds page, but a flash page is larger than just the page tag).&lt;/p&gt;
&lt;p&gt;So in order to ensure that the swap page can become a data page, one of the 1&amp;#39;s is flipped to 0. That is why the data tag and swap tag are so similar.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Either way, I would like to see a flash dump of the chip for research purposes. Did you start with 4 or 5 data pages?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>