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

Can't correctly restore data stored with FDS

Hello,

I am using FDS to store three int32_t numbers.

Here is my code for storing :

static void store(void)
{
    int32_t value_A = get_value_A();
    int32_t value_B = get_value_B();
    int32_t value_C = get_value_C();
    int32_t values[3] = { value_A, value_B, value_C };

    NRF_LOG_INFO("Size %d", sizeof(values)/sizeof(int32_t));

    fds_record_t record;
    record.file_id           = FILE_ID;
    record.key               = RECORD_KEY;
    record.data.p_data       = values;
    record.data.length_words = 3;

    ret_code_t err_code;
    err_code = fds_record_write(&record_desc, &record);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_INFO("Stored value A %d", value_A);
    NRF_LOG_INFO("Stored value B %d", value_B);
    NRF_LOG_INFO("Stored value C %d", value_C);

    read_values();
}

Here is my code for reading :

static bool read_values(void)
{
    memset(&ftok, 0x00, sizeof(fds_find_token_t));
    fds_flash_record_t flash_record;
    fds_record_desc_t record_desc;

    while (fds_record_find(FILE_ID, RECORD_KEY, &record_desc, &ftok) == NRF_SUCCESS)
    {
        if (fds_record_open(&record_desc, &flash_record) != NRF_SUCCESS)
        {
            return false;
        }

        const int32_t* values = flash_record.p_data;

        int32_t value_A = values[0];
        NRF_LOG_INFO("Read value_A %d", value_A);

        int32_t value_B = values[1];
        NRF_LOG_INFO("Read value_C %d", value_B);

        int32_t value_C = values[2];
        NRF_LOG_INFO("Read value_C %d", value_C);

        if (fds_record_close(&record_desc) != NRF_SUCCESS)
        {
            /* Handle error. */
            return false;
        }

        return true;
    }
}

Here are the logs (stored values are the correct ones) : 

<info> app: Size 3
<info> app: Stored value A -11810
<info> app: Stored value B -5737
<info> app: Stored value C 200

<info> app: Read value A 536882505
<info> app: Read value B 72429
<info> app: Read value C 100360

What am I missing ? This *looks* like a uint <-> int conversion issue, but I never store nor read as uint ...

Thanks! Best regards

Parents Reply Children
Related