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

Flash memory utilization

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?

Can you tell me why the following code crash ?

uint32_t page = 128;

uint8_t word_count = 1;
uint32_t data_array[2]={0};

err_code = ble_flash_page_write(page,(uint32_t *) &data_array,1);
APP_ERROR_CHECK(err_code);
														
err_code = ble_flash_page_read(page, (uint32_t *) & data_array, &word_count);
APP_ERROR_CHECK(err_code);
  • You can see the size of the application in Keil's output when it's compiling. If you know that you're going to use this page for application data, you could also consider reducing the size of IROM in Keil'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.

  • static void updateSetting(){
       uint8_t err_code;
    
    simple_uart_putstring((const uint8_t *)"writing Settings\n");
    
    uint32_t* indata = malloc(32*sizeof(uint32_t));
    
    int i;
    for (i=0;i<32;i++){
    	
    	 indata[i] = i;
    }
    
    err_code =  ble_flash_page_write 	( 128,	indata,		32	) ;	
    APP_ERROR_CHECK(err_code);
    }
    

    /**@brief function to get setting from flash */

    static void getSetting(){
    
    uint8_t err_code;
    
    simple_uart_putstring((const uint8_t *)"getting Settings\n");
    
    
    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]<<24 |length[2]<<16 | length[1]<<8 | length[0]) ;
    
    
    
    int i=0;
    for (i=0;i<msg_length;i++){
    	uint32_t value = setting0[i];
    	uint8_t result[4];
    
    	result[0] = (value & 0x000000ff);
    	result[1] = (value & 0x0000ff00) >> 8;
    	result[2] = (value & 0x00ff0000) >> 16;
    	result[3] = (value & 0xff000000) >> 24;
    	
    	char msg[9];
    	sprintf(msg,"%08lx\n",(unsigned long)value);
    	simple_uart_putstring((const uint8_t *)msg);
    }
    

    }

Related