<?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>SDK12.3 flash storage</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/23967/sdk12-3-flash-storage</link><description>I want to store some data into flash. Whether there are relevant application notes or program code? Thanks</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Aug 2017 12:54:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/23967/sdk12-3-flash-storage" /><item><title>RE: SDK12.3 flash storage</title><link>https://devzone.nordicsemi.com/thread/94357?ContentTypeID=1</link><pubDate>Wed, 02 Aug 2017 12:54:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fae3478-5bf2-4ecf-80b0-0dfd6026d1e3</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Can you check what is the error ? is it hardfault ?&lt;/p&gt;
&lt;p&gt;You need to make sure the priority of the interrupt where you call the function is APP_LOW so that you can call flash API.
Otherwise you have to use app scheduler to call the flash&amp;#39;s functions in main context.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK12.3 flash storage</title><link>https://devzone.nordicsemi.com/thread/94356?ContentTypeID=1</link><pubDate>Wed, 02 Aug 2017 06:32:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:86b49651-7420-451e-a2c0-a89550320709</guid><dc:creator>Mr.Wu</dc:creator><description>&lt;p&gt;use softdevice, this test code：&lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.3.0%2Flib_fds_usage.html&amp;amp;cp=4_0_2_3_37_2"&gt;link text&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static uint8_t fs_callback_flag;

static void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result)
{
	if (result != FS_SUCCESS)
	{
		bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
	}
	else
	{
		NRF_LOG_INFO(&amp;quot;fstorage command successfully completed\n\r&amp;quot;);
		fs_callback_flag = 0;
	}
}

static void power_manage(void)
{
	uint32_t err_code = sd_app_evt_wait();

	APP_ERROR_CHECK(err_code);
}

void fstorage_test(void)
{
	static char char_data[5];
	static char special_char_data[5];
	static uint32_t data;
	uint32_t flash_data[4];

	FS_REGISTER_CFG(fs_config_t fs_config) =
	{
		.callback  = fs_evt_handler,
		.num_pages = NUM_PAGES_SN,
		.priority  = 0xFD
	};

	fs_ret_t ret = fs_init();
	if (ret != FS_SUCCESS)
	{
		bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
	}
	
	// Erase one page (page 0).
	NRF_LOG_INFO(&amp;quot;Erasing a flash page at address 0x%X\r\n&amp;quot;, (uint32_t)fs_config.p_start_addr);
	fs_callback_flag = 1;
	ret = fs_erase(&amp;amp;fs_config, fs_config.p_start_addr, 1, NULL);
	if (ret != FS_SUCCESS)
	{
		bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
	}
	while(fs_callback_flag == 1)  {power_manage();}
	
	//Read the first 4 words of the page
	NRF_LOG_INFO(&amp;quot;Reading from flash address 0x%X: &amp;quot;, (uint32_t)fs_config.p_start_addr);
	for(int i=0; i&amp;lt;4; i++)
	{
		flash_data[i] = *(fs_config.p_start_addr + i);
		NRF_LOG_INFO(&amp;quot;%X &amp;quot;, flash_data[i]);
	}

	//Write first word
	data = 0x4455AABB;
	NRF_LOG_INFO(&amp;quot;Writing data 0x%X to address 0x%X\r\n&amp;quot;, data, (uint32_t)fs_config.p_start_addr);
	fs_callback_flag = 1;
	ret = fs_store(&amp;amp;fs_config, fs_config.p_start_addr, &amp;amp;data, 1, NULL);      //Write data to memory address 0x0003F00. Check it with command: nrfjprog --memrd 0x0003F000 --n 16
	if (ret != FS_SUCCESS)
	{
		bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
	}
	while(fs_callback_flag == 1)  {power_manage();}

	//Write second word
	data = 0;
	strcpy(char_data, &amp;quot;buzz&amp;quot;);
	char_data[4] = &amp;#39;\0&amp;#39;;
	data |= (char_data[0] &amp;lt;&amp;lt; 24);
	data |= (char_data[1] &amp;lt;&amp;lt; 16);
	data |= (char_data[2] &amp;lt;&amp;lt;  8);
	data |= (char_data[3] &amp;lt;&amp;lt;  0);
	
	NRF_LOG_INFO(&amp;quot;Writing string &amp;#39;%s&amp;#39; (0x%X) to address 0x%X\r\n&amp;quot;, (uint32_t)char_data, data, (uint32_t)fs_config.p_start_addr + 4);
	
	fs_callback_flag = 1;
	ret = fs_store(&amp;amp;fs_config, fs_config.p_start_addr + 1, &amp;amp;data, 1, NULL);      //Write data to memory address 0x0003F000. Check it with command: nrfjprog --memrd 0x0003F000 --n 16
	if (ret != FS_SUCCESS)
	{
		bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
	}
	while(fs_callback_flag == 1)  {power_manage();}
	
	//Write third word
	data = 0;
	strcpy(special_char_data,&amp;quot;~!@#&amp;quot;);
	special_char_data[4] = &amp;#39;\0&amp;#39;;
	data |= (special_char_data[0] &amp;lt;&amp;lt; 24);
	data |= (special_char_data[1] &amp;lt;&amp;lt; 16);
	data |= (special_char_data[2] &amp;lt;&amp;lt;  8);
	data |= (special_char_data[3] &amp;lt;&amp;lt;  0);
	
	NRF_LOG_INFO(&amp;quot;Writing string &amp;#39;%s&amp;#39; (0x%X) to address 0x%X\r\n&amp;quot;, (uint32_t)special_char_data, data, (uint32_t)fs_config.p_start_addr + 8);
	
	fs_callback_flag = 1;
	ret = fs_store(&amp;amp;fs_config, fs_config.p_start_addr + 2, &amp;amp;data, 1, NULL);      //Write data to memory address 0x0003F000. Check it with command: nrfjprog --memrd 0x0003F000 --n 16
	if (ret != FS_SUCCESS)
	{
		bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
	}
	while(fs_callback_flag == 1)  {power_manage();}
	
	
	//Read the first 4 words of the page and print in hex format
	NRF_LOG_INFO(&amp;quot;Reading from flash address 0x%X (hex): &amp;quot;, (uint32_t)fs_config.p_start_addr);
	for(int i=0; i&amp;lt;4; i++)
	{
		flash_data[i] = *(fs_config.p_start_addr + i);
		NRF_LOG_INFO(&amp;quot;%X &amp;quot;, flash_data[i]);
	}
	
	//Read the first 4 words of the page and print in ascii format
	NRF_LOG_INFO(&amp;quot;Reading from flash address 0x%X (ascii): &amp;quot;, (uint32_t)fs_config.p_start_addr);
	for(int i=0; i&amp;lt;4; i++)
	{
		char characters[4];
		flash_data[i] = *(fs_config.p_start_addr + i);
		characters[0] = flash_data[i] &amp;gt;&amp;gt; 24;
		characters[1] = flash_data[i] &amp;gt;&amp;gt; 16;
		characters[2] = flash_data[i] &amp;gt;&amp;gt;  8;
		characters[3] = flash_data[i] &amp;gt;&amp;gt;  0;
		NRF_LOG_INFO(&amp;quot;%c%c%c%c &amp;quot;, characters[0], characters[1], characters[2], characters[3]);
	}
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Called directly in the main.c， no problem。 If, called in a callback function， the application stops running&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SDK12.3 flash storage</title><link>https://devzone.nordicsemi.com/thread/94355?ContentTypeID=1</link><pubDate>Tue, 01 Aug 2017 13:00:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:09faf82e-d083-4c27-84b5-1183b30d518a</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Do you use softdevice or not ? If you use softdevice please have a look at this fds usage &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.3.0/lib_fds_usage.html?cp=4_0_2_3_37_2"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you don&amp;#39;t use softdevice, please have a look at the SDK example \examples\peripheral\flashwrite&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>