<?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 erase/write problems</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/60113/flash-erase-write-problems</link><description>I&amp;#39;ve spent several days reading all the support tickets regarding this issue but I cannot find a resolution. 
 I am running the ble_central_uart example with SD 132, SES 4.30, SDK 15.3 on an nRF52 DK dev board. 
 I have been unable to erase flash consistently</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 27 Apr 2020 13:21:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/60113/flash-erase-write-problems" /><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/246874?ContentTypeID=1</link><pubDate>Mon, 27 Apr 2020 13:21:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e01990f-e57c-40b0-8f0f-7bc575966f7f</guid><dc:creator>EricDelangis</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;That explains a lot. I thought that I wasn&amp;#39;t in an interrupt while running my main service function.&amp;nbsp; Can you direct me to some documentation that explains the underlying design philosophy to this system?&amp;nbsp; Does it use a Linux kernel?&amp;nbsp; How do the SDs operate and interact with user code?&amp;nbsp; Who does per review?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/246820?ContentTypeID=1</link><pubDate>Mon, 27 Apr 2020 12:21:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97f802dd-c311-4812-ba79-a97e813bd3b2</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;There are tons of things that are wrong in your program. And I strongly suggest you to get your code peer reviewed. I have not done any detailed code review but spending 5 minutes with main.c file I see that you call&amp;nbsp;ble_nus_c_evt_handler-&amp;gt;&amp;nbsp;ble_handle_message-&amp;gt;convert_temperature_values-&amp;gt;update_flash_info-&amp;gt;erase_flash-&amp;gt;While(never_ending_loop)&lt;/p&gt;
&lt;p&gt;Basically doing a flash activity inside the BLE event handler and waiting for an event while in interrupt context is not a good idea at all. You need to probably use app_scheduler to push all this activity you are doing for converting temperature values into thread context instead of doing so much oeprations inside an interrupt context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/246562?ContentTypeID=1</link><pubDate>Fri, 24 Apr 2020 14:20:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e344c4f2-b698-46e6-93a8-952cb326c499</guid><dc:creator>EricDelangis</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;I do not like hard delays either but I&amp;#39;ve been unable to get anything else working properly.&amp;nbsp; Though, I&amp;#39;ve got my doubts about hard delays working properly without excessively long delays that will affect the SD.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve attached my code.&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/2043._2100_PerfShwrValve.zip"&gt;/cfs-file/__key/communityserver-discussions-components-files/4/2043._2100_PerfShwrValve.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can unzip in examples directory.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/246471?ContentTypeID=1</link><pubDate>Fri, 24 Apr 2020 11:00:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63985060-132d-4b43-a727-c71642b50be9</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Can you please upload your whole project, so that I can look at the contexts properly to be able to give any suggestions to you.&lt;/p&gt;
[quote user="EricDelangis"]Do you have example code that uses hard delays (nrf_delay_xx)?[/quote]
&lt;p&gt;&amp;nbsp;We normally use a timer asynchronous delay instead of of busy delays when we are using softdevice, since most of the processing is done in the interrupt handlers with BLe activity. It does not mean that you can not use a busy delay nrf_delay_ms when executing in Thread context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245887?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 15:27:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af129dd5-b6f0-4495-8252-d155d6d3c28a</guid><dc:creator>EricDelangis</dc:creator><description>&lt;p&gt;So, how do I get around this so the flash erase and writes are reliable?&amp;nbsp; Do you have example code that uses hard delays (nrf_delay_xx)?&amp;nbsp; I can live with the delays as long as the SD 132 can.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245703?ContentTypeID=1</link><pubDate>Tue, 21 Apr 2020 06:44:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18b53fa3-c061-49b0-91ab-b3985b4248b0</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="EricDelangis"]Are you sure that I don&amp;#39;t have any coding errors that are causing the problems?&amp;nbsp;[/quote]
&lt;p&gt;&amp;nbsp;Hi Eric,&lt;/p&gt;
&lt;p&gt;I cannot answer that since I do no know the contexts of all the calls happening. But if you are calling&amp;nbsp;erase_flash_page and&amp;nbsp;write_flash_page from Thread context, then I do not see anything in your code that blocks the SD events indefinitely.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245377?ContentTypeID=1</link><pubDate>Sun, 19 Apr 2020 16:59:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f1580d0-ec6b-40fe-b7fe-408426e4380e</guid><dc:creator>EricDelangis</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;Are you sure that I don&amp;#39;t have any coding errors that are causing the problems?&amp;nbsp; I am not using interrupts, only timers and I don&amp;#39;t have any while() statements in my&amp;nbsp;timer handling routines.&amp;nbsp; Am I correctly processing the SD event?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245368?ContentTypeID=1</link><pubDate>Sun, 19 Apr 2020 10:49:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8cc7c2b6-48d7-40b7-8d9c-8d2bb0616edc</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;They should work, your application should have received SD events unless your application has while() statement in an interrupt context that blocks the SD_EVT_IRQHandler&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245241?ContentTypeID=1</link><pubDate>Fri, 17 Apr 2020 13:03:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e7d298f-e3f0-445f-b02a-d3a9be11e6b6</guid><dc:creator>EricDelangis</dc:creator><description>&lt;p&gt;I put this code in because the SD events functions were not working.&amp;nbsp; I left them in because they don&amp;#39;t affect the writing&amp;nbsp;anyway.&amp;nbsp; Even so, the SD events aren&amp;#39;t working so this code should allow enough time for a write to work.&amp;nbsp; However, it doesn&amp;#39;t work reliably anyway.&amp;nbsp; I will remove this code once the SD events are confirmed to be working.&lt;/p&gt;
&lt;p&gt;Why aren&amp;#39;t my SD events working?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245148?ContentTypeID=1</link><pubDate>Fri, 17 Apr 2020 08:02:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:669befe9-871b-46a5-8512-463094391fab</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Why do you have the below?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    while(!flash_operation_completed)
    {
//    nrf_delay_ms(100);     // 85ms minimum flash time to finish erase cycle
//    sd_app_evt_wait();
    flash_operation_completed = true;
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If the flash oepration is complete, you will get the event from the SD, why do you force it to be completed within 100ms anyways. Then there would be no point in having the events.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245090?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 19:41:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5163410d-cb0f-4f0c-bff1-bcc8b2456b8d</guid><dc:creator>EricDelangis</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;I still can&amp;#39;t get the flash writes working reliably.&amp;nbsp; I found&amp;nbsp;this thread&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/44306/issue-with-nrf_sdh_soc_observer"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/44306/issue-with-nrf_sdh_soc_observer&lt;/a&gt; that solved the same problem as I am having but I haven&amp;#39;t been able to get my code to work.&amp;nbsp; Here&amp;#39;s what I&amp;#39;ve got:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
/****************** Erase Flash ***************************/
void erase_flash_page(void)
{
    NRF_LOG_INFO(&amp;quot;Erasing Flash...&amp;quot;);
    uint32_t evt = 0;
retry_flash:
    flash_operation_completed = false;
    sd_flash_page_erase(pg_num);
/*   
    while(!flash_operation_completed)
    {
      sd_evt_get (&amp;amp;evt);
      if (evt == NRF_EVT_FLASH_OPERATION_SUCCESS || evt == NRF_EVT_FLASH_OPERATION_ERROR)
      {
        flash_operation_completed = true;
        goto resume_flash_operations;
      }
      else 
      {
        start_flash_timer();
        goto retry_flash;
      }
    }
*/
    while(!flash_operation_completed)
    {
//    nrf_delay_ms(100);     // 85ms minimum flash time to finish erase cycle
//    sd_app_evt_wait();
    flash_operation_completed = true;
    }

resume_flash_operations:
    return (12345);
}

/****************** Write Flash ***************************/
void write_flash_page(void)
{
    NRF_LOG_INFO(&amp;quot;Writing Flash...&amp;quot;);
    uint8_t block_size = sizeof(write_flash_block);
    ret_code_t err_code;
    flash_operation_completed = false;
    err_code = sd_flash_write((uint32_t*)flash_addr, (uint32_t*)&amp;amp;write_flash_block, block_size);

    if (err_code != NRF_SUCCESS)
    {
       NRF_LOG_INFO(&amp;quot;Error writing to flash, err_code = \&amp;quot;%x\&amp;quot; .&amp;quot;, err_code);
        if (err_code == NRF_ERROR_INVALID_LENGTH) while (1);
        if (err_code == NRF_ERROR_INVALID_ADDR) while (1);
        if (err_code == NRF_ERROR_BUSY) while (1);
        if (err_code == NRF_ERROR_FORBIDDEN) while (1);
    }

    while(!flash_operation_completed)
    {
    sd_app_evt_wait();
    nrf_delay_ms(2);     // &amp;lt;1 ms minimum flash time to finish write cycle
    flash_operation_completed = true;
    }
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s my nrf_sdh_soc_observer and handler stuff: (Note: I found a thread that talked about enabling&amp;nbsp;NRF_SDH_SOC_ENABLE, it is enabled in the sdk_config.h file, but I can&amp;#39;t find any function in the Nordic directories and I get an error when I try to instantiate it in lines 42-45.)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;  // flash storage handler
static void soc_evt_handler(uint32_t evt_id, void * p_context)
{
    switch (evt_id)
    {
        case NRF_EVT_FLASH_OPERATION_SUCCESS:
        // fall through 
        case NRF_EVT_FLASH_OPERATION_ERROR:

            if (flash_operation_completed)
            {
                flash_operation_completed = false;
            }
            break;

        default:
            // No implementation needed.
              flash_operation_completed = true;
            break;
    }
}
/* ******************************** End *********************************/

static void ble_stack_init(void) {
  ret_code_t err_code;
  uint32_t   ram_start = 0;

  err_code = nrf_sdh_enable_request();
  APP_ERROR_CHECK(err_code);

  // Configure the BLE stack using the default settings.
  // Fetch the start address of the application RAM.
//  uint32_t ram_start = 0;
  err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &amp;amp;ram_start);
  APP_ERROR_CHECK(err_code);

  // Enable BLE stack.
  err_code = nrf_sdh_ble_enable(&amp;amp;ram_start);
  APP_ERROR_CHECK(err_code);

 /*************************** Added by Eric ***********************/
 // Enable SOC.
//  err_code = nrf_sdh_soc_enable();
//  err_code = NRF_SDH_SOC_ENABLE();
//  APP_ERROR_CHECK(err_code);
/* ******************************** End *********************************/

  // Register a handler for BLE events.
  NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);

/*************************** Added by Eric ***********************/
  NRF_SDH_SOC_OBSERVER(m_soc_observer, APP_SOC_OBSERVER_PRIO, soc_evt_handler, NULL);
/*
  // Register with the SoftDevice handler module for BLE events.
  err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
  APP_ERROR_CHECK(err_code);

    /* Request Softdevice to turn on Crystal oscillator to test if SoC events are
       forwarded to the application. _SOC_ observers should get notified of the
       NRF_EVT_HFCLKSTARTED event after this call. */
    err_code = sd_clock_hfclk_request();
    APP_ERROR_CHECK(err_code);
/* ******************************** End *********************************/
}

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245088?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 17:51:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0d50e30e-565f-4757-82d0-cb25b0066ab5</guid><dc:creator>EricDelangis</dc:creator><description>&lt;p&gt;I am using ble_central without modifications. However, I do include ble_uart_central, pwm, saadc and flash functions.&amp;nbsp; A search of the code has NO references to FDS so I don&amp;#39;t know how it saves the keys.&amp;nbsp; And as I said, disabling FDS in sdk_config.h did not generate any errors. The big question is how do I write to flash reliably since it doesn&amp;#39;t return either success for failure messages?&amp;nbsp; With hard delays, i.e. nrf_delay_ms(100), for a flash page erase, and nrf_delay_ms(2) for a flash page write, it sometimes works.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245030?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 13:56:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0d8a51f-1379-4c0c-896d-19736e84fad7</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="EricDelangis"]I&amp;#39;m not sure when you say &amp;quot;&lt;span&gt;You need to differentiate your logic between the completed flag and successful flag.&amp;quot; The problem is that neither flag is getting set!&amp;nbsp; So differentiating at this point will make no difference.&amp;nbsp; I&amp;#39;ll try the soc_evt_handler to see how that works&lt;/span&gt;[/quote]
&lt;p&gt;&amp;nbsp;It means that you need to set &amp;quot;flash_operation_completed = true;&amp;quot; in both&amp;nbsp;NRF_EVT_FLASH_OPERATION_SUCCESS and also in the case&amp;nbsp;NRF_EVT_FLASH_OPERATION_ERROR. This is because&amp;nbsp; your application is depending on the flash operation to complete to exit from the wait loop and if flash operation returns&amp;nbsp;&lt;span&gt;NRF_EVT_FLASH_OPERATION_ERROR, then your application will loop for ever even though there is no ongoing flash operations.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="EricDelangis"]Finally, are you saying that the sd_flash_write/erase functions will work with the ble_central apps and that I don&amp;#39;t need to use FDS?&amp;nbsp; I turned OFF (disabled) FDS in the sdk_config.h file and didn&amp;#39;t get any compile errors so I don&amp;#39;t think that FDS is used for saving ble keys as previously stated by Turbo J.&amp;nbsp; Is that correct?[/quote]
&lt;p&gt;If you are using peer_manager library for storing BLE keys, it does use FDS.&amp;nbsp;I used them in my reply since it seemed that you are using them already based on your original question.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245029?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 13:54:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e82a709-f5a3-42cd-bf34-33614168e310</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;you should add it in the ble_stack_init at the same level where you plugin your&amp;nbsp;ble_evt_handler for your application as BLE events observer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/245024?ContentTypeID=1</link><pubDate>Thu, 16 Apr 2020 13:47:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eab50c5f-ff4a-45b7-84a2-b81114a4ee9e</guid><dc:creator>EricDelangis</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;How does the code you reference work?&amp;nbsp; I can&amp;#39;t seem to get the&amp;nbsp;NRF_SDH_SOC_OBSERVER(m_soc_observer, APP_SOC_OBSERVER_PRIO, soc_evt_handler, NULL); to run.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/244479?ContentTypeID=1</link><pubDate>Tue, 14 Apr 2020 13:59:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7ee3f77-fb43-429d-b5db-1fe7c5327af3</guid><dc:creator>EricDelangis</dc:creator><description>&lt;p&gt;Hi Susheel,&lt;/p&gt;
&lt;p&gt;I am calling my flash routines from my main(void) functions. NOT INTERRUPTS. You said &amp;quot;&lt;span&gt;Then it means that which ever is not the flash event will be ignored completely by your whole application since sd_evt_get pull the event from the buffer and hence the rest of the application will not get any other event while you are calling&amp;nbsp;sd_evt_get (&amp;amp;evt); and ignoring the non flash events.&amp;quot;&amp;nbsp; I had that same thought when working with the sd_evt_get&amp;nbsp;(&amp;amp;evt) function.&amp;nbsp; Thanks for confirming that.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure when you say &amp;quot;&lt;span&gt;You need to differentiate your logic between the completed flag and successful flag.&amp;quot; The problem is that neither flag is getting set!&amp;nbsp; So differentiating at this point will make no difference.&amp;nbsp; I&amp;#39;ll try the soc_evt_handler to see how that works.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Finally, are you saying that the sd_flash_write/erase functions will work with the ble_central apps and that I don&amp;#39;t need to use FDS?&amp;nbsp; I turned OFF (disabled) FDS in the sdk_config.h file and didn&amp;#39;t get any compile errors so I don&amp;#39;t think that FDS is used for saving ble keys as previously stated by Turbo J.&amp;nbsp; Is that correct?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/244401?ContentTypeID=1</link><pubDate>Tue, 14 Apr 2020 11:02:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa1b17bb-5345-42a3-b70e-32c4570124b9</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user=""]This code executes but it does not check for the flash erase function to complete.&amp;nbsp; In debugging the problem, I found that the write function&amp;nbsp;sd_flash_write() was erroring out on&amp;nbsp;err_code == NRF_ERROR_BUSY.&amp;nbsp; So I figured the erase function required more time to complete[/quote]
&lt;p&gt;Are you calling your&amp;nbsp;write_flash_page from main Thread context or an intterrupt context? Calling this interrupt context si not a good idea as you seem to be busy waiting on the flash complete flag&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;sd_evt_get (&amp;amp;evt);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So you are using&amp;nbsp;sd_evt_get (&amp;amp;evt); in your code to know if the flash event is complete or not. Then it means that which ever is not the flash event will be ignored completely by your whole application since sd_evt_get pull the event from the buffer and hence the rest of the application will not get any other event while you are calling&amp;nbsp;sd_evt_get (&amp;amp;evt); and ignoring the non flash events.&lt;/p&gt;
&lt;p&gt;using&amp;nbsp;NRF_EVT_FLASH_OPERATION_SUCCESS/NRF_EVT_FLASH_OPERATION_ERROR both tells that the flash operation has completed and&amp;nbsp;&lt;span&gt;NRF_EVT_FLASH_OPERATION_SUCCESS only tells that the flash operation has been successful. You need to differentiate your logic between the completed flag and successful flag.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;in the file&amp;nbsp;examples\ble_central\ble_app_gatts\main.c you can see that you can plug in a soc_evt_handler as an observer to soc events, you need to do that instead of creating your own callback function&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;NRF_SDH_SOC_OBSERVER(m_soc_observer, APP_SOC_OBSERVER_PRIO, soc_evt_handler, NULL);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/244309?ContentTypeID=1</link><pubDate>Mon, 13 Apr 2020 22:08:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a408182e-bea6-41c6-87bf-020eddb543fd</guid><dc:creator>EricDelangis</dc:creator><description>&lt;p&gt;I was previously told (by another Nordic tech support person) to use the sd_flash_page_erase() / write functions.&amp;nbsp; The problem is that I only need to store a single structure in flash and the FDS code carries a HUGE overhead.&amp;nbsp; Do you have a scaled down example that uses FDS but only deals with storing and reading a few system variables?&amp;nbsp; I don&amp;#39;t need any kind of record processing support.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash erase/write problems</title><link>https://devzone.nordicsemi.com/thread/244270?ContentTypeID=1</link><pubDate>Mon, 13 Apr 2020 07:04:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0c2495d-ad01-42a4-8ace-a646fcc82c45</guid><dc:creator>Turbo J</dc:creator><description>[quote userid="82465" url="~/f/nordic-q-a/60113/flash-erase-write-problems"] I implemented the sd_flash_page_erase() function as follows:[/quote]
&lt;p&gt;That won&amp;#39;t do.&lt;/p&gt;
&lt;p&gt;The ble_* examples already use FDS in order to store BLE data (device keys) in Flash. I strongly recommend using FDS for your application, too.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>