<?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 problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9242/flash-write-problem</link><description>I am trying to implement some write to flash, and started by integrating the relevant functions from the example code I found in this thread . 
 I added a dummy write function in my main.c like this: 
 static uint8_t pstorage_wait_flag = 0;
static</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 28 Sep 2015 13:36:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9242/flash-write-problem" /><item><title>RE: flash write problem</title><link>https://devzone.nordicsemi.com/thread/34105?ContentTypeID=1</link><pubDate>Mon, 28 Sep 2015 13:36:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:faa24496-cfa1-4385-8915-c5a725b5e4ea</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Two mistakes in the code.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Variables in dummy_write need to be declared static. With the current implementation where variables only exist locally in the dummy_write function, the flash operation will be pointing to locations in RAM, that actually might be used for something else.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The scheduler apparently needs to be used for softdevice callbacks, i.e. SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, true) instead of SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false)&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flash write problem</title><link>https://devzone.nordicsemi.com/thread/34104?ContentTypeID=1</link><pubDate>Wed, 23 Sep 2015 12:19:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c51584d7-eb4e-4e5a-9501-59dffa103c49</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;I have not found the root cause yet. I can reproduce the issue with SDK 7.2.0 + S110 7.3.0. I can however not reproduce the issue with SDK 8.0.0 + S110 8.0.0. I cant see in the release notes that the bug has been addressed in SDK 8.0.0, but I have assigned a task to the SDK team to look into the issue. At this point, I can not say when they will finish their investigation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flash write problem</title><link>https://devzone.nordicsemi.com/thread/34103?ContentTypeID=1</link><pubDate>Tue, 22 Sep 2015 10:47:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a324d0e9-4c91-4dc7-932e-a21d05a6d906</guid><dc:creator>wim</dc:creator><description>&lt;p&gt;Hi Stefan, any news on this subject?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flash write problem</title><link>https://devzone.nordicsemi.com/thread/34102?ContentTypeID=1</link><pubDate>Fri, 18 Sep 2015 10:21:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f891636-7981-43d8-9abc-a2eaca9c90e1</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;I will try to come up with an official fix, but any additional feedback on the problem is most welcome. I will report on this thread with my progress&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flash write problem</title><link>https://devzone.nordicsemi.com/thread/34101?ContentTypeID=1</link><pubDate>Fri, 18 Sep 2015 10:18:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b74d3ffd-e6b1-49e8-9ac0-45a37a3906a4</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi wim&lt;/p&gt;
&lt;p&gt;Yes, I will progress on this and seems that we are not alone with this problem, see &lt;a href="https://devzone.nordicsemi.com/question/30693/pstorage-handle-never-called/"&gt;this thread&lt;/a&gt;. Seems that some customers have found workarounds.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flash write problem</title><link>https://devzone.nordicsemi.com/thread/34100?ContentTypeID=1</link><pubDate>Fri, 18 Sep 2015 10:16:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e7d4454-f9be-4f7f-b38d-28291bf0fb74</guid><dc:creator>wim</dc:creator><description>&lt;p&gt;Hi Stefan,
That is really strange, I will give it a try, but could you please investigate further and keep me informed of your progress?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flash write problem</title><link>https://devzone.nordicsemi.com/thread/34098?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2015 23:59:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:12883e2d-340a-4c2e-b134-a764d8ad6c03</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;What context are you calling dummy_write() from? Main thread context, ie in your main code, or from a handler or some sort, timer, button .. etc?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: flash write problem</title><link>https://devzone.nordicsemi.com/thread/34099?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2015 20:43:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8470f380-dc3d-413d-9cac-45886f2f61e4</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I saw nothing wrong with your code. I tried to put your code directly into ble_app_template example in SDK 7.2.0, but experienced the same as you, the example_cb_handler was never called. I saw however that the sys_evt_dispatch handler was called. The CPU goes into a hardfault when trying to call example_cb_handler from pstorage.c, but I do not realize at this point why that happens. However, inserting more code into the example_cb_handler seems to fix the problem.  If I define it as e.g.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void example_cb_handler(pstorage_handle_t  * handle,
													 uint8_t              op_code,
													 uint32_t             result,
													 uint8_t            * p_data,
													 uint32_t             data_len)
{
		if(handle-&amp;gt;block_id == pstorage_wait_handle) 
		{ 
			 pstorage_wait_flag = 0; 
		} 
		
		switch(op_code)
		{
			case PSTORAGE_LOAD_OP_CODE:
				 if (result == NRF_SUCCESS)
				 {
				 pstorage_wait_flag = 0; 
				 
						 SEGGER_RTT_WriteString(0, &amp;quot;pstorage LOAD callback received \n\n&amp;quot;);
						 LEDS_INVERT(BSP_LED_1_MASK);				 
				 }
				 else
				 {
						 SEGGER_RTT_WriteString(0, &amp;quot;pstorage LOAD ERROR callback received \n\n&amp;quot;);
						 LEDS_INVERT(BSP_LED_2_MASK);	
				 }
				 break;
			case PSTORAGE_STORE_OP_CODE:
				 if (result == NRF_SUCCESS)
				 {
						 SEGGER_RTT_WriteString(0, &amp;quot;pstorage STORE callback received \n\n&amp;quot;);
						 LEDS_INVERT(BSP_LED_1_MASK);	
				 }
				 else
				 {
						 SEGGER_RTT_WriteString(0, &amp;quot;pstorage STORE ERROR callback received \n\n&amp;quot;);
						 LEDS_INVERT(BSP_LED_2_MASK);	
				 }
				 break;				 
			case PSTORAGE_UPDATE_OP_CODE:
				 if (result == NRF_SUCCESS)
				 {
						 SEGGER_RTT_WriteString(0, &amp;quot;pstorage UPDATE callback received \n\n&amp;quot;);
						 LEDS_INVERT(BSP_LED_1_MASK);	
				 }
				 else
				 {
						 SEGGER_RTT_WriteString(0, &amp;quot;pstorage UPDATE ERROR callback received \n\n&amp;quot;);
						 LEDS_INVERT(BSP_LED_2_MASK);	
				 }
				 break;
			case PSTORAGE_CLEAR_OP_CODE:
				 if (result == NRF_SUCCESS)
				 {
						 SEGGER_RTT_WriteString(0, &amp;quot;pstorage CLEAR callback received \n\n&amp;quot;);
						 LEDS_INVERT(BSP_LED_1_MASK);	
				 }
				 else
				 {
						 SEGGER_RTT_WriteString(0, &amp;quot;pstorage CLEAR ERROR callback received \n\n&amp;quot;);
						 LEDS_INVERT(BSP_LED_2_MASK);	
				 }
				 break;
			case PSTORAGE_ERROR_OP_CODE:
						SEGGER_RTT_WriteString(0, &amp;quot;pstorage ERROR callback received \n\n&amp;quot;);
						LEDS_INVERT(BSP_LED_2_MASK);	
				 break;				 
		}	
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;it seems to fix the problem.  I will have to investigate further what causes the hardfault.&lt;/p&gt;
&lt;p&gt;In this case I use &lt;a href="https://devzone.nordicsemi.com/tutorials/6/debugging-with-real-time-terminal/"&gt;Segger RTT&lt;/a&gt; to see when each callback is received.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>