<?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>BLE and flash write problem</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20489/ble-and-flash-write-problem</link><description>Hello, 
 I&amp;#39;m using nrf51822/s130/sdk12.1.0.
Before adding BLE code there&amp;#39;s no problem in writing inner flash.
In main I just added below ble_app_uart codes(not modified). 
 
 ble_stack_init(); 
 gap_params_init(); 
 services_init(); 
 advertising_init</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 18 Mar 2017 01:37:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20489/ble-and-flash-write-problem" /><item><title>RE: BLE and flash write problem</title><link>https://devzone.nordicsemi.com/thread/79900?ContentTypeID=1</link><pubDate>Sat, 18 Mar 2017 01:37:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2aa779e3-392c-4b77-8f1b-a4913180844d</guid><dc:creator>air</dc:creator><description>&lt;p&gt;I will.
Thank you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and flash write problem</title><link>https://devzone.nordicsemi.com/thread/79897?ContentTypeID=1</link><pubDate>Fri, 17 Mar 2017 11:48:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fa6be78-054d-422e-a320-15c6ca263333</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;The required delay depends on if there are some BLE activity going on. Therefore, rather than using a fixed delay, I would recommend you to wait for the event &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s132.api.v4.0.2%2Fgroup___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html&amp;amp;cp=2_3_0_1_1_2_7_2_7&amp;amp;anchor=ga9c93dd94a138ad8b5ed3693ea38ffb3e"&gt;NRF_EVT_FLASH_OPERATION_SUCCESS&lt;/a&gt;, telling that the operation was successfully completed.&lt;/p&gt;
&lt;p&gt;In addition, it is also good practice to check the returned error code when calling a function.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and flash write problem</title><link>https://devzone.nordicsemi.com/thread/79899?ContentTypeID=1</link><pubDate>Fri, 17 Mar 2017 10:35:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1586e97-f048-4d0a-95d0-0bee2cd07e8c</guid><dc:creator>air</dc:creator><description>&lt;p&gt;I solved this problem thanks to you.
In below code is delay time necessary?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sd_flash_page_erase(page);
nrf_delay_ms(ERASE_FLASH_DELAY);   // 5mS
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;//	writeFlashPage(addr, wrData);
sd_flash_write(addr, wrData, cnt);
nrf_delay_ms(WRITE_FLASH_DELAY);   // 5mS&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and flash write problem</title><link>https://devzone.nordicsemi.com/thread/79898?ContentTypeID=1</link><pubDate>Fri, 17 Mar 2017 10:26:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed072b16-6a7d-4ba6-b668-5b9a08f2d659</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Yes, the area you write to has to be erased before writing to it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and flash write problem</title><link>https://devzone.nordicsemi.com/thread/79896?ContentTypeID=1</link><pubDate>Fri, 17 Mar 2017 00:24:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ed6bd24-7703-4766-9103-561111e46667</guid><dc:creator>air</dc:creator><description>&lt;p&gt;I&amp;#39;ll try.
Additionally must I erase before write?
I know that erase is necessary before write commonly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and flash write problem</title><link>https://devzone.nordicsemi.com/thread/79895?ContentTypeID=1</link><pubDate>Thu, 16 Mar 2017 09:24:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c45f8b95-2918-4347-baa8-d4e0eaa303f3</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;When the softdevice is enabled, flash operations should be done using the sd_flash_xx api. For writing to flash, &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s130.api.v2.0.1%2Fgroup___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html&amp;amp;cp=3_7_2_1_0_2_7_2_9&amp;amp;anchor=ga8b49f2e72e97291aecc18ce396956eed"&gt;sd_flash_write()&lt;/a&gt; should be used.&lt;/p&gt;
&lt;p&gt;To simplifying storing data to flash, the library &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v13.0.0%2Flib_fds.html&amp;amp;cp=4_0_0_3_43"&gt;flash data storage&lt;/a&gt; (FDS) can be used.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and flash write problem</title><link>https://devzone.nordicsemi.com/thread/79894?ContentTypeID=1</link><pubDate>Thu, 16 Mar 2017 08:17:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba9675f1-c41b-45b6-b026-df36654a2c6c</guid><dc:creator>air</dc:creator><description>&lt;p&gt;I add my code.&lt;/p&gt;
&lt;p&gt;static void eraseFlashPage(uint32_t * page_address)
{
// Turn on flash erase enable and wait until the NVMC is ready:
NRF_NVMC-&amp;gt;CONFIG = (NVMC_CONFIG_WEN_Een &amp;lt;&amp;lt; NVMC_CONFIG_WEN_Pos);&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy)
{
	// Do nothing.
}

// Erase page:
NRF_NVMC-&amp;gt;ERASEPAGE = (uint32_t)page_address;

while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy)
{
	// Do nothing.
}

// Turn off flash erase enable and wait until the NVMC is ready:
NRF_NVMC-&amp;gt;CONFIG = (NVMC_CONFIG_WEN_Ren &amp;lt;&amp;lt; NVMC_CONFIG_WEN_Pos);

while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy)
{
	// Do nothing.
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;static void writeFlashPage(uint32_t * address, uint8_t  value[])
{
uint16_t i;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Turn on flash write enable and wait until the NVMC is ready:
NRF_NVMC-&amp;gt;CONFIG = (NVMC_CONFIG_WEN_Wen &amp;lt;&amp;lt; NVMC_CONFIG_WEN_Pos);

while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy)
{
	// Do nothing.
}

for(i=0; i&amp;lt;PAGE_PARAMETER_SIZE; i++)
{
	*(address + i) = value[i];
}

while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy)
{
	// Do nothing.
}

// Turn off flash write enable and wait until the NVMC is ready:
NRF_NVMC-&amp;gt;CONFIG = (NVMC_CONFIG_WEN_Ren &amp;lt;&amp;lt; NVMC_CONFIG_WEN_Pos);

while (NRF_NVMC-&amp;gt;READY == NVMC_READY_READY_Busy)
{
	// Do nothing.
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;#define PAGE_SIZE						1024
#define PAGE_PARAMETER_SIZE		PAGE_SIZE / 4		// 256 Byte / 1 page
#define PARAMETER1_ADDR				PAGE_SIZE * 192	// page 192, 0x30000
#define PARAMETER2_ADDR				PAGE_SIZE * 193	// page 192, 0x30400
#define PARAMETER3_ADDR				PAGE_SIZE * 194	// page 192, 0x30800
#define PARAMETER4_ADDR				PAGE_SIZE * 195	// page 192, 0x30c00&lt;/p&gt;
&lt;p&gt;#define ERASE_FLASH_DELAY			5				// 5 mS
#define WRITE_FLASH_DELAY			5				// 5 mS&lt;/p&gt;
&lt;p&gt;void infoSaveToFlash(void)
{
uint32_t err_code;
uint32_t * addr;
uint8_t wrData[PAGE_PARAMETER_SIZE] = {0};
uint16_t i;&lt;/p&gt;
&lt;p&gt;//	__disable_irq();
//	err_code = sd_softdevice_disable();&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;lockInfo.lockStatus = lockPosition;


// PARAMETER1_ADDR
memcpy(wrData, &amp;amp;lockInfo, sizeof(param_t));

addr = (uint32_t *)(PARAMETER1_ADDR);
eraseFlashPage(addr);
nrf_delay_ms(ERASE_FLASH_DELAY);
writeFlashPage(addr, wrData);
nrf_delay_ms(WRITE_FLASH_DELAY);


// PARAMETER2_ADDR
for(i=0; i&amp;lt;5; i++)
{
	memcpy(&amp;amp;wrData[PASSWORD_SIZE * i], &amp;amp;password[i][0], PASSWORD_SIZE);
}

addr = (uint32_t *)(PARAMETER2_ADDR);
eraseFlashPage(addr);
nrf_delay_ms(ERASE_FLASH_DELAY);
writeFlashPage(addr, wrData);
nrf_delay_ms(WRITE_FLASH_DELAY);


// PARAMETER3_ADDR
// PARAMETER4_ADDR
// reserved
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;//	__enable_irq();
}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: BLE and flash write problem</title><link>https://devzone.nordicsemi.com/thread/79893?ContentTypeID=1</link><pubDate>Thu, 16 Mar 2017 07:40:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:704e3b8e-7201-4af3-ba4e-25c71d1d13ec</guid><dc:creator>air</dc:creator><description>&lt;p&gt;I use SDK_12.1.0_flashwrite example.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>