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.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX