<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://test-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>NVS in watchdog callback</title><link>https://test-devzone.nordicsemi.com/f/nordic-q-a/88260/nvs-in-watchdog-callback</link><description>Hi, 
 I&amp;#39;m trying to save system uptime when the watchdog callback occurs. 
 The NVS functionality works when calling nvs_write elsewhere in code. 
 Calling nvs_write inside the watchdog callback, I always receive -ETIMEDOUT. The documentation for NVS</description><dc:language>en-US</dc:language><generator>Telligent Community 13 Non-Production</generator><lastBuildDate>Wed, 25 May 2022 11:55:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://test-devzone.nordicsemi.com/f/nordic-q-a/88260/nvs-in-watchdog-callback" /><item><title>RE: NVS in watchdog callback</title><link>https://test-devzone.nordicsemi.com/thread/369509?ContentTypeID=1</link><pubDate>Wed, 25 May 2022 11:55:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40e96cbe-be48-4d66-afb8-371ce080abd0</guid><dc:creator>user98857</dc:creator><description>&lt;p&gt;It seems to work if I signal a thread from the WDT callback to save the uptime. I suppose the NVS write function have some mutex/semaphore stuff that should not be handled in ISR. However, it is still strange that it work with CONFIG_BT=n.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure whether it is to risky to rely on signaling a thread to save NVS after the&amp;nbsp;watchdog has bitten as the system might be in an unstable state (the task could have crashed).&lt;/p&gt;
&lt;p&gt;Wouldn&amp;#39;t it be better just to allocate a flash area for storing uptime and inside the WDT CB write directly to the flash address without using the NVS driver?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NVS in watchdog callback</title><link>https://test-devzone.nordicsemi.com/thread/369496?ContentTypeID=1</link><pubDate>Wed, 25 May 2022 11:15:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be2ad2f8-6e8e-4945-b826-3a3c5c87cf15</guid><dc:creator>user4240</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the clarification. It does make a difference actually, I assumed you where using the HW WDT (&lt;span class="item"&gt;&lt;a title="WDT &amp;mdash; Watchdog timer" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/wdt.html?cp=4_0_0_5_35"&gt;WDT &amp;mdash; Watchdog timer&lt;/a&gt;&lt;/span&gt;) which is less flexible in that it won&amp;#39;t let you abort or delay an impending reset.&lt;/p&gt;
&lt;p&gt;It doesn&amp;#39;t sound like you are getting the MPU fault as discussed here &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/storage/nvs/nvs.html#troubleshooting"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/storage/nvs/nvs.html#troubleshooting&lt;/a&gt; either. Have you tried to single step through the function to see what condition is causing it to return with this error? &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Edit: &lt;br /&gt;&lt;/strong&gt;Do you have CONFIG_BT_SETTINGS=y enabled as well? &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NVS in watchdog callback</title><link>https://test-devzone.nordicsemi.com/thread/369473?ContentTypeID=1</link><pubDate>Wed, 25 May 2022 09:43:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d50c07c4-7334-4c1a-9d67-3191027a691b</guid><dc:creator>user98857</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;First of all I should mention that task watchdog is used if that changes anything.&lt;/p&gt;
&lt;p&gt;In my watchdog callback I have tried to create a while loop printing the uptime to measure the amount of time available before the reset occours. This gave me around 40 ms which is plenty to save uptime in NVS.&lt;/p&gt;
&lt;p&gt;Since topic creation, I have been succesfull in writing to nvs by taking the WDT sample and added the NVS functionality. However as soon as i set CONFIG_BT=y, the NVS is giving me the ETIMEDOUT error. Why does it not work with BT enabled?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NVS in watchdog callback</title><link>https://test-devzone.nordicsemi.com/thread/369466?ContentTypeID=1</link><pubDate>Wed, 25 May 2022 09:23:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7fbe8200-bcc1-42ae-8e07-eb9edce4438c</guid><dc:creator>user4240</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You only get ~2 32KHz clock cycles from the WDT IRQ is raised until the WD reset will be effectuated, and I doubt this is enough time to perform a flash write. I would rather recommend you to store the uptime to a non-initialized section and RAM as in the sample posted here: &lt;a href="https://test-devzone.nordicsemi.com/f/nordic-q-a/80416/save-register-information-when-watchdog-reset/334194#334194"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/80416/save-register-information-when-watchdog-reset/334194#334194&lt;/a&gt;. You may store the uptime from RAM to flash on the following boot.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>