<?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>Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/11319/urgently-about-flash-access</link><description>Hi,
I use s110_6.0.0 and sdk_5.2.1 in my old product. I found that I can&amp;#39;t write flash sometimes. Timer1 and Timer2 are used, and their interrupt priority level is 1(high_priority). If I change the priority to 3(low-level), it runs well.
I think interrupts</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 19 May 2016 03:40:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/11319/urgently-about-flash-access" /><item><title>RE: Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/thread/42578?ContentTypeID=1</link><pubDate>Thu, 19 May 2016 03:40:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7ec7899-f18c-4a68-88bf-fb4cab56d4f5</guid><dc:creator>mansfield</dc:creator><description>&lt;p&gt;I replaced pstorage.c, psdorage.h and pstorage_platform.h files from SDK 11.0.0. And I have updated the flash more than 2500 times. The problem didn&amp;#39;t reproduced any more. It seems that SDK 11.0.0 have fixed this problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/thread/42577?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2016 07:30:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45d6600d-b9cc-44bc-8384-ac35c86b447c</guid><dc:creator>mansfield</dc:creator><description>&lt;p&gt;Thank you! I created a case on www.nordicsemi.com just now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/thread/42575?ContentTypeID=1</link><pubDate>Tue, 26 Jan 2016 08:49:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d5ec6ae8-5d4a-43d5-b095-b9e7d8e70b96</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;So I suspect you are using pstorage since you talk about updates, am I correct? It would be good if I can look at your code. If you do not want to share it here, you can create a support case on www.nordicsemi.com (not public), submit your project and refer to this case&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/thread/42576?ContentTypeID=1</link><pubDate>Tue, 26 Jan 2016 05:16:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:360f1125-91a8-4a19-840a-ca9fc08b2598</guid><dc:creator>mansfield</dc:creator><description>&lt;p&gt;Now I set the timer priority to 3. But I also found the update operation fail in sdk 8.1.1, if I write frequently(1 write+2 update per 10 second, the 2 updates are in the same page).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/thread/42573?ContentTypeID=1</link><pubDate>Fri, 22 Jan 2016 08:26:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2089dcb-2055-49f1-b7df-d2c215c6bc93</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;No it is not fixed in 8.x.x. However, there is one more factor and that is the softdevices. For softdevices prior to S110 8.0.0, CPU is blocked during the whole BLE radio event, with S110 8.0.0 and later, CPU can be used by the application during the BLE radio event. This means that S110 8.0.0 provides better CPU utilization than its predecessors, and could make a difference in your case, but it could depend on your BLE connection/advertitising interval. It also depends on if you are doing a flash write only or if you are doing also flash erase or flash update. &lt;a href="https://devzone.nordicsemi.com/question/24027/pstorage_store-and-pstorage_update-execution-time/?answer=24044#post-id-24044"&gt;Flash update is a pstorage operation and includes flash erase operation&lt;/a&gt; among other things.&lt;/p&gt;
&lt;p&gt;For details on CPU blocking, see my answer on &lt;a href="https://devzone.nordicsemi.com/question/37205/advertising-causes-timer1-delay/?answer=37299#post-id-37299"&gt;this thread&lt;/a&gt; below the dotted line.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/thread/42574?ContentTypeID=1</link><pubDate>Fri, 22 Jan 2016 04:18:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:452b848a-c293-47d0-8961-f42e58e8be97</guid><dc:creator>mansfield</dc:creator><description>&lt;p&gt;Thank you very much! I have changed the priority of the timer to level 3. Now I&amp;#39;m migrating to sdk 8.1.1. Does this problem fixed in 8.1.1?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/thread/42572?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 15:25:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:598a3a99-73ac-44eb-a87f-bee6ea5029be</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi mansfield&lt;/p&gt;
&lt;p&gt;The timer frequency is rather high and I suspect this is a CPU utilization problem. The flash operation most likely can not be scheduled with such high frequency Timer interrupts. Ongoing flash operation blocks the CPU.&lt;/p&gt;
&lt;p&gt;The softdevice calls sd_flash_page_erase, sd_flash_protect and sd_flash_write are handled with ARM priority 2. When you have the timer interrupt priority high (arm priority 1) it has higher priority than the flash operation. When you have the timer interrupt priority low (arm priority 3) it has lower priority than the flash operation, which means a timer interrupt can&amp;#39;t preempt a flash operation. The execution of the timer interrupt handler is therefore delayed until a flash operation completes.   You could verify if this is the case by connecting a logical analyzer to a GPIO pin and toggle the GPIO pin every time the timer interrupt handler starts executing. If you see that it pauses for some time, that is the pstorage operation at work.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 18.5.2016&lt;/strong&gt;
The conclusion is that there is a bug in pstorage library in SDK 8.1.0 and earlier SDKs that causes a race condition between the thread that calls the pstorage operation and the pstorage callback. The result is that occasionally the pstorage callback handler is not called by the pstorage module. This is evident when the pstorage calling thread is in the main context  and CPU load is high and/or interrupt activity is high. Large BLE activity creates both high CPU and interrupt activity and can cause the bug to appear.&lt;/p&gt;
&lt;p&gt;A workaround is to simply use pstorage module from nRF51 SDK 9.0.0 or more recent. You dont necessarily need to update your whole project to SDK 9.0.0+, you can just replace the pstorage module (pstorage.h, pstorage.c and pstorage_platform.h files) with pstorage module from SDK 9.0.0+. The pstorage module was refactored in SDK 9.0.0, which apparently removed the bug mentioned above. Pstorage is pretty much isolated module. It is not depending on other modules, so migrating only the pstorage module to SDK 9.0.0+ should not be risky. As far as I see, it is only interacting with the two softdevice API flash functions, sd_flash_page_erase and sd_flash_write.&lt;/p&gt;
&lt;p&gt;Note: pstorage_platform.h is pstorage configuration file normally located in your project. If you have configured the pstorage_platform.h file in your project you must configure the new pstorage_platform.h from SDK 9.0.0+ accordingly.&lt;/p&gt;
&lt;p&gt;Bug details:&lt;/p&gt;
&lt;p&gt;Occasionally, callback was not received from pstorage module, making the pstorage module hang.   I found out that the callback was actually received by the pstorage_sys_event_handler in pstorage.c, but still the cb_handler was never called in flash.c. That is because occasionally there was no flash access registered when he callback arrived, i.e.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;m_cmd_queue.flash_access == false
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;making the callback handler think there is no ongoing flash operation, so the handler did nothing. The fault is that in cmd_process function in pstorage.c, which processes pstorage task in the pstorage queue, calls the relevant flash operation (e.g. sd_flash_write) and then sets the flash access flag at the bottom of the function. I suspect this causes a race condition between the cmd_process function to set&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; m_cmd_queue.flash_access = true;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;before the pstorage_sys_event_handler checks for the same flash access flag, i.e. with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;if (m_cmd_queue.flash_access == true)
{
    // Process the callback
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;because if the flash access flag is not true, the pstorage_sys_event_handler will do nothing and the pstorage will hang.&lt;/p&gt;
&lt;p&gt;I suspect this deadlock can only happen when the caller to the pstorage function is in the main context, i.e. with the lowest priority. When the caller has lowest priority, the flash operation callback can preempt the caller and check the flash access flag before the caller can set it. This scenario is more likely to happen when there is increased interrupt activity, i.e. from timers, BLE, or other, as all interrupts can preempt the caller if it runs in the main context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/thread/42571?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2016 15:13:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41980d37-67f6-4379-89d7-62da277758f5</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;What puzzles me is that you mention update operation. If you use S110 flash API directly, it consists of sd_flash_page_erase, sd_flash_protect and sd_flash_write.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/thread/42570?ContentTypeID=1</link><pubDate>Sat, 16 Jan 2016 07:07:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57c5bf81-3605-4bb3-be9f-f717793d7b52</guid><dc:creator>mansfield</dc:creator><description>&lt;p&gt;I am using S110 flash API directly. Frequncy of Timer1 is 6k, and Timer2 is 1k. Some simple compute and io control are running in the interrupt. I didn&amp;#39;t found failure during erase, since this operation runs not so much. So I found failure only at update and write operation.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Urgently!! About flash access</title><link>https://devzone.nordicsemi.com/thread/42569?ContentTypeID=1</link><pubDate>Fri, 15 Jan 2016 12:00:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe84211a-c4f1-40af-bc6e-786acab6c5d8</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi mansfield&lt;/p&gt;
&lt;p&gt;Im not sure why this fails for you with high priority timer.
Are you using the pstorage module or are you using the S110 flash API directly?
Can I ask what you are trying to achieve?
What is the interrupt frequency of your timers?
Does it only fail with flash writes? What about flash erase?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>