This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Advertisement fails after writing an image(40kB) into the internal flash

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 ( fails in, is buffer word aligned). and sometimes i can write and display the images but advertisement is not happening (hard-fault in ble_stack_init) .

So how can i use the memory to store the images, without fail in advertisement.

Regards, Balaji.M

  • Are you sure no data is accidentally written somewhere it shouldn'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?

    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?

    If you have further problems, I don'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'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?

    Edit: This turned out to be a two-fold problem

    • 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.
    • 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.
  • 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's are written in exact location as i programmed. If possible try to give solution using the snippets below.

    i just modified the ble_ app_alert_notification application,

    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();
        }
    
    }
    
    
    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->CODEPAGESIZE;
        pg_num  = NRF_FICR->CODESIZE - 65;    
       addr = (uint32_t *)(pg_size * pg_num);
    	
    	for (i=0; i<39; i++)
    	{	
    	flash_page_erase(addr+(i*pg_size));    
    	}
    	
    	for (i = 0; i<size; i+=4)  
    	{
    	image_data = (image[i+3]<<24)|(image[i+2]<<16)|(image[i+1]<<8)|(image[i]);
    		
               ////		image_data = (image[i]<<24)|(image[i+1]<<16)|(image[i+2]<<8)|(image[i+3]);
    	  flash_word_write(addr++, image_data);  
      }
        
    }
    

    If the above information is not enough i can post a regular support case as you suggest.

    Regards, Balaji

  • From where do you get Image_Sample_128x160? Anyway, I can't really say much from this sample snippet, so I suggest that you post a support case.

  • I've expanded my answer above with what turned out to be the problem here, so I'd be happy if you could accept it as an answer, to clear up this question.

Related