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

how to set the address for user data?

I use nrf52832 sdk 14.0

SD+ boot(for ota)+app

In the applicaiton there are some user data to save. I used two pages ( one pages start from 0x6E000 and the other start from 0x6F000).

my user data want to save about 6000 bytes.

on pure circuit board, the app runs rightly, but after Rubberized 4 pcs of 24 runs abnormal and found user data lost.

I wonder if it's the address for user data define error? how to calc the right address which can be used to save user data?

any suggestion is appreciated!

  • Hi,

    What is the start address of your bootloader, and did the data get lost after an OTA update? User data should be placed just below the bootloader as shown here, and you need to set the APP_DATA_RESERVED define in your bootloader to reserve the region for app data. 

  • thank you very much, Vidar Berg. I used the SDK14.0, S132 v5.0.x) bootloader address:0x78000. After many times test, I found it's the sd_flash_write function sometime return NRF_ERROR_BUSY, which result the data lost. and increase the delay time after sd_flash_erase and sd_flash_write, also return NRF_ERROR_BUSY sometime.

    #define USER_DATA_ADDR2  (0x06F000)
    #define FLASH_PAGE_SIZE  (0x1000)   //==4096
    
    typedef __packed struct 
    {
    	uint32_t m_flag;  		//------------------------------------------4
    	uint8_t  m_batchID[3];	// ------------------------------------3
    
    	uint8_t m_pn_mark[2];	//------------------------------------------2
    	uint8_t m_level[3];		//------------------------------------------3
    	uint8_t m_pn_name[8];	// ---------------------------------8
    	uint8_t m_pn_dat[8][500];//-----------------------------4000
    	uint8_t m_rev[4];		//------------------------------------------4
    	
    }TM_CONFIG2; //---------------------4024bytes
    
    uint32_t refresh_flash_config_data(void)
    {
    	TM_CONFIG2 sector2;
    	uint32_t err_code = NRF_SUCCESS;
    	uint8_t i = 0;
    	
    	memcpy(&sector2, (uint32_t *)USER_DATA_ADDR2, sizeof(TM_CONFIG2));
    
    	//------------------------------------------------------------
    	err_code = sd_flash_page_erase( USER_DATA_ADDR2/FLASH_PAGE_SIZE );  //
    	nrf_delay_ms(300);
    	if(err_code!=NRF_SUCCESS)
    	{
    		NRF_LOG_PRINTF("erase Flash 2 fail!\n")
    	}
    	
            //some code here, modify the content of sector2
            //...
    
    	err_code = sd_flash_write( (uint32_t *)USER_DATA_ADDR2, (const uint32_t *)(&sector2), sizeof(TM_CONFIG2)>>2 );  //### sometime return NRF_ERROR_BUSY ###
    	nrf_delay_ms(400);
    	if(NRF_SUCCESS == err_code )
    	{
    		NRF_LOG_PRINTF("Write Flash 2 OK!\n")
    	}
    	else
    	{
    		NRF_LOG_PRINTF("Write Flash 2 error! code=0x%x!\n", err_code);//sometime print here, code=0x11
    	}
    	
        //...
    	
    	return err_code;
    }
    

  • I have solved the problem by using the fstorage module! thanks!

Related