<?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>[NRF52840] Issue using nrf_fstorage_* with FreeRTOS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/97860/nrf52840-issue-using-nrf_fstorage_-with-freertos</link><description>NRF52840 Dev Kit, SoftDevice v7.2, S140 
 Hello all, 
 I&amp;#39;ve been looking around at some other questions on the forums related to the use of the nrf_fstorage_sd API with FreeRTOS, and I have tried a few of the proposed solutions to no success. 
 My goal</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 May 2023 14:20:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/97860/nrf52840-issue-using-nrf_fstorage_-with-freertos" /><item><title>RE: [NRF52840] Issue using nrf_fstorage_* with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/423347?ContentTypeID=1</link><pubDate>Tue, 02 May 2023 14:20:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c98461bc-ea19-4b67-b14a-b5537f462770</guid><dc:creator>jspear</dc:creator><description>&lt;p&gt;Sigurd,&lt;/p&gt;
&lt;p&gt;Thanks for getting back to me. I have found that FDS does indeed suit our needs, and after incorporating it into our project, we have acquired the desired functionality.&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [NRF52840] Issue using nrf_fstorage_* with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/422031?ContentTypeID=1</link><pubDate>Mon, 24 Apr 2023 11:59:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abf262fe-d001-4070-951f-4867791fb054</guid><dc:creator>Sigurd</dc:creator><description>[quote user="jspear"]Do all of those bytes become wasted and unusable since I am only using 1/8th the page?[/quote]
&lt;p&gt;No, you can still write to the other 7/8 pages.&lt;/p&gt;
[quote user="jspear"]Is there any chance other data could be written there unknowingly and then accidentally erased using the nrf_fstorage_erase() function?[/quote]
&lt;p&gt;When doing erase, the entire page need to be erased. So care must be taken here.&lt;/p&gt;
&lt;p&gt;I think FDS might be better suited for you. See this link:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_fds.html"&gt;https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_fds.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [NRF52840] Issue using nrf_fstorage_* with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/416641?ContentTypeID=1</link><pubDate>Tue, 21 Mar 2023 17:40:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3afd0d83-aca0-4d68-adaa-edfa7c0f8469</guid><dc:creator>jspear</dc:creator><description>&lt;p&gt;Sigurd,&lt;/p&gt;
&lt;p&gt;I see that this could cause problems, and I am able to utilize only 256 bytes for our application as a workaround. My only concern&amp;nbsp;is what would happen to the rest of the page that the flashed data is written too, i.e. the other 3840 bytes? Do all of those bytes become wasted and unusable since I am only using 1/8th the page? Is there any chance other data could be written there unknowingly and then accidentally erased using the nrf_fstorage_erase() function?&lt;/p&gt;
&lt;p&gt;I also wanted to ask you about the&amp;nbsp;Flash Data Storage (FDS) module. In our case, we are going to be wanting to update a small region of flash based on user input, and I see that updates are explicitly mentioned in the FDS documentation. We want to keep the code as simple and least abstracted as possible, hence why we began with the FStorage module, but would the FDS provide better help&amp;nbsp;with our use-case and/or the issue that this thread was originally about?&lt;/p&gt;
&lt;p&gt;Thanks for any insight,&lt;/p&gt;
&lt;p&gt;Joseph&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [NRF52840] Issue using nrf_fstorage_* with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/416476?ContentTypeID=1</link><pubDate>Tue, 21 Mar 2023 09:51:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d099d0d1-0849-492e-8be0-ff06d8b4f8c0</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="jspear"]Reducing the flashing size to around 768 bytes in a single write seems to be the most I can write consistently.[/quote]
&lt;p&gt;I have seen similar reports in the past, where the workaround is to spilt the write in half, i.e. 512 bytes. See this post:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/40088/sd_flash_write-cause-nrf_fault_id_sd_assert"&gt;sd_flash_write() cause NRF_FAULT_ID_SD_ASSERT&lt;/a&gt;&amp;nbsp;, I&amp;#39;m not sure if this case is 100% the same as yours, as I would then have expected a SD assert, and not a&amp;nbsp;&lt;span&gt;HardFault exception.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [NRF52840] Issue using nrf_fstorage_* with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/416372?ContentTypeID=1</link><pubDate>Mon, 20 Mar 2023 19:49:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c86d7c20-4f67-471a-ae3e-6fc4c9bbde10</guid><dc:creator>jspear</dc:creator><description>&lt;p&gt;Reducing the flashing size to around 768 bytes in a single write seems to be the most I can write consistently.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [NRF52840] Issue using nrf_fstorage_* with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/416366?ContentTypeID=1</link><pubDate>Mon, 20 Mar 2023 18:20:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:855c8cf8-0fdc-4bb2-ae57-9ef85e888387</guid><dc:creator>jspear</dc:creator><description>&lt;p&gt;Reducing the tmp size, and the&amp;nbsp;number of bytes to be written by half (essentially doing a PAGE_LEN/2 in the code above) brings back the older behavior of stopping the cold without a&amp;nbsp;HardFault exception&amp;nbsp;being&amp;nbsp;thrown.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [NRF52840] Issue using nrf_fstorage_* with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/416365?ContentTypeID=1</link><pubDate>Mon, 20 Mar 2023 18:13:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e588f556-179b-4cfe-a6da-16536965ad27</guid><dc:creator>jspear</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;Thanks for getting to me. The SDK version is version 17.1.0.&lt;/p&gt;
&lt;p&gt;Here is a snippet of code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**	\def PAGE_LEN
 * 	\brief	Size of 1 NRF52840 Flash page. */
#define PAGE_LEN            0x1000

/**	\var fstorage
 * 	\brief	Instance of the fstorage module. */
NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
	/* Set a handler for fstorage events. */
	.evt_handler = Fstorage_Evt_Handler,

	/* These below are the boundaries of the flash space assigned to this instance of fstorage.
	 * You must set these manually, even at runtime, before nrf_fstorage_init() is called.
	 * The function nrf5_flash_end_addr_get() can be used to retrieve the last address on the
	 * last page of flash available to write data. */
	.start_addr = 0x0003E000,
	// There should only be 4096 Bytes of flash memory allocated to the user
	.end_addr   = (0x0003E000 + PAGE_LEN - 0x01),
};
	
// Function for writing to flash	
void write_func(uint32_t addr, uint8_t* p_data, uint32_t len)
{
	ret_code_t status_code = NRF_SUCCESS;
	char tmp[PAGE_LEN] = {&amp;#39;\0&amp;#39;};
	
	// Make sure that the length is a factor of 4 (1 word = 4 bytes)
	if(0 != (len % 4))
	{
		return;
	}	/*	end if block	*/
	
	// Make sure the whole message will fit inside of the allocated region
	if((addr &amp;lt; fstorage.start_addr) || ((addr + len) &amp;gt; fstorage.end_addr))
	{
        return;
	}	/*	end if block	*/
    
    // Copy desired data into the tmp buffer
    memcpy(tmp, p_data, len);
    
	status_code = nrf_fstorage_write(	&amp;amp;fstorage, addr, 
										tmp, PAGE_LEN, NULL);
	APP_ERROR_CHECK(status_code);
}	/*	end write_func()	*/&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This function is called from a FreeRTOS Task based off of a particular input. When the code gets to the actual nrf_fstorage_write() function call, it stops there. While trying to replicate this issue on a different device, I have found that this actually causes a HardFault exception with the following info:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;error&amp;gt; hardfault: HARD FAULT at 0x00031FFE

&amp;lt;error&amp;gt; hardfault: R0: 0xDB681B4B R1: 0x00000A61 R2: 0x00000A61 R3: 0x20008F08

&amp;lt;error&amp;gt; hardfault: R12: 0x00000001 LR: 0x00031FF1 PSR: 0x8100000E

&amp;lt;error&amp;gt; hardfault: Cause: The processor has made an unaligned memory access.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The data that is passed into the&amp;nbsp;write_func() is just a random few bytes of test data and this is copied into a buffer that is the size of a flash page initialized to zero. The idea is that we will be wanting to preserve the data in the rest of the page, while writing the new data into the desired spot. This will work with an nrf_fstorage_erase() to ensure new data WILL be written. For now, I am leaving it more basic than the&amp;nbsp;final implementation.&lt;/p&gt;
&lt;p&gt;Note: In doing other tests, I have noticed the device be able to perform operations at much smaller byte writes (such as 16 bytes), but based on the desired functionality above, it appears that I am going to need to erase the whole page and write it again, hence the need to write 4096 bytes&amp;nbsp;at a time. If I am mistaken in how this process works, please let me know&lt;/p&gt;
&lt;p&gt;Thanks for the help!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [NRF52840] Issue using nrf_fstorage_* with FreeRTOS</title><link>https://devzone.nordicsemi.com/thread/416325?ContentTypeID=1</link><pubDate>Mon, 20 Mar 2023 14:46:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc17e047-2976-4077-abb4-109657c77a44</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;span&gt;1) What SDK version are you using?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2)&lt;/span&gt;&lt;/p&gt;
[quote user=""]using nrf_fstorage_write(), the device hangs there and does not progress[/quote]
&lt;p&gt;Code you post some code that shows how you call nrf_fstorage_write ?&lt;/p&gt;
&lt;p&gt;Also, please take a look at this case here, it might give you some clues and hints.&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/85261/using-sd_flash_write-in-freertos"&gt;Using sd_flash_write in FreeRTOS&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>