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

FDS write fail

Hi all,

I have some problem with the FDS write function.

This is some example codes for my FDS write:

// Global variables
static uint16_t fileID; 
static uint16_t recordKey;
static fds_record_t        record;
static fds_record_desc_t   record_desc;
static fds_record_chunk_t  record_chunk;
static fds_flash_record_t  flash_record;
static fds_find_token_t    ftok;

struct
{
   uint16_t     	variable1[7];
   uint16_t     	variable2;
   uint16_t		variable3;
   uint8_t     	        variable4[7];
   uint8_t		variable5;
} saveData;

struct
{
  uint16_t            variable6;
  uint8_t              variable 7[7];
} saveData2;


// Inside Main( )
fileID = 0x1000;
recordKey = 0x2000;
record_chunk.p_data         = &saveData;
record_chunk.length_words   = sizeof(saveData)/sizeof(uint32_t);
record.file_id              = fileID;
record.key                  = recordKey;
record.data.p_chunks       = &record_chunk;
record.data.num_chunks   = 1;	
ret = fds_write();
if (ret != FDS_SUCCESS)
{
NRF_LOG_INFO("Write History fail!\r\n");
}			

fileID = 0x1000;
recordKey = 0x2001;
record_chunk.p_data         = &saveData2;
record_chunk.length_words   = sizeof(saveData2)/sizeof(uint32_t);
record.file_id              = fileID;
record.key                  = recordKey;
record.data.p_chunks       = &record_chunk;
record.data.num_chunks   = 1;	
ret = fds_write();
if (ret != FDS_SUCCESS)
{
NRF_LOG_INFO("Write History fail!\r\n");
}	

My fds_write function looks like this:

static ret_code_t fds_write(void)
{
	ret_code_t ret = fds_record_write(&record_desc, &record);
	if (ret != FDS_SUCCESS)
	{
			return ret;
	}
	while (write_flag==0);
	
	NRF_LOG_INFO("Writing Record ID = %d \r\n",record_desc.record_id);
	return NRF_SUCCESS;
}

The first write is successful but the second write is unsuccessful. Why does this happen?

Related