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

CRC failure on fds_record_open after multiple calls to fds_record_update

We're using FDS in our application and have found that often after quick, repeated writes to a given record, the next time that an attempt to open the record is made, the CRC check on that record fails. We are finding the record using a key and file ID. The method we are using to modify the recorded is as follows (this is just a snippet of a larger function that handles different fds operations):

// Look for the record in the file
errCode = fds_record_find( inOperation->fileID, inOperation->recordKey, &recordDescriptor, &localFindProgress );
require( errCode == FDS_SUCCESS || errCode == FDS_ERR_NOT_FOUND, exit );

NRF_LOG_INFO( "Found record to write: %d, %d, 0x%x, ID: 0x%x",
    inOperation->fileID,
    inOperation->recordKey,
    (uint32_t) recordDescriptor.p_record,
    recordDescriptor.record_id );

// Fill in the record to write details
recordToWrite.file_id           = inOperation->fileID;
recordToWrite.key               = inOperation->recordKey;

// Point the chunk data to the buffer holding the data to be written
recordToWrite.data.p_data       = inOperation->data;

// Set length in words making sure we're word aligned
recordToWrite.data.length_words = ( inOperation->dataLen + 3 ) / 4;

// Increment number of pending operations to wait on
mFileSystem.numberOfPendingWriteOperations++;

// If the record wasn't previously found then we write a new one, otherwise we update the one found
if ( errCode == FDS_ERR_NOT_FOUND )
{
    errCode = fds_record_write( &recordDescriptor, &recordToWrite );
}
else
{
    errCode = fds_record_update( &recordDescriptor, &recordToWrite );
}

It appears that fds_record_find is being called multiple times before the queued writes to update the record have completed. This is apparent because the details of the record descriptor appear to be the same across multiple calls to modify the record, when I know the p_record and record_id should change each time the record is updated.

Would you expect this behavior based on what I have described? Do you have any recommendations on how to better handle this situation (a queue for file system operations, etc.)?

We're using an nRF52840, running SDK 15.3.

Thanks!

  • Hi,

    Both fds_record_write() and fds_record_update() are non-blocking calls, where the flash operation itself is only queued. The actual writing (or updating) happens later, after which you will get notified through the callback function that you have previously registered with fds_register().

    If you loop through searching for and updating a record, multiple times in a row, in rapid succession, it is conceivable that you manage to find and read the same "old" record data multiple times, before the queued updates are performed by the FDS backend.

    If you are going to read a record, update it, then find it again, it would be wise to wait for the callback for the update before you perform the subsequent find operation.

    Regards,
    Terje

Related