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

Flash Data Storage (FDS) not writing or reading records correctly

Hello everyone,

I am working on a project using FDS. I am using the nRF52832 with the s132 SoftDevice.

As far as I can tell, the code I've written to store data records and retrieve them should work, yet I am having problems. I've confirmed with FDS stats that there are records being written, but when going to retrieve the records, I only get garbage data. I know that when writing records, the correct data is passed to the function.

My code to write records:

static void write_record(data_record_t* p_data, uint16_t key) {
    fds_record_t record_to_write;
    fds_record_desc_t record_desc;
    ret_code_t err_code;

    record_to_write.file_id = FILE_ID;
    record_to_write.key = key;
    record_to_write.data.p_data = (const data_record_t*) p_data;
    record_to_write.data.length_words = 2;

    err_code = fds_record_write(&record_desc, &record_to_write);
    APP_ERROR_CHECK(err_code);
}

My code to read records:

static void read_record(uint16_t key, data_record_t* p_record) {
    ret_code_t err_code;
    fds_record_desc_t record_desc;
    fds_find_token_t ftok;
    fds_flash_record_t flash_record;
    data_record_t data;

    memset(&ftok, 0, sizeof(fds_find_token_t));

    err_code = fds_record_find(FILE_ID, key, &record_desc, &ftok);
    APP_ERROR_CHECK(err_code);

    err_code = fds_record_open(&record_desc, &flash_record);
    APP_ERROR_CHECK(err_code);

    memcpy(&data, flash_record.p_data, sizeof(data_record_t));
    p_record->next_record_key = data.next_record_key;
    p_record->reading = data.reading;

    err_code = fds_record_close(&record_desc);
    APP_ERROR_CHECK(err_code);
}

Any ideas what might be going on here?

Thanks.

Parents Reply
  • FDS operations are queued, so this could be the problem. I lack enough information of your application to know, though. The key is that you must ensure that the memory is valid until the data is written to flash. I suggest that you double-check that, and also inspect the FDS flash are with a debugger to verify that it gets correctly written. If not, then you know the issue is with the writing. If it is correctly written, then you know there is a problem with how you read.

Children
No Data
Related