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

FDS update returns or changes some part of data randomly.

Hi,

We are using NRF 15.03 SDK and used NUS application for the project. We need to store some data into flash and we are using FDS example based code to do the same.

We are storing two files. File 1 has 6KB data (divided into 500 records of 12 Bytes) , file 2 contains 268B of single record. We are using same file ID for both and a different record ID for all the records.

The code works fine as expected. But randomly, the data gets corrupted(old data is retained instead of new) when we do update of records.

This occurs very randomly and we could not find the sequence it is occurring.

Has anyone seen this kind of behavior? How do we make sure that we are storing the data correctly?

Are there any corner cases we need to handle while using FDS?

Thank you,

Bharath

Parents
  • Hi Einar Thorsrud,

    Thanks for your reply.

    I added a variable to check if the write/update is complete in the fds_evnt_callback switch cases. Every time, the variable becomes true and I write data, it succeeds.

    At some point when the fds_gc gets called, the callback function calls "FDS_EVT_GC" & I call my write pending function to write back the pending data. But the callback never gets called for update complete after this .

    Thank you,

    Bharath

  • Hi Bharath,

    Good to hear you fixed the initial issue.

    Bharath Gopal said:
    At some point when the fds_gc gets called, the callback function calls "FDS_EVT_GC" & I call my write pending function to write back the pending data. But the callback never gets called for update complete after this .

    It is difficult to say anything specific without seeing your code. But another typical issue when people test FDS is problems with interrupt priorities. Do you by any chance call the write function from the event handler (or a function that is called from there or in another interrupt context)? If so, and if you also wait for the event in a loop, then you will have a deadlock. This is all just guesses though. Please share and explain your code if it does not fit so that I can see what you are actually doing.

  • Thanks for the update Einar.

    I am calling write function from UART interrupt on receiving some commands. Also, the update pending write is called from FDS_EVT handler.

    When I check for the return code inside FDS_EVT  handler, it returns code 3 (FDS_ERR_UNALIGNED_ADDR).

    What does this error mean?

    Thank you,

    Bharath

  • Hi,

    This means that you are providing a pointer to an address that is not a multiple of 4. This is invalid since all flash operations must be word-aligned, and the flash words are 4 byte-sized.

  • If it is so, why does it fail only some time? I am using a global buffer every time and the address is always same.

    If it is a address alignment issue, how to make sure that the buffer is word aligned?

  • Hi,

    Bharath Gopal said:
    If it is so, why does it fail only some time? I am using a global buffer every time and the address is always same.

    I cannot explain that. Can you double-check?

    Bharath Gopal said:
    If it is a address alignment issue, how to make sure that the buffer is word aligned?

    This is only an issue if you are using non-4 byte data types, or for instance structs with some members that are not 4 bytes. Then depending on the packing of the struct, the data may not be aligned. See this post for how to fix it in that case. If that does not help, please share some code showing the data structure you are trying to write to flash and how you write it.

Reply
  • Hi,

    Bharath Gopal said:
    If it is so, why does it fail only some time? I am using a global buffer every time and the address is always same.

    I cannot explain that. Can you double-check?

    Bharath Gopal said:
    If it is a address alignment issue, how to make sure that the buffer is word aligned?

    This is only an issue if you are using non-4 byte data types, or for instance structs with some members that are not 4 bytes. Then depending on the packing of the struct, the data may not be aligned. See this post for how to fix it in that case. If that does not help, please share some code showing the data structure you are trying to write to flash and how you write it.

Children
No Data
Related