<?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 memory utilization</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/227/flash-memory-utilization</link><description>Dear Nordic Support Team, 
 I am trying to write some information in the flash memory without success. In the ble_flash.h file, it is specified that the pages 0-127 are reserved to the soft device. So, I can use the next page to store my data, am I right</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Nov 2014 04:43:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/227/flash-memory-utilization" /><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1268?ContentTypeID=1</link><pubDate>Tue, 11 Nov 2014 04:43:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4caf4988-b401-42cc-a033-49dea3310886</guid><dc:creator>jeff</dc:creator><description>&lt;pre&gt;&lt;code&gt;static void updateSetting(){
   uint8_t err_code;

simple_uart_putstring((const uint8_t *)&amp;quot;writing Settings\n&amp;quot;);

uint32_t* indata = malloc(32*sizeof(uint32_t));

int i;
for (i=0;i&amp;lt;32;i++){
	
	 indata[i] = i;
}

err_code =  ble_flash_page_write 	( 128,	indata,		32	) ;	
APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;/**@brief function to get setting from flash
*/&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void getSetting(){

uint8_t err_code;

simple_uart_putstring((const uint8_t *)&amp;quot;getting Settings\n&amp;quot;);


uint32_t *setting0 = malloc(32*sizeof(uint32_t));
uint8_t *length = malloc(4*sizeof(uint8_t));
err_code = ble_flash_page_read(128, setting0, length);
APP_ERROR_CHECK(err_code);

int msg_length = (length[3]&amp;lt;&amp;lt;24 |length[2]&amp;lt;&amp;lt;16 | length[1]&amp;lt;&amp;lt;8 | length[0]) ;



int i=0;
for (i=0;i&amp;lt;msg_length;i++){
	uint32_t value = setting0[i];
	uint8_t result[4];

	result[0] = (value &amp;amp; 0x000000ff);
	result[1] = (value &amp;amp; 0x0000ff00) &amp;gt;&amp;gt; 8;
	result[2] = (value &amp;amp; 0x00ff0000) &amp;gt;&amp;gt; 16;
	result[3] = (value &amp;amp; 0xff000000) &amp;gt;&amp;gt; 24;
	
	char msg[9];
	sprintf(msg,&amp;quot;%08lx\n&amp;quot;,(unsigned long)value);
	simple_uart_putstring((const uint8_t *)msg);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1266?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2013 11:48:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ef577da-9542-4a53-86b2-d02a9ac14bd1</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;You can see the size of the application in Keil&amp;#39;s output when it&amp;#39;s compiling. If you know that you&amp;#39;re going to use this page for application data, you could also consider reducing the size of IROM in Keil&amp;#39;s project settings, so that you get errors on no remaining space if the application grows into this region. You can see that this is done for all the BLE examples in the SDK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1267?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2013 11:46:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4f46304-86cb-4aad-abc7-70e70651ff7c</guid><dc:creator>Guest</dc:creator><description>&lt;p&gt;Thanks for the clarification. I moved my code in the BLE disconnect event and it works.&lt;/p&gt;
&lt;p&gt;Last question, at this time, I am using the code &amp;quot;NRF_FICR-&amp;gt;CODESIZE - 4&amp;quot; to retrieve a page number to write my data. But, how can I know if I am writting in the application flash pages? Is there a way to know the application size?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1265?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2013 11:46:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30abeb3d-edb4-41f9-a5a9-bf239940d6f7</guid><dc:creator>Bastiaan</dc:creator><description>&lt;p&gt;Thanks for the clarification. I moved my code in the BLE disconnect event and it works.&lt;/p&gt;
&lt;p&gt;Last question, at this time, I am using the code &amp;quot;NRF_FICR-&amp;gt;CODESIZE - 4&amp;quot; to retrieve a page number to write my data. But, how can I know if I am writting in the application flash pages? Is there a way to know the application size?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1264?ContentTypeID=1</link><pubDate>Fri, 16 Aug 2013 09:45:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a62e6da7-3ce4-44a2-9687-f41a769d96b1</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;Remember that doing flash operations locks the CPU. You write in a comment that you do it right before the infinite loop in main, but at this point, the chip is most likely advertising. If it is, the time it takes to erase a page may will cause an assert, and the program will end up in the app_error_handler, which by default does a reset.&lt;/p&gt;
&lt;p&gt;I recommend that you remove the reset from the error handler, and instead uncomment the call to ble_debug_assert_handler(), since this will make it much easier for you to find errors as they happen.&lt;/p&gt;
&lt;p&gt;The only workaround to this problem is to avoid doing flash operations except when not in a connection and not advertising.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1261?ContentTypeID=1</link><pubDate>Wed, 14 Aug 2013 09:07:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8386bc0-1814-4a54-a8bb-d51b7907edea</guid><dc:creator>S&amp;#233;bastien Despont</dc:creator><description>&lt;p&gt;Dear Ole Morten,&lt;/p&gt;
&lt;p&gt;Thanks for helping me with this problem.
I am just trying to test the read/write flash page feature without success.&lt;/p&gt;
&lt;p&gt;Please, have a look on my answer on this thread above to see my code. Teh code is executed at the end of the main function, just before the infinity loop containing the &amp;quot;sd_app_event_wait&amp;quot; softdevice function.&lt;/p&gt;
&lt;p&gt;At this point, the ble stack is started and I should be able to use ble_flash_page_write function, but I can&amp;#39;t. The code crash when I execute the function ble_flash_page_write, therefore, I don&amp;#39;t have any error message to give you...&lt;/p&gt;
&lt;p&gt;Go into the function does not help because the debugger stopped on function ble_flash_crc16_compute, but if I set a breakpoint right after, it execute successfully the ble_flash_crc16_compute function.&lt;/p&gt;
&lt;p&gt;I think that it crashes due to a bad memory address. The page I am tring to write is NRF_FICR-&amp;gt;CODESIZE - 4;&lt;/p&gt;
&lt;p&gt;Do you have any idea or example which could inspired me?&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1260?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2013 08:14:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ee70539-9960-42b0-a088-bdda3993dcc1</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;Sorry for the delay, it&amp;#39;s just been way too busy lately. However, you don&amp;#39;t give a lot of details, so it&amp;#39;s a little hard to help you. What exactly is not working, and how does it not work? Don&amp;#39;t you see anything changing? What is the flash contents before and after running this snippet? Does it return an error code or does fail in some other way? Are you in a BLE connection when it fails?&lt;/p&gt;
&lt;p&gt;It would be helpful if you could edit your original question and add the complete project you&amp;#39;re working with, so that I can test it on my end.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1259?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2013 07:23:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6bbfb21e-3d82-4be5-9b48-d2e5df3bc3fc</guid><dc:creator>S&amp;#233;bastien Despont</dc:creator><description>&lt;p&gt;Up, this code is still not working. How can I fix that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1263?ContentTypeID=1</link><pubDate>Tue, 13 Aug 2013 04:48:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ccfdfc5-b61c-4cff-b9f3-26812bff2fb7</guid><dc:creator>S&amp;#233;bastien Despont</dc:creator><description>&lt;p&gt;Up, this code is still not working. How can I fix that?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1262?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2013 05:49:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3122ba0-cb48-487d-974c-be2e370b07f5</guid><dc:creator>S&amp;#233;bastien Despont</dc:creator><description>&lt;p&gt;Thanks for your answer.&lt;/p&gt;
&lt;p&gt;I have tried this code as you suggest, but it still doesn&amp;#39;t work. I don&amp;#39;t get any error number, the code just crash and I don&amp;#39;t understand why.&lt;/p&gt;
&lt;p&gt;Could you have a look on my codebelow? I didn&amp;#39;t find any example which explain how to use the flash memory in the SDK.&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t page = NRF_FICR-&amp;gt;CODESIZE - 4;

uint8_t word_count = 1;
uint32_t data_array[2]={0};

err_code = ble_flash_page_write(page,(uint32_t *) &amp;amp;data_array,1);
APP_ERROR_CHECK(err_code);
														
err_code = ble_flash_page_read(page, (uint32_t *) &amp;amp; data_array, &amp;amp;word_count);
APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1258?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2013 05:38:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:98831889-4ef6-444a-8bb4-8cfd6d622604</guid><dc:creator>S&amp;#233;bastien Despont</dc:creator><description>&lt;p&gt;Thanks for your reply. So, to write 1 page, I need to use something like &amp;quot;NRF_FICR-&amp;gt;CODESIZE-4&amp;quot;?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Flash memory utilization</title><link>https://devzone.nordicsemi.com/thread/1257?ContentTypeID=1</link><pubDate>Tue, 06 Aug 2013 05:29:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f40d4a43-5e33-459e-b6cb-136acf78e065</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;This code most likely crashes because you are trying to overwrite the application code. There isn&amp;#39;t a separate data flash in the nRF51822, so when you write to flash, you write to the same flash that the actual program runs from. You should therefore be careful not to erase or write to pages where there is program code, as the comment in ble_flash.h tells you.&lt;/p&gt;
&lt;p&gt;The softdevice occupies pages 0-79 (not 127 anymore, this is actually a bug in ble_flash.h) which translates to address 0 to 0x13FFF, while the application can use pages 79-255, address 0x14000 to 0x39FFF. However, this latter part will be shared between actual application code and data storage. It is a strict requirement that the code of the application starts at address 0x14000, and how far up it will go is simply a matter of how big it is.&lt;/p&gt;
&lt;p&gt;For data storage you should therefore make sure to use the upper pages. If you look at the bond manager, it uses pages 254 and 255, so I&amp;#39;d recommend you to use for example page 253 for other application storage needs.&lt;/p&gt;
&lt;p&gt;Also remember that any flash writing or erasing locks the CPU, so you need to be careful if you try to do this while in a BLE connection. Have a look at &lt;a href="https://devzone.nordicsemi.com/index.php/halt-flash-write"&gt;this question&lt;/a&gt; for details on this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>