<?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>Using wait_for_flash_ready() causes firmware to restart after exception</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84775/using-wait_for_flash_ready-causes-firmware-to-restart-after-exception</link><description>Hi, 
 this is kind of continuation of my previous ticket . After solving it the last time I thought that I don&amp;#39;t need wait_for_flash_ready() function as it caused some problems and the code was working good enough without it. Right now I face the problem</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 25 Feb 2022 14:36:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84775/using-wait_for_flash_ready-causes-firmware-to-restart-after-exception" /><item><title>RE: Using wait_for_flash_ready() causes firmware to restart after exception</title><link>https://devzone.nordicsemi.com/thread/355068?ContentTypeID=1</link><pubDate>Fri, 25 Feb 2022 14:36:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb98ba32-47bd-4838-8f6c-c7a3a2f76cc1</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The call stack shows that the&amp;nbsp;&lt;span&gt;wait_for_flash_ready() is called in interrupt context from a BLE event, which again calls the sd_app_evt_wait(). This is most likely causing the issue because the program is waiting for a lower priority event to complete from a higher priority event. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you want to do a reset after the&amp;nbsp;wait_for_flash_ready() has completed then I would first move&amp;nbsp;wait_for_flash_ready() to the main loop so that it runs in the main context. Next, set a flag in the BLE interrupt routine that is checked in the main loop and signalizes that&amp;nbsp;wait_for_flash_ready() can be called. After that I would use the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_pwr_mgmt.html?cp=8_1_3_36"&gt;power management&amp;nbsp;module and call NRF_PWR_MGMT_CONFIG_AUTO_SHUTDOWN_RETRY&lt;/a&gt;&amp;nbsp;instead of sd_app_wait() for the nRF to reset. See the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/pwr_mgmt_example.html?cp=8_1_4_6_21"&gt;power management&amp;nbsp;example&lt;/a&gt;&amp;nbsp;in the SDK for a reference on how the module is used.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Jared&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using wait_for_flash_ready() causes firmware to restart after exception</title><link>https://devzone.nordicsemi.com/thread/354731?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 08:27:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c97069f5-143e-4d8a-90a5-4bb8db5ed37c</guid><dc:creator>crl</dc:creator><description>&lt;p&gt;In the attachement there is a screenshot of call stack from VSCode.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m calling wait_for_flash_ready() right after nrf_fstorage_write or nrf_fstorage_erase. I was looking through the code but I cannot find any interrupt priority modifications. In the code I have a comment by my predecessor:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;NRF52 sdk is relatively high-level, no raw interrupt handling is done by us,
except for the hard fault handler.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So I think I can assume that fstorage has the standard priority, whatever it is. Is there any way to check it?&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/2022_2D00_02_2D00_23-15_2D00_08_2D00_57.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using wait_for_flash_ready() causes firmware to restart after exception</title><link>https://devzone.nordicsemi.com/thread/354373?ContentTypeID=1</link><pubDate>Tue, 22 Feb 2022 13:46:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:643dbf0f-f5d1-40c7-a5f7-b497b71a2033</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could you show the call stack from debug view? What context are you calling&amp;nbsp;&lt;span&gt;wait_for_flash_ready() from, and what interrupt priority do you have on the fstorage module?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Jared&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using wait_for_flash_ready() causes firmware to restart after exception</title><link>https://devzone.nordicsemi.com/thread/354028?ContentTypeID=1</link><pubDate>Mon, 21 Feb 2022 07:02:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b266e3f1-8cfb-4a3b-a240-803fc8a7f069</guid><dc:creator>crl</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Unfortunately I cannot share my code explicitly, rewriting it to paste it here might not be useful as it will look like the one used in an example.&lt;/p&gt;
&lt;p&gt;As my collegue found, the sdk_config.h used in this project is older than used sdk (copyright 2019 vs 2020). Might that or inproperly configured config file be the case?&lt;br /&gt;I will include the newer one first, then include project-oriented config and check if it will help.&lt;/p&gt;
&lt;p&gt;[EDIT]&lt;/p&gt;
&lt;p&gt;I found out that sdk_config.h is oddly included, I will redo it. For previous testing I just added two includes into main but nothing changed, nrf_wait_for_flash_ready() still causes a restart.&lt;/p&gt;
&lt;p&gt;I found out why previously I just used __WFE(). Function power_manage from fstorage example has a macro that depends on SD (if it is present) &lt;span style="text-decoration:line-through;"&gt;but the only difference is that with SD present it returns NRF_SUCCESS. If I put __WFE() into my wait_for_flash_ready function it will crash. __WFE is a macro defined in CMSIS, so it should be properly working. I will investigate how the CMSIS is used as that will probably be the source of all this hassle. &lt;br /&gt;&lt;/span&gt;[I was wrong here. VSCode sent me to wrong file (nrf_soc_nosd). I should've looked at softdevice/s132/headers/nrf_soc.h and here sd_app_evt_wait is called by SVCALL which causes the fault. Anyway, __WFE used directly causes fault too, but it should not be used with SD.]&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using wait_for_flash_ready() causes firmware to restart after exception</title><link>https://devzone.nordicsemi.com/thread/353835?ContentTypeID=1</link><pubDate>Fri, 18 Feb 2022 12:25:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e92307ff-cbd9-4c8f-8bae-849d67cd4d66</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could you share your code?&lt;/p&gt;
[quote user=""]In sdk_config I have FDS_BACKEND configured to use SD (FDS_BACKEND 2).[/quote]
&lt;p&gt;This definition is relevant for the flash data storage(fds) module, not the flash storage(fstorage) module which is a lower-level module.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using wait_for_flash_ready() causes firmware to restart after exception</title><link>https://devzone.nordicsemi.com/thread/353357?ContentTypeID=1</link><pubDate>Wed, 16 Feb 2022 13:11:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1cfa8cf2-6dc5-41a8-bc89-41f1b7a9f447</guid><dc:creator>crl</dc:creator><description>&lt;p&gt;About the incorrectly written bytes I just made a simple table which shows (I hope clearly) what happens. Be advised that there are leading zeroes (mostly) that will fill up the structure up to 200 bytes, the structures you see are ending bytes.&lt;br /&gt;I have not found any signs of in-code modifications of this structure other than flash write/read.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/2022_2D00_02_2D00_16-14_2D00_06_2D00_43.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using wait_for_flash_ready() causes firmware to restart after exception</title><link>https://devzone.nordicsemi.com/thread/353349?ContentTypeID=1</link><pubDate>Wed, 16 Feb 2022 12:49:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e844356-8920-4b0a-8ae6-986715e231d8</guid><dc:creator>crl</dc:creator><description>&lt;p&gt;There is no error during J-Link - terminal debugging but using Cortex Debug plugin in VSCode throws &amp;quot;Exception has occured&amp;quot; as a baloon and not much else. In terminal I can see that even if I let the program run without breakpoints it stops at specific points where flash is erased or written to.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/2022_2D00_02_2D00_16-13_2D00_48_2D00_23.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using wait_for_flash_ready() causes firmware to restart after exception</title><link>https://devzone.nordicsemi.com/thread/353346?ContentTypeID=1</link><pubDate>Wed, 16 Feb 2022 12:25:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c5fc847-cff0-465b-a359-fcb9e7b86865</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote user=""]I am using copied parts of code from fstorage example. When the code calls wait_for_flash_ready() it reaches SVCALL(SD_APP_EVT_WAIT, uint32_t, sd_app_evt_wait(void)); in nrf_soc.h (sdk/components/softdevice/s132/headers) and there an exception occurs.[/quote]
&lt;p&gt;What kind of error is thrown? Could you share a screenshot from debug view highlighting the error?&lt;/p&gt;
&lt;p&gt;&lt;span&gt;regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;Jared&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>