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

old data gets overwritten in fds when i read the data after setting a new one.

I have written a flash code using fds in which i am trying to save the data 7pages(1024 each). I have defined array of record key and fie ID for it.The problem it saves for first time  but then due to some pointer problem or something, it gets old data and overwrites in it. Here is the flash file.

Parents Reply Children
  • I tried your example and it worked properly.As you have seen my code, I declared an array of record & file id to save different records at different pages.The data that i am saving is - 

    1.Array of structs[100](pg 0-4).

    2.One separate struct(pg 5)

    So whenever i get and set the data, i provide the index also for record,file ID.If there is no record, it creates a new one.When i updates any file, it invalidates the old one.But when i reads it, i gets one step back and  gives the old data.If i keep reading, it goes one step back everytime.

  • I suspect that instead of updating the record, the code actually creating new record with same File id and key. Note that, fds allow to have multiple record having same file ID and key. Each time you use fds_record_find() with the previous token, it will try to find the next record that matches File ID and key. 

    Please add some debug log especially inside get_flash_data()

    I would suggest instead of using 

     if (err_code == FDS_SUCCESS)

    if (err_code == FDS_ERR_NOT_FOUND)

    You use : 

    else {if (err_code == FDS_ERR_NOT_FOUND)

    And then check if there is any other err_code. 

    And on each of the return code of any other API call, you need to check if it's success or not. 

  • Yes it does create a new record with same File id and key, but i am initialising all descriptors and token every time i do a read or write.So why on read would i get the old data because it is invalidated.And also now i am using one file ID and also one page of 8kb to store all the data. I have seen this issue is also faced by other people here and i don't think they've got the solution.

  • Yes, the record should be marked as dirty (header = 0xFFFF0000). Could you check in the flash if you see the header 0xFFFF0000 ? You can read the whole flash dump using nrfjprog.exe --readcode

    If you can provide an example code (a project with source) that reproduce the issue it would be much easier for us.

    Could you provide the link to the similar cases ? 

    Be careful when defining large virtual page. Could you try to test setting the FDS_VIRTUAL_PAGE_SIZE = FDS_PHY_PAGE_SIZE = 1024 ? 

  • So when i set the data in different records, and read  anyone, the same data is getting copied everywhere.Everything seems fine to me too.I am using same file ID and different keys.I also tried for initializing descriptor and flash_record_t every time.But nothing helped. Can give some tips if you have encountered a similar issue before?

Related