There are a few setting options I would like to keep through power cycle like sensor sampling rate, continuous sampling on/off, etc. I had success implementing saving of one value using FDS with the following functions
static ret_code_t fds_test_write(void)
{
#define FILE_ID 0x1111
#define REC_KEY 0x2222
fds_record_t record;
fds_record_desc_t record_desc;
fds_record_chunk_t record_chunk;
// Set up data.
record_chunk.p_data = &timerTick;
record_chunk.length_words = 1;
// Set up record.
record.file_id = FILE_ID;
record.key = REC_KEY;
record.data.p_chunks = &record_chunk;
record.data.num_chunks = 1;
ret_code_t ret = fds_record_write(&record_desc, &record);
if (ret != FDS_SUCCESS)
{
return ret;
}
return NRF_SUCCESS;
}
static ret_code_t fds_read(void)
{
#define FILE_ID 0x1111
#define REC_KEY 0x2222
fds_flash_record_t flash_record;
fds_record_desc_t record_desc;
fds_find_token_t ftok ={0};//Important, make sure you zero init the ftok token
uint32_t *data;
uint32_t err_code;
// Loop until all records with the given key and file ID have been found.
while (fds_record_find(FILE_ID, REC_KEY, &record_desc, &ftok) == FDS_SUCCESS)
{
err_code = fds_record_open(&record_desc, &flash_record);
if ( err_code != FDS_SUCCESS)
{
return err_code;
}
NRF_LOG_INFO("Found Record ID = %d\r\n",record_desc.record_id);
data = (uint32_t *) flash_record.p_data;
timerTick = data[0];
NRF_LOG_INFO("%d\r\n",timerTick);
// Access the record through the flash_record structure.
// Close the record when done.
err_code = fds_record_close(&record_desc);
if (err_code != FDS_SUCCESS)
{
return err_code;
}
}
return NRF_SUCCESS;
}
Now I'm trying to add a second value to save. The modification in my mind is to change
record_chunk.p_data = &timerTick;
record_chunk.length_words = 1;
to
uint32_t dataToSave[2] = {timerTick, value2};
record_chunk.p_data = dataToSave;
record_chunk.length_words = 2;
Before adding the second value, I tried to modify the code to save the value I initially had. In this case, I always got 810000 no matter what number I set timerTick to save.
uint32_t dataToSave[1] = {timerTick};
record_chunk.p_data = dataToSave;
record_chunk.length_words = 1;
Is this the right way to save multiple values with FDS? Why do I always get 810000 instead of the right value?