<?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>Advertisement fails after writing an image(40kB) into the internal flash</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/1568/advertisement-fails-after-writing-an-image-40kb-into-the-internal-flash</link><description>Hi, 
 I need to store an image of size 40kB to internal flash memory. Actually i tried to store it from the address like 0x28400 and 0x2E984 (memory addresses after softdevice and bank 0 ). I am getting hard-fault error, in timer initialization itself</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 13 Feb 2014 11:53:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/1568/advertisement-fails-after-writing-an-image-40kb-into-the-internal-flash" /><item><title>RE: Advertisement fails after writing an image(40kB) into the internal flash</title><link>https://devzone.nordicsemi.com/thread/6938?ContentTypeID=1</link><pubDate>Thu, 13 Feb 2014 11:53:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4a70258a-32f8-4bca-9ed2-c06861bec54e</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;I&amp;#39;ve expanded my answer above with what turned out to be the problem here, so I&amp;#39;d be happy if you could accept it as an answer, to clear up this question.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertisement fails after writing an image(40kB) into the internal flash</title><link>https://devzone.nordicsemi.com/thread/6937?ContentTypeID=1</link><pubDate>Tue, 11 Feb 2014 09:52:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5598f681-5683-41fc-a688-d63fec391b47</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;From where do you get Image_Sample_128x160? Anyway, I can&amp;#39;t really say much from this sample snippet, so I suggest that you post a support case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertisement fails after writing an image(40kB) into the internal flash</title><link>https://devzone.nordicsemi.com/thread/6936?ContentTypeID=1</link><pubDate>Tue, 11 Feb 2014 07:58:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e81585eb-b877-41cb-bed6-e7749f503fd3</guid><dc:creator>balaji</dc:creator><description>&lt;p&gt;Thanks for the reply Morten,
I cannot say that there is no accidental written of data in somewhere(how can i check?). But, as a result through readout i can only say that, the image data&amp;#39;s are  written in exact location as i programmed.  If possible try to give solution using the snippets  below.&lt;/p&gt;
&lt;p&gt;i just modified the ble_ app_alert_notification application,&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int main(void)
{    
    leds_init();
    timers_init();
   app_timer_start(m_timer_update_id, TIMER_UPDATE_INTERVAL, NULL);
    gpiote_init();
    buttons_init();
    app_button_enable();

// store and display an image before advertisement start

          store_image(Image_Sample_128x160, 40960);   // function to store image data in internal flash
	  nrf_gpio_cfg_output(RST);
	  nrf_gpio_cfg_output(RS);
	
	  spi_master_init(SPI0, SPI_MODE0,false);   
	  TFT_init();
	  TFT_Clear_Screen(WHITE);
          TFT_Putphoto();                                            // read and display the image stored in internal flash

    bond_manager_init();
    ble_stack_init();
    ble_error_log_init();
    gap_params_init();
    advertising_init();
    alert_notification_init();
    conn_params_init();
    sec_params_init();
    radio_notification_init();
    
    // Start execution.
    advertising_start();
		
    // Enter main loop.
    for (;;)
    {
        power_manage();
    }

}

&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code&gt;int store_image(const unsigned char image[], uint32_t size)     
{  
    uint32_t *addr;  
    uint32_t i;
    uint32_t pg_size;
    uint32_t pg_num;
	 uint32_t  image_data; 
	    
    pg_size   = NRF_FICR-&amp;gt;CODEPAGESIZE;
    pg_num  = NRF_FICR-&amp;gt;CODESIZE - 65;    
   addr = (uint32_t *)(pg_size * pg_num);
	
	for (i=0; i&amp;lt;39; i++)
	{	
	flash_page_erase(addr+(i*pg_size));    
	}
	
	for (i = 0; i&amp;lt;size; i+=4)  
	{
	image_data = (image[i+3]&amp;lt;&amp;lt;24)|(image[i+2]&amp;lt;&amp;lt;16)|(image[i+1]&amp;lt;&amp;lt;8)|(image[i]);
		
           ////		image_data = (image[i]&amp;lt;&amp;lt;24)|(image[i+1]&amp;lt;&amp;lt;16)|(image[i+2]&amp;lt;&amp;lt;8)|(image[i+3]);
	  flash_word_write(addr++, image_data);  
  }
    
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If the above information is not enough i can post a regular support case as you suggest.&lt;/p&gt;
&lt;p&gt;Regards,
Balaji&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Advertisement fails after writing an image(40kB) into the internal flash</title><link>https://devzone.nordicsemi.com/thread/6935?ContentTypeID=1</link><pubDate>Mon, 10 Feb 2014 17:53:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78803b37-eab0-4418-8c10-ddd774379696</guid><dc:creator>Ole Morten</dc:creator><description>&lt;p&gt;Are you sure no data is accidentally written somewhere it shouldn&amp;#39;t be? Have you tried to do a readout of your device before and after the flash write, to verify that this is not the case?&lt;/p&gt;
&lt;p&gt;Also, do you reset after having done your flash write? If not, could it be that you see a stack overflow, so that the RAM use of your flash writing overwrites static RAM of other parts of your application? How big stack have you set?&lt;/p&gt;
&lt;p&gt;If you have further problems, I don&amp;#39;t think we can do much more about this without seeing the code, and getting instructions to try reproducing the problem ourselves. If you can&amp;#39;t share your code here, can you please create a regular support case and upload it there, along with a thorough explanation of how to reproduce the problem?&lt;/p&gt;
&lt;p&gt;Edit: This turned out to be a two-fold problem&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First, the flash area used included the flash area used for static RAM values. This means that when the reset handler copied static RAM values from flash to RAM on reset, the values copied were just 0xFF, which in the end caused a HardFault when modules were trying to use this area.&lt;/li&gt;
&lt;li&gt;Secondly, there is a bug in the calculation of page addresses in the function below, causing only every 4th page to be erased. This has to do with the pointer arithmetic of C, when incrementing a uint32_t pointer.&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>