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!