<?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>sd_flash_* operations no longer working after SDK(14.2) -&amp;gt; (15.2) and SD(5.1) -&amp;gt; (6.1.1) migration</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/85104/sd_flash_-operations-no-longer-working-after-sdk-14-2---15-2-and-sd-5-1---6-1-1-migration</link><description>Hi there, 
 I&amp;#39;m in the midst of migrating between SDK14.2-&amp;gt;15.2, and SD 5.1-&amp;gt;6.1 
 I&amp;#39;m calling sd_flash_write() and sd_flash_page_erase() before enabling the SoftDevice with no issue, however, once I enable the softdevice these functions return NRF_ERROR_BUSY</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Mar 2022 17:28:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/85104/sd_flash_-operations-no-longer-working-after-sdk-14-2---15-2-and-sd-5-1---6-1-1-migration" /><item><title>RE: sd_flash_* operations no longer working after SDK(14.2) -&gt; (15.2) and SD(5.1) -&gt; (6.1.1) migration</title><link>https://devzone.nordicsemi.com/thread/355650?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 17:28:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9e2b5864-6874-44ef-8870-e3b8371cb9c4</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Do&amp;nbsp;sd_evt_get() return NRF_SUCCESS or&amp;nbsp;NRF_ERROR_NOT_FOUND? Does your &amp;quot;workaround&amp;quot; also work if you do not call&amp;nbsp;&lt;span&gt;sd_evt_get() inside the loop? Or if you only call&amp;nbsp;sd_evt_get() inside the loop?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_flash_* operations no longer working after SDK(14.2) -&gt; (15.2) and SD(5.1) -&gt; (6.1.1) migration</title><link>https://devzone.nordicsemi.com/thread/355405?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 01:46:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f7a4c2c-67b6-4044-82e7-1f18625cd463</guid><dc:creator>Matthew Leroy Stephens</dc:creator><description>&lt;p&gt;Looks like I found a workaround?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;If I create a 1000 attempt retry loop, and call sd_evt_get after attempting to call sd_flash*, the next time I attempt sd_flash*, it works.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    for (uint16_t i = 0; i &amp;lt; 1000; i++)
    {
      err_code = sd_flash_page_erase(page_to_erase + i);
      if (err_code == NRF_SUCCESS)
        break;

      uint32_t evt = 0;
      sd_evt_get(&amp;amp;evt);
      nrf_delay_ms(1);
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The flash operations in my application as critical, so I&amp;#39;m interested in reason why these functions are behaving this way.&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: sd_flash_* operations no longer working after SDK(14.2) -&gt; (15.2) and SD(5.1) -&gt; (6.1.1) migration</title><link>https://devzone.nordicsemi.com/thread/355375?ContentTypeID=1</link><pubDate>Mon, 28 Feb 2022 19:03:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:276aa329-6370-46a2-b297-e7ce8e56013a</guid><dc:creator>Matthew Leroy Stephens</dc:creator><description>&lt;p&gt;Thanks for you detailed response,&lt;/p&gt;
&lt;p&gt;Other than&amp;nbsp;a&amp;nbsp;configuration issue in sdk_config.h, I don&amp;#39;t know how my application could be causing this behavior. I made a test main() which only runs the&amp;nbsp;code snippets I shared, so nothing else is happening. Are there any relevant configuration macros in sdk_config.h that could be causing this?&lt;/p&gt;
&lt;p&gt;I also went ahead and tried registering a SDH_SOC observer to print some output when the FLASH_OPERATION_* event is&amp;nbsp;generated, but it never runs.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void soc_handler(uint32_t evt_id, void * p_context)
{
//This never prints, soc_handler never called?
  UART_CRITICAL_PRINTF(&amp;quot;soc_handler evt_id:%d&amp;quot;, evt_id); 
}

NRF_SDH_SOC_OBSERVER(obs, 1, soc_handler, NULL);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It seems like the FLASH_OPERATION event is never being generated so the SD always&amp;nbsp;believes it&amp;#39;s busy, returning the error that I&amp;#39;m seeing.&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: sd_flash_* operations no longer working after SDK(14.2) -&gt; (15.2) and SD(5.1) -&gt; (6.1.1) migration</title><link>https://devzone.nordicsemi.com/thread/355005?ContentTypeID=1</link><pubDate>Fri, 25 Feb 2022 11:40:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e6b2c23f-ac97-4cf5-b3cf-3959d36210a4</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I tried adding your code examples to the ble_app_beacon example in nRF5 SDK v15.2.0, by replacing the ble_stack_init function and removing the advertising parts. With this configuration, I&amp;#39;m not getting the NRF_ERROR_BUSY return code from the second call to&amp;nbsp;sd_flash_page_erase(). This leads me to believe there is something else in your application causing this behavior. Attaching the example project for reference:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ble_5F00_app_5F00_sd_5F00_flash_5F00_sdk15.2.0_5F00_s132_5F00_v6.1.1.zip"&gt;devzone.nordicsemi.com/.../ble_5F00_app_5F00_sd_5F00_flash_5F00_sdk15.2.0_5F00_s132_5F00_v6.1.1.zip&lt;/a&gt;&lt;/p&gt;
[quote user="Patriks74"]In regards to fstorage, it&amp;#39;s my understanding that nrf_fstorage_write() enqueues a flash write operation onto the application event queue (which is eventually serviced through a call to app_sched_execute())[/quote]
&lt;p&gt;Fstorage does not use the application scheduler library. It has its own queue implementation, which enables you to schedule multiple flash operations from the application, without having to wait for the Softdevice to complete the previous operation, but it does not depend on the application to execute the scheduled operations. When you call the fstorage write or erase functions, the operation is added to the queue, but the function will immediately call the&amp;nbsp;queue_start() function to start processing the queued operations. When a flash operation is completed, fstorage library will be notified by the Softdevice flash event, and fstorage will start the next queued flash operation.&lt;/p&gt;
[quote user="Patriks74"]whereas sd_flash* directly kicks of a flash operation (blocking if SD enabled, async if not).[/quote]
&lt;p&gt;The softdevice will accept a requested flash operation, but it will schedule the execution between other BLE activity. See&amp;nbsp;&lt;a title="Flash memory API" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/flash_mem_api/flash_mem_api.html?cp=4_7_3_0_7"&gt;Flash memory API&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a title="Scheduling" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/multilink_scheduling/multilink_scheduling.html?cp=4_7_3_0_14"&gt;Scheduling&lt;/a&gt;. This implies that it is not safe to use a delay set to the maximum time for the flash operation according to the product specification, you need to wait for the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v6.1.1/group___n_r_f___s_o_c___e_n_u_m_s.html#gga2a3d2f55035ee3173aff0c05465fb648a566ef9d8a97914dd30cd152bdfcd50e6"&gt;NRF_EVT_FLASH_OPERATION_SUCCESS&lt;/a&gt;/&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s132.api.v6.1.1/group___n_r_f___s_o_c___e_n_u_m_s.html#gga2a3d2f55035ee3173aff0c05465fb648a7c0083f76ab9ee6e75369776526d584d"&gt;NRF_EVT_FLASH_OPERATION_ERROR&lt;/a&gt;&lt;span&gt;&amp;nbsp;events before starting a new operation.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_flash_* operations no longer working after SDK(14.2) -&gt; (15.2) and SD(5.1) -&gt; (6.1.1) migration</title><link>https://devzone.nordicsemi.com/thread/354900?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 22:28:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28cc31eb-06a6-4fde-a908-6ce1f4f44f94</guid><dc:creator>Matthew Leroy Stephens</dc:creator><description>&lt;p&gt;in my last paragraph, I meant to say *async if SD enabled, blocking if not*&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_flash_* operations no longer working after SDK(14.2) -&gt; (15.2) and SD(5.1) -&gt; (6.1.1) migration</title><link>https://devzone.nordicsemi.com/thread/354897?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 21:57:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28adebe3-c57e-4cfb-8110-d60cc4aae6b5</guid><dc:creator>Matthew Leroy Stephens</dc:creator><description>&lt;p&gt;Hi Jorgen,&lt;/p&gt;
&lt;p&gt;I think I have identified part of the issue.&lt;/p&gt;
&lt;p&gt;I can call many successful sd_flash* operations before enabling the SD, but but after I enable the SD, it always returns busy. However, if I do not call an sd_flash* function before enabling the SD, sd_flash*&amp;nbsp;invocations return NRF_SUCCESS the first time, and NRF_BUSY thereafter.&lt;/p&gt;
&lt;p&gt;(I am using the Softdevice handler library by calling nrf_sdh_enable_request(), though I am not registering an nrf_soc observer.)&lt;/p&gt;
&lt;p&gt;Example:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;  ret_code_t err_code = (ret_code_t)NRF_SUCCESS;

  // Initialize the SoftDevice handler module.
  err_code = (ret_code_t)nrf_sdh_enable_request();//returns NRF_SUCCESS

  // Fetch the start address of the application RAM.
  uint8_t const conn_cfg_tag = 1;                
  uint32_t ram_start = 0;
  err_code = (ret_code_t)nrf_sdh_ble_default_cfg_set(conn_cfg_tag, &amp;amp;ram_start);  

  // enable SoftDevice
  err_code = (ret_code_t)sd_ble_enable(&amp;amp;ram_start);

  err_code = sd_flash_page_erase(0x76);// returns NRF_SUCCESS
  
  rf_delay_ms(90); //flash operation takes maximum of 90ms

  err_code = sd_flash_page_erase(0x76);// returns NRF_BUSY&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Example 2:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;  ret_code_t err_code = (ret_code_t)NRF_SUCCESS;

  // Initialize the SoftDevice handler module.
  err_code = (ret_code_t)nrf_sdh_enable_request();//returns NRF_SUCCESS

  // Fetch the start address of the application RAM.
  uint8_t const conn_cfg_tag = 1;                
  uint32_t ram_start = 0;
  err_code = (ret_code_t)nrf_sdh_ble_default_cfg_set(conn_cfg_tag, &amp;amp;ram_start);  

  err_code = sd_flash_page_erase(0x76);// returns NRF_SUCCESS

  // enable SoftDevice
  err_code = (ret_code_t)sd_ble_enable(&amp;amp;ram_start);
  
  rf_delay_ms(90); //flash operation takes maximum of 90ms

  err_code = sd_flash_page_erase(0x76);// returns NRF_BUSY&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m calling these functions in the main context.&lt;br /&gt;&lt;br /&gt;In regards to fstorage, it&amp;#39;s my understanding that nrf_fstorage_write() enqueues a flash write operation onto the application event queue (which is eventually serviced through a call to app_sched_execute()), whereas sd_flash* directly kicks of a flash operation (blocking if SD enabled, async if not). Is this correct?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sd_flash_* operations no longer working after SDK(14.2) -&gt; (15.2) and SD(5.1) -&gt; (6.1.1) migration</title><link>https://devzone.nordicsemi.com/thread/354759?ContentTypeID=1</link><pubDate>Thu, 24 Feb 2022 10:17:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a34f4cf5-1425-4568-8744-f828df663981</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Do the first call to&amp;nbsp;&lt;span&gt;sd_flash_write()/sd_flash_page_erase() after enabling the softdevice return successfully?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Are you processing the events from the softdevice? E.g through the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_softdevice_handler.html"&gt;Softdevice handler library&lt;/a&gt;, etc?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Are you calling the functions from main context or interrupt context? Can you post a minimal code showing how we can reproduce this problem?&lt;/span&gt;&lt;/p&gt;
[quote user=""]I would prefer to use the SoftDevice directly (as opposed to Fstorage)&amp;nbsp;to leverage it&amp;#39;s async properties.[/quote]
&lt;p&gt;&lt;span&gt;Fstorage is also using the sd_flash* API in its &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_fstorage.html#lib_fstorage_sd"&gt;Softdevice backend&lt;/a&gt;. It is not possible to write/erase the flash through NVMC peripheral when the softdevice is enabled, without using the Softdevice APIs.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>