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

What should I start in order to use the maximum memory space in fstorage?

Hello everybody, 

I just started using fStorage. When I examine the example, it starts from write address 0x3e000.

err_code = nrf_fstorage_write(&fstorage, 0x3e000, m_hello_world, sizeof(m_hello_world), NULL);
APP_ERROR_CHECK(err_code);

Q-1 How is this write address determined?

Q-2 For example, when I write12 bytes data, what should I start with the next write address?

Thank you.

Parents
  • After Kristin's help, I finally get the solution.

    I do not know exactly why, If you want to record a sequence directly, it gives an error. So I have defined external an array( m_deadbeef[10] ) in the fds_write function. Then I copied the array that I want to save into m_deadbeef. And the problem is solved.

    static ret_code_t kls_fds_write(uint32_t write_file_id, uint32_t write_record_key , uint8_t write_data[])
    {		
    		static uint8_t m_deadbeef[10] = {0};
    		
    		memcpy(m_deadbeef, write_data, sizeof(m_deadbeef));
    		
    		fds_record_t        record;
    		fds_record_desc_t   record_desc;
    	
    		// Set up record.
    		record.file_id              = write_file_id;
    		record.key              		= write_record_key;
    		record.data.p_data       		= &m_deadbeef;
    		record.data.length_words   	= sizeof(m_deadbeef)/sizeof(uint8_t);
    				
    		ret_code_t ret = fds_record_write(&record_desc, &record);
    		if (ret != FDS_SUCCESS)
    		{
    				return ret;
    		}
    		 NRF_LOG_INFO("Writing Record ID = %d \r\n",record_desc.record_id);
    		return NRF_SUCCESS;
    	
    }
    	
    static ret_code_t kls_fds_read(uint32_t read_file_id, uint32_t relevant_record_key , uint8_t read_data[])
    {	
    		fds_flash_record_t  flash_record;
    		fds_record_desc_t   record_desc;
    		fds_find_token_t    ftok ={0};//Important, make sure you zero init the ftok token
    		uint8_t *data;
    		uint32_t err_code;
    		
    		NRF_LOG_INFO("Start searching... \r\n");
    		// Loop until all records with the given key and file ID have been found.
    		while (fds_record_find(read_file_id, relevant_record_key, &record_desc, &ftok) == FDS_SUCCESS)
    		{
    				err_code = fds_record_open(&record_desc, &flash_record);
    				if ( err_code != FDS_SUCCESS)
    				{
    					return err_code;		
    				}
    				
    				NRF_LOG_INFO("Found Record ID = %d\r\n",record_desc.record_id);
    
    				data = (uint8_t *) flash_record.p_data;
    				for (uint8_t i=0;i<flash_record.p_header->length_words;i++)
    				{
    					read_data[i] = data[i];
    				}
    			
    		
    				NRF_LOG_HEXDUMP_INFO(read_data, sizeof(read_data));
    				// Access the record through the flash_record structure.
    				// Close the record when done.
    				err_code = fds_record_close(&record_desc);
    				if (err_code != FDS_SUCCESS)
    				{
    					return err_code;	
    				}
    		}
    		return NRF_SUCCESS;	
    }
    
    

Reply
  • After Kristin's help, I finally get the solution.

    I do not know exactly why, If you want to record a sequence directly, it gives an error. So I have defined external an array( m_deadbeef[10] ) in the fds_write function. Then I copied the array that I want to save into m_deadbeef. And the problem is solved.

    static ret_code_t kls_fds_write(uint32_t write_file_id, uint32_t write_record_key , uint8_t write_data[])
    {		
    		static uint8_t m_deadbeef[10] = {0};
    		
    		memcpy(m_deadbeef, write_data, sizeof(m_deadbeef));
    		
    		fds_record_t        record;
    		fds_record_desc_t   record_desc;
    	
    		// Set up record.
    		record.file_id              = write_file_id;
    		record.key              		= write_record_key;
    		record.data.p_data       		= &m_deadbeef;
    		record.data.length_words   	= sizeof(m_deadbeef)/sizeof(uint8_t);
    				
    		ret_code_t ret = fds_record_write(&record_desc, &record);
    		if (ret != FDS_SUCCESS)
    		{
    				return ret;
    		}
    		 NRF_LOG_INFO("Writing Record ID = %d \r\n",record_desc.record_id);
    		return NRF_SUCCESS;
    	
    }
    	
    static ret_code_t kls_fds_read(uint32_t read_file_id, uint32_t relevant_record_key , uint8_t read_data[])
    {	
    		fds_flash_record_t  flash_record;
    		fds_record_desc_t   record_desc;
    		fds_find_token_t    ftok ={0};//Important, make sure you zero init the ftok token
    		uint8_t *data;
    		uint32_t err_code;
    		
    		NRF_LOG_INFO("Start searching... \r\n");
    		// Loop until all records with the given key and file ID have been found.
    		while (fds_record_find(read_file_id, relevant_record_key, &record_desc, &ftok) == FDS_SUCCESS)
    		{
    				err_code = fds_record_open(&record_desc, &flash_record);
    				if ( err_code != FDS_SUCCESS)
    				{
    					return err_code;		
    				}
    				
    				NRF_LOG_INFO("Found Record ID = %d\r\n",record_desc.record_id);
    
    				data = (uint8_t *) flash_record.p_data;
    				for (uint8_t i=0;i<flash_record.p_header->length_words;i++)
    				{
    					read_data[i] = data[i];
    				}
    			
    		
    				NRF_LOG_HEXDUMP_INFO(read_data, sizeof(read_data));
    				// Access the record through the flash_record structure.
    				// Close the record when done.
    				err_code = fds_record_close(&record_desc);
    				if (err_code != FDS_SUCCESS)
    				{
    					return err_code;	
    				}
    		}
    		return NRF_SUCCESS;	
    }
    
    

Children
No Data
Related