Hello,
I am using one nrf52840 based SOC with nRF5_SDK_17.0.2_d674dde SDK for one of our project. I am trying to utilize internal 1MB of flash for storing some data. For that I am using FDS library. I am writing to flash on periodic basis in chunks of size > 220bytes. Till that time I will hold onto the data in local buffer. However if and when a request is made to get the data, first I am immediately writing all the data held data to the flash so that while reading back I can collect all the data from there itself. In such cases the last packet which is being immediately written may not be >220bytes. Data contains multiple sample of 14 bytes each and each sample contains timestamp.
Now the problem which I am facing is that while reading back from the flash, the data read is not in sequential manner i.e. the last packet which I read back is not the last packet which I stored in the flash. This happens mostly when the size of data is less than my maximum threshold which is case when I am writing the last packet when I data request comes. What I actually read is the last >220 bytes of packet. And my less than lets say 50 bytes of data which actually got written to the flash last is read somewhere in between the read attempts. So the data is not lost but it messes up the sequence of the data and timestamps related to it.
I am attaching a file for reference. This is an example set of data which is received from the flash. The data is received in the same sequence as shown in the file. If we try to plot the last column of timestamp we can observe some spikes in the value, which are actually not the spike but smaller set of data being misplaced in flash or while reading back. Those spikes are just the last set of data (which got written last)being read early and sent first.
Is there a reason behind such behavior from FDS? Is it because of some fragmentation in storage space which causes it store data in flash in where it find available space? Or am I missing something in my implementation?