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
  • OK I have understand how to see the memory :
    0x000F2000   =>   DEADC0DE F11E01FE 00032000 00001111 00000001 0000000E 00000051 00000061 FFFFFFFF FFFFFFFF FFFFFFFF

    Here I have stored the 3 values 0xE, 0x51, and 0x61 under record key 0x2000 and file id 0x1111.
    It looks OK (is it ok to have 32000 instead of 2000 ?)

    When reading after writing successful (using the event FDS_EVT_WRITE from fds_register) :

    But when reading :

    <info> app: Stored valueA 14
    <info> app: Stored valueB 81
    <info> app: Stored valueC 97
    <info> app: Restored valueA 14
    <info> app: Restored valueB 393219
    <info> app: Restored valueC 0

Children
Related