<?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>FATAL ERROR using NVS for writing to flash while BLE is active</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/104936/fatal-error-using-nvs-for-writing-to-flash-while-ble-is-active</link><description>Hi All, 
 I&amp;#39;m updating some configuration parameters, which I store in flash using the NVS API, inside the callback that handles a characteristic write. So, flash writes occur while BLE is active. 
 Whenever I write to flash using nvd_write() a FATAL</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 28 Oct 2023 15:24:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/104936/fatal-error-using-nvs-for-writing-to-flash-while-ble-is-active" /><item><title>RE: FATAL ERROR using NVS for writing to flash while BLE is active</title><link>https://devzone.nordicsemi.com/thread/452874?ContentTypeID=1</link><pubDate>Sat, 28 Oct 2023 15:24:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44b625d2-f4dc-49a7-9082-d62cc9273b60</guid><dc:creator>V.Lorz</dc:creator><description>&lt;p&gt;Sigurd, thanks for your support, it guided me to look at the right place.&lt;/p&gt;
&lt;p&gt;I needed to explicitly set CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE=n, and found out that the effective chain of calls until it arrived to the driver&amp;#39;s flash write function required a much larger stack for the work queue.&lt;/p&gt;
&lt;p&gt;I already had a work thread for low priority tasks with a suitable stack size and deferred the flash write operation to that thread instead of adding more RAM usage to the application.&lt;/p&gt;
&lt;p&gt;Thanks again, BR&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FATAL ERROR using NVS for writing to flash while BLE is active</title><link>https://devzone.nordicsemi.com/thread/452498?ContentTypeID=1</link><pubDate>Thu, 26 Oct 2023 10:42:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:667d8bd4-3738-4193-a151-833b31b7036b</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Aha, yea no then it should not matter that it is called from a callback I think.&lt;/p&gt;
&lt;p&gt;The NVS drivers use the flash API, which is defined for nrf &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/main/drivers/flash/soc_flash_nrf.c"&gt;here&lt;/a&gt;.&lt;/p&gt;
[quote user="V.Lorz"]BLE has very tight timing requirements, so flash operations MUST be executed synchronized with its operation.[/quote]
&lt;p&gt;You are right, and this is already taken into account in our SDK, as long as &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index.html#CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE"&gt;CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE&lt;/a&gt; is not set. You can see how this is handled in the &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/2e2523efe52a7ac89f0567b8798fd857b1e71ae3/drivers/flash/soc_flash_nrf.c#L211C9-L222"&gt;flash write driver&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Can you check this option for your project?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FATAL ERROR using NVS for writing to flash while BLE is active</title><link>https://devzone.nordicsemi.com/thread/452368?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2023 19:33:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5d8c34f-e88b-4ccc-9ba5-83097037ddc3</guid><dc:creator>V.Lorz</dc:creator><description>&lt;p&gt;One thing to note here is the callback function is not called from inside an ISR context, but from a work thread. Zephyr does that for us, which is nice and convenient.&lt;/p&gt;
&lt;p&gt;Of course I can enqueue the job for later, but I can still face the same issue at random because the origin is BLE has very tight timing requirements, so flash operations MUST be executed synchronized with its operation.&lt;/p&gt;
&lt;p&gt;Question remains the same: How can I achieve that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FATAL ERROR using NVS for writing to flash while BLE is active</title><link>https://devzone.nordicsemi.com/thread/451883?ContentTypeID=1</link><pubDate>Tue, 24 Oct 2023 06:42:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:851ae4d2-052a-4440-acdb-f8c058ab4f38</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;I recommend not calling NVS functions from a callback.&lt;/p&gt;
&lt;p&gt;Instead, either do it the easy way and set a global variable that you poll in a thread somewhere.&lt;br /&gt;Or, do it the more clean way and use a &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/kernel/services/threads/workqueue.html"&gt;work queue&lt;/a&gt; which you trigger from the callback.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FATAL ERROR using NVS for writing to flash while BLE is active</title><link>https://devzone.nordicsemi.com/thread/451767?ContentTypeID=1</link><pubDate>Mon, 23 Oct 2023 14:21:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71492239-e11e-4e99-a0bf-3880173f16ad</guid><dc:creator>V.Lorz</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Yes, I do, I write to NVS &amp;quot;inside the callback that handles a characteristic write.&amp;quot;&lt;/p&gt;
&lt;p&gt;The test I mentioned that works OK is writing/reading before initializing BLE.&lt;/p&gt;
&lt;p&gt;BR&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FATAL ERROR using NVS for writing to flash while BLE is active</title><link>https://devzone.nordicsemi.com/thread/451692?ContentTypeID=1</link><pubDate>Mon, 23 Oct 2023 11:40:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7df7c656-0526-4c3a-a673-e1ba89bc6f04</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Do you by chance write to NVS from a BLE callback?&lt;/p&gt;
&lt;p&gt;If not, can you explain a bit on how you test writing to NVS while BLE is on?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>