<?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>Cann&amp;#39;t write data to flash by using pstorage.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9824/cann-t-write-data-to-flash-by-using-pstorage</link><description>Hi 
 
 Now I&amp;#39;m using the pstorage module to save some data.But I meet some problem,I hope I can get your help,thanks a lot. 
 It seems that the block has been created successfully and I can see the ID is 0x0003f800.However,I read the block and find</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 27 Oct 2015 15:36:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9824/cann-t-write-data-to-flash-by-using-pstorage" /><item><title>RE: Cann't write data to flash by using pstorage.</title><link>https://devzone.nordicsemi.com/thread/36465?ContentTypeID=1</link><pubDate>Tue, 27 Oct 2015 15:36:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0845b2c-2160-47f9-9ed1-9c4d9d27398b</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi Alice&lt;/p&gt;
&lt;p&gt;Im not sure I understand your problem.&lt;/p&gt;
&lt;p&gt;However, the way it works under the hood is that you can only erase a whole flash page. In pstorage, you can choose to erase just a few bytes, but what happens under the hood is that the untouched data of the page is swapped out, then the whole page is erased and then the untouched data is swapped in again.&lt;/p&gt;
&lt;p&gt;You can choose to update just certain bytes in a block by calling the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v9.0.0/lib_pstorage.html?cp=4_1_0_3_13_2_5#pstorage_update"&gt;pstorage_update&lt;/a&gt; function. What happens under the hood when you use that function is described &lt;a href="https://devzone.nordicsemi.com/question/24027/pstorage_store-and-pstorage_update-execution-time/?answer=24044#post-id-24044"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cann't write data to flash by using pstorage.</title><link>https://devzone.nordicsemi.com/thread/36464?ContentTypeID=1</link><pubDate>Thu, 22 Oct 2015 11:10:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:027c7e07-86b7-40a1-8188-a418e78c65a0</guid><dc:creator>Alice</dc:creator><description>&lt;p&gt;Hi Dan,&lt;/p&gt;
&lt;p&gt;Thanks for your help.I have another peoblem.For example,I need to write two variables(A and B) to the flash in the same page.I want to just update one variable(A or B) value by using pstorage,what should I do?&lt;/p&gt;
&lt;p&gt;Now I do it like this:Firstly,I read the value of the two variable,then update one variable(A or B) value,then write the two variable to flash.However,this method would be inconvenient when there are many data to write to flash.So could you give me some advice?Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cann't write data to flash by using pstorage.</title><link>https://devzone.nordicsemi.com/thread/36463?ContentTypeID=1</link><pubDate>Wed, 21 Oct 2015 14:25:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f47bc50-c2dd-4294-84f4-46ee115fb456</guid><dc:creator>Dan Danknick</dc:creator><description>&lt;p&gt;I had this same problem the first time I used PStorage. I suggest you add the following function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// 
// This function is called from the System event interrupt handler after a system event has been received.
//
static void sys_evt_dispatch(uint32_t sys_evt)
{
    pstorage_sys_event_handler(sys_evt);		// Run the state machine on the PStorage module
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then register it at the end of your &lt;strong&gt;ble_stack_init()&lt;/strong&gt; function with:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Register with the SoftDevice handler module for sys events.
err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Good luck!
-- Dan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>