<?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>Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/53111/flash-storage-not-working-in-ble_evt_handler</link><description>My code bluetooth module hangs if I use flash storage functions inside the ble_evt_handler . I am using the functions from the fstorage example in peripheral folder. I turned on debug, connected to module, updated the value and then it hangs and no matter</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 14 Oct 2019 13:54:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/53111/flash-storage-not-working-in-ble_evt_handler" /><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214881?ContentTypeID=1</link><pubDate>Mon, 14 Oct 2019 13:54:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:077812d5-0f54-4893-ad1d-59c917906894</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Assume this&amp;nbsp;is related to the issue you reported here:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/53201/fds-storing-random-value-when-called-in-ble_evt_handler"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/53201/fds-storing-random-value-when-called-in-ble_evt_handler&lt;/a&gt;?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214740?ContentTypeID=1</link><pubDate>Mon, 14 Oct 2019 07:52:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64eed7a7-b28d-4016-9ace-ab831f1c034d</guid><dc:creator>Ameer Usman</dc:creator><description>&lt;p&gt;Any possible suggestions?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214688?ContentTypeID=1</link><pubDate>Sun, 13 Oct 2019 06:48:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9753b36-e7e7-4825-9537-670f91f233fb</guid><dc:creator>Ameer Usman</dc:creator><description>&lt;p&gt;Just by removing the&amp;nbsp;&lt;strong&gt;wait_for_flash_ready()&amp;nbsp;&lt;/strong&gt;function the program worked in the &lt;strong&gt;ble_evt_handler&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This seems to have solved one issue but here comes another one! &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f603.svg" title="Smiley"&gt;&amp;#x1f603;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The read function is not working properly and is not giving the right value. Ideally it should give the same value which I saved but it is not. Is there a specific prerequisite before performing the read function?&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
NRF_LOG_INFO(&amp;quot;Writing \&amp;quot;%x\&amp;quot; to flash.&amp;quot;, p_data);
err_code = nrf_fstorage_write(&amp;amp;fstorage, 0x3e100, &amp;amp;p_data, length, NULL);
APP_ERROR_CHECK(err_code);

uint8_t m_hello_world[] = &amp;quot;33333333&amp;quot;;
err_code = nrf_fstorage_read(&amp;amp;fstorage, 0x3e100, &amp;amp;m_hello_world, length);

err_code = nrf_fstorage_read(&amp;amp;fstorage, 0x3e100, &amp;amp;p_data, length);
                
NRF_LOG_INFO(&amp;quot;Reading p_data \&amp;quot;%02x%02x%02x%02x\&amp;quot; to flash.&amp;quot;, p_data[0], p_data[1], p_data[2], p_data[3]);
                
NRF_LOG_INFO(&amp;quot;Reading \&amp;quot;%02x%02x%02x%02x\&amp;quot; to flash.&amp;quot;, m_hello_world[0], m_hello_world[1], m_hello_world[2], m_hello_world[3]);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The output I get it:&lt;br /&gt;&lt;br /&gt;&amp;lt;info&amp;gt; app: Initializing nrf_fstorage_sd implementation... &lt;br /&gt;&amp;lt;info&amp;gt; app: Writing &amp;quot;2003FEC6&amp;quot; to flash. &lt;br /&gt;&amp;lt;info&amp;gt; app: Reading p_data &amp;quot;00040020&amp;quot; to flash. &lt;br /&gt;&amp;lt;info&amp;gt; app: Reading &amp;quot;00000000&amp;quot; to flash. &lt;br /&gt;&amp;lt;info&amp;gt; app: UUID Identified &lt;br /&gt;&amp;lt;info&amp;gt; app: Storage event handler &lt;br /&gt;&amp;lt;info&amp;gt; app: --&amp;gt; Event received: wrote 4 bytes at address 0x3E100. &lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t even get the correct data in&amp;nbsp;&lt;strong&gt;p_data.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;Thank you for sticking with me :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214438?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 14:40:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32df7f9e-6895-4f71-9833-2f7d2bb64484</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Please follow the debug guide &lt;a href="https://devzone.nordicsemi.com/question/60125/my-device-is-freezing-and-restarting/#60126"&gt;here&lt;/a&gt;. The code never &amp;quot;freezes&amp;quot; it only end up being in a dead loop or it resets.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How do you call the function ? Have you removed&amp;nbsp;&lt;span&gt;wait_for_flash_ready()&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214378?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 13:03:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24332510-cc30-4d62-92aa-aca8b9379201</guid><dc:creator>Ameer Usman</dc:creator><description>&lt;p&gt;I connect and the logger shows me that it is&amp;nbsp;&lt;strong&gt;Connected&lt;/strong&gt; but when I update the value of the characteristic, which will cause the event handler to initiate, the program freezes. But if I remove line 12-56 (of first code pasted) it works fine. This is the same code that handles the flash storage.&lt;br /&gt;&lt;br /&gt;Like even before coming into the evt_handler the code freezes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214374?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 12:57:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6feb5c6d-923a-4429-9609-fd05b9ca6f3b</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;What exactly not working ? How do you call it out side of ble_evt_handler?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214364?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 12:25:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da4b1fbc-8943-480d-9b86-dce99f3aaaa0</guid><dc:creator>Ameer Usman</dc:creator><description>&lt;p&gt;No its not working even when i secluded it from the ble_evt_handler.&lt;/p&gt;
&lt;p&gt;Any further information I can provide regarding this for diagnosis?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214352?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 12:05:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37a5cd98-1beb-40ab-b7d0-9370b0e9ef9c</guid><dc:creator>Hadi Deknache</dc:creator><description>&lt;p&gt;Do you check the flag inside the loop? I assume that the code you posted above on main is not the one you used?&lt;/p&gt;
&lt;p&gt;e.g.,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;for (;;)
{   
    if(flash_ready)
    {
        flash_Test(); 
    }
    
    idle_state_handle();
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;EDIT:&lt;/p&gt;
&lt;p&gt;Does the code also freeze if you call these in the ble_evt_handler&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;err_code = nrf_fstorage_init(&amp;amp;fstorage, p_fs_api, NULL);
APP_ERROR_CHECK(err_code);             

NRF_LOG_INFO(&amp;quot;Initializing nrf_fstorage_sd implementation...&amp;quot;);

/* Let&amp;#39;s write to flash. */
NRF_LOG_INFO(&amp;quot;Writing \&amp;quot;%x\&amp;quot; to flash.&amp;quot;, p_data);
err_code = nrf_fstorage_write(&amp;amp;fstorage, 0x3e100, &amp;amp;p_data, length, NULL);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and then perform the next read function calls in the&amp;nbsp;&lt;span&gt;fstorage_evt_handler when it triggers&amp;nbsp;&lt;a class="el" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.0.0/group__nrf__fstorage.html#ggaaf3afe024c1f96a15b21f1241c860d2da5e5fbe9199debbb6ace7aeaf777733d2"&gt;NRF_FSTORAGE_EVT_WRITE_RESULT&lt;/a&gt;&amp;nbsp;and vice versa&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;/Hadi&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214348?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 11:51:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:737d16c7-d9d9-4f50-b5eb-8a7eb87fb4fc</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;I agree with Hadi. You shouldn&amp;#39;t call fstorage init and especially&amp;nbsp;wait_for_flash_ready() inside the event handler.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;wait_for_flash_ready()&amp;nbsp;&lt;/span&gt;is a blocking function and the MCU will stuck inside that event handler waiting for the fstorage event. But the event can&amp;#39;t be handled because you are already on the same&amp;nbsp;context priority so the event will not be fetched and you will end up in a dead loop.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In stead you should check for the event inside fstorage_evt_handler().&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214328?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 10:20:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f0f1d5e-1019-4a4d-94fa-cb4126ac812d</guid><dc:creator>Ameer Usman</dc:creator><description>&lt;p&gt;I tried changing a flag that would initiate a snip in the main loop but the code seems to stay under&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;idle_state_handle();&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So I am unable to run it in the main loop.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; But I tried it in a timer, but again the program froze&amp;nbsp;and gave no errors.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash Storage not working in ble_evt_handler</title><link>https://devzone.nordicsemi.com/thread/214324?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 09:59:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e4a2871-2058-4ba5-ad5c-fe8d1c110583</guid><dc:creator>Hadi Deknache</dc:creator><description>&lt;p&gt;Hi Ameer,&lt;/p&gt;
&lt;p&gt;My guess is that the flash storage functions are blocking in the event handler which therefore cause it to freeze. Generally events should be very short and call as few functions as possible in the event handler. A good idea would be to either add app_scheduler in you application or change a flag which you check in a loop if it has been changed and perform the function calls there.&lt;/p&gt;
&lt;p&gt;/Hadi&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>