Hey, I want to save stuff to flash under the same id and key which should be no problem as shown in the documentation. But when I save it and retrieve the data only the last saved data is in both of the entries. I use SDK 13.
Here is the relevant code.
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;
NRF_LOG_INFO("Start searching... \r\n");
// 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);
NRF_LOG_INFO("Data = ");
data = (uint32_t *) flash_record.p_data;
for (uint8_t i=0;i<flash_record.p_header->tl.length_words;i++)
{
NRF_LOG_INFO("0x%x ",data[i]);
}
NRF_LOG_INFO("\r\n");
// 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;
}
And here the write function:
static ret_code_t fds_test_write(void)
{
#define FILE_ID 0x1111
#define REC_KEY 0x2222
static uint32_t m_deadbeef[2] = {0xDEADBEEF,0xBAADF00D};
fds_record_t record;
fds_record_desc_t record_desc;
fds_record_chunk_t record_chunk;
// Set up data.
record_chunk.p_data = m_deadbeef;
record_chunk.length_words = 2;
// Set up record.
record.file_id = FILE_ID;
record.key = REC_KEY;
record.data.p_chunks = &record_chunk;
record.data.num_chunks = 1;
write_flag = 0;
ret_code_t ret = fds_record_write(&record_desc, &record);
if (ret != FDS_SUCCESS)
{
return ret;
}
NRF_LOG_INFO("Writing Record ID = %d \r\n",record_desc.record_id);
m_deadbeef[0] = 1;
m_deadbeef[1] = 2;
// Set up data.
record_chunk.p_data = m_deadbeef;
record_chunk.length_words = 2;
// Set up record.
record.file_id = FILE_ID;
record.key = REC_KEY;
record.data.p_chunks = &record_chunk;
record.data.num_chunks = 1;
while (write_flag==0);
write_flag = 0;
ret = fds_record_write(&record_desc, &record);
if (ret != FDS_SUCCESS)
{
return ret;
}
NRF_LOG_INFO("Writing Record ID = %d \r\n",record_desc.record_id);
}
The relevant output is this.
APP:INFO:Writing Record ID = 7
APP:INFO:Writing Record ID = 8
APP:INFO:Start searching...
APP:INFO:Found Record ID = 7
APP:INFO:Data = APP:INFO:0x1 APP:INFO:0x2 APP:INFO:
APP:INFO:Found Record ID = 8
APP:INFO:Data = APP:INFO:0x1 APP:INFO:0x2 APP:INFO:
Anyone knows whats wrong? Thanks in advance.