<?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>Flash write issue!</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/62639/flash-write-issue</link><description>hello, 
 I am using SDK 16.0 and I use flash storage to store some value which is critical for our application, when I use fstorage_write as below inside main(), 
 
 int main() 
 { 
 uint32_t mode=0x22; uint32_t address_reg=0x54000; 
 fstorage_init();</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 16 Jun 2020 11:49:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/62639/flash-write-issue" /><item><title>RE: Flash write issue!</title><link>https://devzone.nordicsemi.com/thread/255236?ContentTypeID=1</link><pubDate>Tue, 16 Jun 2020 11:49:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4bfe1aed-0ddc-4ac9-8162-e00ca01da255</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The variable that you pass to the function (&lt;span&gt;uint32_t mode) will go out of scope when the function call returns. fstorage write and erase operations happen asynchronously and may not complete before the function returns. Since you pass a reference to the mode variable to fstorage_write, the content of the address may have changed before fstorage will write the data to flash.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You need to make sure that the variable that is referenced is in scope until the write is complete. This can be done either by using a global variable for passing data to the function or by using a pointer in the function arguments and pass a pointer to a variable that is in scope after the function call returns.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>