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

FDS record update increments record ID, and calls event handler twice

Hello,

SDK: 15.3.0

nRF52840-DK

s140

I have taken the flash_fds_s140_pca10056 example and modified it for our own use. I would like to store versioning information, number of system resets, system on time, and various other system related information that needs to persist between power cycles or resets. I would like to define a single record, and I do not expect or intend to add additional records in the future.

The print out below shows initial start up, and  then a restart. The write is successful (which is creating the record and setting the initial values). Record ID = 1, then the update happens and is successful, but the Record ID = 2. I do not know why the record ID is increasing? This is followed by an  Event: FDS_EVT_UPDATE received (FDS_ERR_NOT_FOUND). After the restart the same behavior occurs and Record ID = 3.  Additionally the Dirty Records after the restart is now 1.

I can not make sense of these behaviors. The code is taken from the example and moved into its own file/functions, but I am following the example closely. 

Why is the record ID increasing?

Why would FDS_EVT_UPDATE occur twice?

In peer_data_storage.c the event handler fds_evt_handler has an empty FDS_EVT_UPDATE case. It is not clear what is needed in the event handler for an update? I have added similar print statements as the example in my version of the event handler with a flag to check for when the update is complete.

FDS example started.
Initializing fds...
Event: FDS_EVT_INIT received (FDS_SUCCESS)
Writing config file...
fds_record_write() Error: FDS_SUCCESS
Event: FDS_EVT_WRITE received (FDS_SUCCESS)
Record ID:	0x0001
File ID:	0xf010
Record key:	0x7010
Reading flash usage statistics...
Found 1 valid records.
Found 0 dirty records (ready to be garbage collected).
Config file found, updating boot count to 0.
config1:	off
config2:	on
boot count:	0
device name:	dummy
Event: FDS_EVT_UPDATE received (FDS_SUCCESS)
Record ID:	0x0002
File ID:	0xf010
Record key:	0x7010
Event: FDS_EVT_UPDATE received (FDS_ERR_NOT_FOUND)

(RESTART)

FDS example started.
Initializing fds...
Event: FDS_EVT_INIT received (FDS_SUCCESS)
Record found, no need to create duplicate
Reading flash usage statistics...
Found 1 valid records.
Found 1 dirty records (ready to be garbage collected).
Config file found, updating boot count to 1.
config1:	off
config2:	on
boot count:	1
device name:	dummy
Event: FDS_EVT_UPDATE received (FDS_SUCCESS)
Record ID:	0x0003
File ID:	0xf010
Record key:	0x7010
Event: FDS_EVT_UPDATE received (FDS_ERR_NOT_FOUND)

Parents Reply Children
  • I did not link any threads in my post, but I have seen both of these threads before and liked them. Also neither of the threads have a definitive explanation to clear up how the Record ID, Record Key, and File Key can be used. Linking to other threads that are not properly answered only creates a web of confusion. This helps no one.

    I do not see where the thread speaks about the record ID increasing. Can you explain this in more depth?

    That is correct. You have two sets of identifiers, one named file and the other named record, that you can use however you want to "tag" the entries.

    File Key, and Record Key, are the identifiers I can use 'however' I would like.

    I would like a single structure stored in persistent flash. I would like to update the values of this structure and get the values of the structure. I do not want to create multiple Record IDs, or in other words duplicate data, I only want 1 set of data. Is this possible with the FDS?

    Additionally, why is the Record ID Increasing? and does this in fact mean there is a duplicate record?

Related