<?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>nrf_storage_is_busy() never returns false</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67327/nrf_storage_is_busy-never-returns-false</link><description>Hi all, 
 I&amp;#39;m working on a project which I started from the multiperipheral example. I am using SDK 15.3.0 for this. I am developing the software on the nrf52840 DK using softdevice S140. This is my first C project (I used C++ until now) and I use the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 19 Oct 2020 13:04:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67327/nrf_storage_is_busy-never-returns-false" /><item><title>RE: nrf_storage_is_busy() never returns false</title><link>https://devzone.nordicsemi.com/thread/275641?ContentTypeID=1</link><pubDate>Mon, 19 Oct 2020 13:04:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd3fb1c0-2fe8-4ffd-809b-4f0cbb30d7c8</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Then I think it may make sense to use fstorage. I wanted to point it out just in case it had not been considered. Good luck:)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_storage_is_busy() never returns false</title><link>https://devzone.nordicsemi.com/thread/275639?ContentTypeID=1</link><pubDate>Mon, 19 Oct 2020 13:00:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0d2fcf2-a761-4881-b745-7d08f4733ad2</guid><dc:creator>Jur</dc:creator><description>&lt;p&gt;Awesome, thanks a lot for helping me out! The flash write should not be frequent. The device will need to be configured once (through a BLE message) before using it. So the idea is this will only be done a few times in the lifetime of the device &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt; Thanks again for the help. Really appreciated!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_storage_is_busy() never returns false</title><link>https://devzone.nordicsemi.com/thread/275638?ContentTypeID=1</link><pubDate>Mon, 19 Oct 2020 12:56:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8656e5d4-5885-4c92-a2bb-437c243a9faa</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, I don&amp;#39;t foresee any problems with this approach. I actaully did not think of this possibilty. I thought the idea was to use the scheduler for Softevice events so events such as BLE_GATTS_EVT_WRITE didn&amp;#39;t have to be processed in the Softdevice IRQ context.&lt;/p&gt;
&lt;p&gt;And as a side note, for frequent storage of data we generally recommend using&amp;nbsp; &lt;span class="item"&gt;&lt;a title="Flash Data Storage (FDS)" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/lib_fds.html?cp=7_1_3_16"&gt;Flash Data Storage (FDS)&lt;/a&gt;&lt;/span&gt; to manage the storage. It helps limit the number of costly erase operations.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_storage_is_busy() never returns false</title><link>https://devzone.nordicsemi.com/thread/275629?ContentTypeID=1</link><pubDate>Mon, 19 Oct 2020 12:45:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92946677-43b6-493d-bdf7-2bb77042d2e4</guid><dc:creator>Jur</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;br /&gt;&lt;br /&gt;I was thinking about doing it this way:&amp;nbsp;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;BLE_GATTS_EVT_WRITE -&amp;gt; Add data to be processed to scheduler queue.&lt;/li&gt;
&lt;li&gt;return from interrupt&lt;/li&gt;
&lt;li&gt;In main loop, app_sched_execute() is called. -&amp;gt; data found in queue which should be processed.&lt;/li&gt;
&lt;li&gt;data is processed and should be written to flash&lt;/li&gt;
&lt;li&gt;as this is now executed in the main context (through the scheduler), nrf_fstorage_is_busy() should work.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Could you debunk this? Or are you saying that the softdevice uses the very same scheduler?&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Else I think I need to indeed just assume the flash operation will complete succesfully and handle errors when they occur.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_storage_is_busy() never returns false</title><link>https://devzone.nordicsemi.com/thread/275623?ContentTypeID=1</link><pubDate>Mon, 19 Oct 2020 12:33:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2aafd9b6-e5c2-45d2-bf66-021818085632</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The app scheduler will prevent the interrupt from getting blocked. But I&amp;#39;m afraid it won&amp;#39;t solve your problem either, because the softdevice events are added to the scheduler queue and only processed after when returning to the main loop.&lt;/p&gt;
&lt;p&gt;I think usually you can assume that a flash operation will complete succesfully. The fstorage callback will notify the app if there was a problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_storage_is_busy() never returns false</title><link>https://devzone.nordicsemi.com/thread/275570?ContentTypeID=1</link><pubDate>Mon, 19 Oct 2020 10:52:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:059aca8f-19df-4c5a-bd70-ff86441ac59d</guid><dc:creator>Jur</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;br /&gt;&lt;br /&gt;Thanks for the fast response! The write function is called after a BLE write operation, which I guess is handled by the softdevice. So basically you&amp;#39;re saying that I am blocking the softdevice interrupt with this? If I understand you correctly I could make the BLE write event trigger an interupt with pri. &amp;lt; 7 which will write the actual data to flash? I&amp;#39;ll go look for some examples&amp;nbsp;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;As to why I want to make it blocking: I calculate a checksum of the data before writing, and directly after writing I would like to read the data again and make sure the checksum matches. I could do this by passing the checksum as an argument to the fstorage_write function, so I can do the check on a NRF_FSTORAGE_EVT_WRITE_RESULT. However, I write to flash for different reasons, which require different actions after the write. So I think making it blocking will make it a cleaner implementation for my purpose.&lt;br /&gt;&lt;br /&gt;Update: It seems it isn&amp;#39;t a matter of just calling an interrupt from the BLE write event. How is this normally done? When data is written to the device, I think it shouldn&amp;#39;t be processed within the BLE_GATTS_EVT_WRITE or should it?&lt;/p&gt;
&lt;p&gt;Update2: Is it usual to use the Scheduler for this?&lt;/p&gt;
&lt;p&gt;Update3: &lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/software-development-kit/posts/scheduler-tutorial"&gt;The scheduler&lt;/a&gt; seems to be exactly what I need for this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf_storage_is_busy() never returns false</title><link>https://devzone.nordicsemi.com/thread/275565?ContentTypeID=1</link><pubDate>Mon, 19 Oct 2020 10:38:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3c7f550-216b-4d8a-88ee-d2aa0e59fdf6</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The write_flash() implementation will only work if called from main the context, or from an interrupt context with lower priority than what the Softdevice interrupt has (i.e. no higher than pri. 7 which is also the lowest one available). The reason for this is that the softdevice interrupt is used to notify&amp;nbsp; the app/fstorage when an asynchrounus flash operation is complete, so if it gets blocked,&amp;nbsp; the fstorage &amp;#39;busy&amp;#39; state will never get cleared.&lt;/p&gt;
&lt;p&gt;Have you considered not making the API blocking? Note that fstorage has an internal queue, so you can queue up multiple write commands without&amp;nbsp; any delays in-between.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>