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?

Parents
  • Hi all,

    I managed to get it to work partially. Its a strange problem. Somehow, the write will fail if the data I am saving into Flash is not taking up a multiple of uint32_t memory and it needs to be at least 3 x uint32_t memory.

    So I had to do this:

    struct
    {
        uint8_t     	var1[7];
        uint8_t		dummy1;
        uint16_t		var2;
        uint16_t		dummy2;
    } saveData2;
    

    So this works. But WHY?

    I also have another weird problem. I am using both fds write and fds update to two different recordKey.

    Assuming I already have one record in recordKey 0x2001 and one record in recordKey 0x2000. And I call the following codes:

    // fds_update function
    static ret_code_t fds_update(void)
    {
        ret_code_t ret = fds_record_update(&record_desc, &record);
        if (ret != FDS_SUCCESS)
        {
            return ret;
        }
        while (update_flag==0);
        NRF_LOG_INFO("Updating Record ID = %d \r\n",record_desc.record_id);
        return NRF_SUCCESS;
    } 
    
    // inside main
    fileID = 0x1000;
    recordKey = 0x2001;
    fds_write();
    
    fileID = 0x1000;
    recordKey = 0x2000;
    fds_update();
    

    When I do a record search, I end up with two records in recordKey 0x2000 and 1 recordKey in 0x2001. But this is wrong. I should have 2 records in recordKey2001 and have a new updated 1 record in recordKey 0x2000.

    *Update I solved the problem. I need to call fds_find_record first before calling fds_update. This worked for me

Reply
  • Hi all,

    I managed to get it to work partially. Its a strange problem. Somehow, the write will fail if the data I am saving into Flash is not taking up a multiple of uint32_t memory and it needs to be at least 3 x uint32_t memory.

    So I had to do this:

    struct
    {
        uint8_t     	var1[7];
        uint8_t		dummy1;
        uint16_t		var2;
        uint16_t		dummy2;
    } saveData2;
    

    So this works. But WHY?

    I also have another weird problem. I am using both fds write and fds update to two different recordKey.

    Assuming I already have one record in recordKey 0x2001 and one record in recordKey 0x2000. And I call the following codes:

    // fds_update function
    static ret_code_t fds_update(void)
    {
        ret_code_t ret = fds_record_update(&record_desc, &record);
        if (ret != FDS_SUCCESS)
        {
            return ret;
        }
        while (update_flag==0);
        NRF_LOG_INFO("Updating Record ID = %d \r\n",record_desc.record_id);
        return NRF_SUCCESS;
    } 
    
    // inside main
    fileID = 0x1000;
    recordKey = 0x2001;
    fds_write();
    
    fileID = 0x1000;
    recordKey = 0x2000;
    fds_update();
    

    When I do a record search, I end up with two records in recordKey 0x2000 and 1 recordKey in 0x2001. But this is wrong. I should have 2 records in recordKey2001 and have a new updated 1 record in recordKey 0x2000.

    *Update I solved the problem. I need to call fds_find_record first before calling fds_update. This worked for me

Children
No Data
Related