FDS records data is incorrect after many records written

At the start of my application, I write several hundred of records, each of size 8 words.
Each file_id/record_key is unique (one record combination per file_id/record_key)
After each write, I wait for the FDS event on completion.

At the end, if I try to read the first few hundreds records, data is correct.
But when retrieving the last dozens records written, I retrieve data full of 0xFF

Every function returns are checked and return NRF_SUCCESS.
I have set FDS_VIRTUAL_PAGES to a large enough number.

Writing :

static void fds_evt_handler(fds_evt_t const * p_fds_evt){
    storage_access_in_progress = false;
    switch (p_fds_evt->id)
    {
        case FDS_EVT_INIT:
            if (p_fds_evt->result != NRF_SUCCESS)
            {
                APP_ERROR_CHECK(p_fds_evt->result);
            }
            break;
        default:
            break;
    }
}

static void wait_for_storage_access()
{
    while(storage_access_in_progress) {}
}

void memory_init()
{
    ret_code_t err_code = fds_register(fds_evt_handler);
    APP_ERROR_CHECK(err_code);

    storage_access_in_progress = true;
    NRF_LOG_INFO("Initializing FDS");

    err_code = fds_init();
    APP_ERROR_CHECK(err_code);
    wait_for_storage_access();

    err_code = fds_gc();
    APP_ERROR_CHECK(err_code);
    wait_for_storage_access();

    NRF_LOG_INFO("End init FDS");
}

void write_all() {

    // In a loop, write 100 records :
    // LOOP START
        uint8_t* data_copy = malloc(SIZE_32);
        // Fill data_copy
        // Increment record_key and/or file_id
        // (...)
    
        fds_record_t record;
        record.file_id           = file_id;
        record.key               = record_key;
        record.data.p_data       = data_copy;
        record.data.length_words = SIZE_32 / 4;
    
        NRF_LOG_INFO("Write record type %s file %x key %x", data_type_to_string(data_type), index_to_file_id(data_type, index), index_to_record_key(data_type, index));
    
        ret_code_t err_code;
        storage_access_in_progress = true;
        err_code = fds_record_write(NULL, &record);
        APP_ERROR_CHECK(err_code);
        if (index > 645) {
            NRF_LOG_HEXDUMP_INFO(i_data, 32);
        }
        while(storage_access_in_progress) {}
    // LOOP END
}

Reading : 

fds_find_token_t ftok;
memset(&ftok, 0x00, sizeof(fds_find_token_t));
fds_flash_record_t  flash_record;
fds_record_desc_t   record_desc;

err_code = fds_record_find(file_id, record_key, &record_desc, &ftok);
APP_ERROR_CHECK(err_code);

err_code = fds_record_open(&record_desc, &flash_record);
APP_ERROR_CHECK(err_code);
NRF_LOG_HEXDUMP_INFO(flash_record.p_data, 32);
err_code = fds_record_close(&record_desc);
APP_ERROR_CHECK(err_code);

Output : 

<info> app: Write record file_id 1001 record_key A043
<info> app:  42 36 31 31 41 37 00 00|B611A7..
<info> app:  00 00 00 00 FF FF FF FF|........
<info> app:  01 00 00 00 FF FF FF FF|........
<info> app:  FF FF FF FF FF FF FF FF|........

<info> app: Write record file_id 1008 record_key A006
<info> app:  37 41 32 36 36 33 00 00|7A2663..
<info> app:  00 00 00 00 FF FF FF FF|........
<info> app:  07 00 00 00 FF FF FF FF|........
<info> app:  FF FF FF FF FF FF FF FF|........

<info> app: Read record file_id 1001 record_key A043
<info> app:  42 36 31 31 41 37 00 00|B611A7..
<info> app:  00 00 00 00 FF FF FF FF|........
<info> app:  01 00 00 00 FF FF FF FF|........
<info> app:  FF FF FF FF FF FF FF FF|........

<info> app: Read record file_id 1008 record_key A006
<info> app:  FF FF FF FF FF FF FF FF|........
<info> app:  FF FF FF FF FF FF FF FF|........
<info> app:  FF FF FF FF FF FF FF FF|........
<info> app:  FF FF FF FF FF FF FF FF|........

Parents
  • Hi,

    I do not immediately see any explanation for this. However, I notice that the only DFS event you handle is FDS_EVT_INIT. Can you add handling of FDS_EVT_WRITE also, and check the result (see for instance how that is done in <SDK>\examples\peripheral\flash_fds\main.c? Do you see an error here, or was the write successful?

    If you don't make progress, can you upload a complete minimal failing example (with instructions on how to build and test on a DK) so that I can have a look and test on my side?

Reply
  • Hi,

    I do not immediately see any explanation for this. However, I notice that the only DFS event you handle is FDS_EVT_INIT. Can you add handling of FDS_EVT_WRITE also, and check the result (see for instance how that is done in <SDK>\examples\peripheral\flash_fds\main.c? Do you see an error here, or was the write successful?

    If you don't make progress, can you upload a complete minimal failing example (with instructions on how to build and test on a DK) so that I can have a look and test on my side?

Children
Related