<?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>pstorage: stuck in erase operation</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3607/pstorage-stuck-in-erase-operation</link><description>This is my code snippet 
 int main(void)
{
	uint32_t err_code;
	
	...
	
	// Scheduler
	scheduler_init();
	
	// Initialize the SoftDevice handler module.
 SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, true); // Use scheduler

 .</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 04 Sep 2014 18:02:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3607/pstorage-stuck-in-erase-operation" /><item><title>RE: pstorage: stuck in erase operation</title><link>https://devzone.nordicsemi.com/thread/13092?ContentTypeID=1</link><pubDate>Thu, 04 Sep 2014 18:02:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52012c5a-1079-4a5d-bd43-d1a2d8648ffb</guid><dc:creator>Petter Myhre</dc:creator><description>&lt;p&gt;Thank for for answering your own question, and separating the questions.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage: stuck in erase operation</title><link>https://devzone.nordicsemi.com/thread/13091?ContentTypeID=1</link><pubDate>Thu, 28 Aug 2014 19:53:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6e44250-d5f2-4ee3-8127-bfe1eaccc8eb</guid><dc:creator>scytulip</dc:creator><description>&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;I repost my question &lt;a href="https://devzone.nordicsemi.com/question/15972/sd_flash_page_erase-will-not-trigger-system-event/"&gt;here&lt;/a&gt;. I found the problem chain is&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;pstorage_init()&lt;/code&gt; called &lt;code&gt;sd_flash_page_erase()&lt;/code&gt;, and set &lt;code&gt;m_cmd_queue.flash_access = true&lt;/code&gt;;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;sd_flash_page_erase()&lt;/code&gt; will not trigger system event handler which calls &lt;code&gt;pstorage_sys_event_handler&lt;/code&gt;, and thus &lt;code&gt;m_cmd_queue.flash_access&lt;/code&gt; kept true;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;because &lt;code&gt;m_cmd_queue.flash_access&lt;/code&gt; is true, then later the &lt;code&gt;pstorage_clear()&lt;/code&gt; is not executed immediately but enqueued.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enqueued command will not be executed, and thus &lt;code&gt;m_cmd_queue.count&lt;/code&gt; is always 1.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;.........&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage: stuck in erase operation</title><link>https://devzone.nordicsemi.com/thread/13090?ContentTypeID=1</link><pubDate>Thu, 28 Aug 2014 18:05:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2deff8e5-bb53-4f52-b952-cbeeaecd4da1</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;Ok, the problem was that when you use scheduler all pstorage execution will be transfered from interrupts to the main context so you need to call scheduler events execution:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Wait until FLASH all cleared
uint32_t count;
do {
    app_sched_execute();
    err_code = pstorage_access_status_get(&amp;amp;count);
    APP_ERROR_CHECK(err_code);
} while(count);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;UPD:&lt;/p&gt;
&lt;p&gt;I messed up and forgot to add app_sched_execute();&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage: stuck in erase operation</title><link>https://devzone.nordicsemi.com/thread/13089?ContentTypeID=1</link><pubDate>Wed, 27 Aug 2014 01:01:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37944192-7fcc-42f4-a659-592781487ea7</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;No, you must use softdevice_sys_evt_handler_set(), because it&amp;#39;s where softdevice will handle end of flash operations ans start new operations:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Registering for system events and passing them on to pstorage module using the pstorage_sys_event_handler is mandatory for the module to function as expected. Code snippet below demonstrates what application needs to do for this.
/**@brief Function for dispatching a system event to interested modules.
  
   @details This function is called from the System event interrupt handler after a system
            event has been received.
  
   @param[in]   sys_evt   System stack event.
 */
static void sys_evt_dispatch(uint32_t sys_evt)
{
    pstorage_sys_event_handler(sys_evt);
}
/**@brief BLE stack initialization.
  
   @details Initializes the SoftDevice and the stack event interrupt.
 */
static void ble_ant_stack_init(void)
{
    // Initialize SoftDevice
    SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, false);
    
    // Subscribe for BLE events.
    uint32_t err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
    APP_ERROR_CHECK(err_code);
    
    // Register with the SoftDevice handler module for System 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;You will block CPU until Flash erase is done with your code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Wait until FLASH all cleared
uint32_t count;
do {
    err_code = pstorage_access_status_get(&amp;amp;count);
    APP_ERROR_CHECK(err_code);
} while(count); /* Stuck here??? */
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage: stuck in erase operation</title><link>https://devzone.nordicsemi.com/thread/13088?ContentTypeID=1</link><pubDate>Tue, 26 Aug 2014 19:10:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eca164f9-deb2-4e3d-8f2f-68b35bd64d71</guid><dc:creator>scytulip</dc:creator><description>&lt;p&gt;Hi, Nikita. I tried softdevice_sys_evt_handler_set() but found this is not what I want. Yes, I can do asynchronous operation in this event handler. However, I&amp;#39;d like to block CPU until the Flash erase is done.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage: stuck in erase operation</title><link>https://devzone.nordicsemi.com/thread/13087?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2014 18:48:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1dab3230-cf8b-494a-831e-0b5529458843</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;Did you init sys events handler with softdevice_sys_evt_handler_set()?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage: stuck in erase operation</title><link>https://devzone.nordicsemi.com/thread/13086?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2014 18:12:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:48ba74ce-8f21-4644-99c6-549201d68f95</guid><dc:creator>scytulip</dc:creator><description>&lt;p&gt;#define __DATA_TYPE	uint8_t \ #define DATA_BLOCK_SIZE	128 * sizeof(__DATA_TYPE) &lt;br /&gt;
#define DATA_BLOCK_COUNT	256\ and pstorage_callback is empty.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage: stuck in erase operation</title><link>https://devzone.nordicsemi.com/thread/13085?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2014 17:12:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a86f45e-1673-457f-b03b-083e6ef4b8e7</guid><dc:creator>Nikita</dc:creator><description>&lt;p&gt;Show DATA_BLOCK_SIZE and DATA_BLOCK_COUNT defines and pstorage_callback. Try to check your code with disabled scheduler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: pstorage: stuck in erase operation</title><link>https://devzone.nordicsemi.com/thread/13084?ContentTypeID=1</link><pubDate>Mon, 25 Aug 2014 16:58:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ffba09b-dc7c-4302-a7b1-8a9766672f34</guid><dc:creator>scytulip</dc:creator><description>&lt;p&gt;I know pstorage is enqueued operation, so I tried &amp;quot;do {
err_code = pstorage_access_status_get(&amp;amp;count);
APP_ERROR_CHECK(err_code);
app_sched_execute();
} while(count);&amp;quot;
No change on the stuck situation. :(&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>