Using internal flash memory to store sensor data

Hi Team,

SDK - 17.1.0

chip -nrf52810

I want to store sensor data (12 bytes) every 30 seconds in flash memory. Once the flash is full, I want to replace the old data and continue writing.

I am trying to use FDS library and it's bit confusing.

  1. I am thinking of assigning a sequential number for each sensor data entry and assign that number as RECORD KEY (CONFIG_REC_KEY). CONFIG_FILE will be same for all entries. Is there any problem in doing so ? 
  2. I have configured FDS_VIRTUAL_PAGES as 10 and FDS_VIRTUAL_PAGE_SIZE as 1024. Does it mean that I will have 10 KB of space to write my sensor data ?
  3. Does the FDS driver writes into flash in block sizes (512 byte) or in 4-byte size ?
Parents
  • Hi Buja, 
    1. I don't see any issue of using same file for multiple entries. You can even use the same file and same record keys for multiple entries. It's just when you read them you need to loop through them. Here is from documentation:
    There is no requirement that keys or IDs must be unique. Therefore, more than one record might match the query. The find record functions return one match at a time and keep track of the progress of the operation. They return a status token that encodes the location of the latest match; this token can be used in a subsequent call to continue the search from that position. So to iterate over all matches, you can repeat the call to the find record function using the same token until no more matches are found.

    2. Correct

    3. It's written in 4-byte word. Each time you create/edit a record the record data and the record header is written to flash, 4-byte aligned. 

    If you want to replace old data you need to find a way to delete old data before writing new data. If you keep them in sequence number you can delete the oldest record. In addition, you need to run garbage collection when the flash is full. The flash is full doesn't meant they are all valid records, they can be deleted record but has not been cleared from the flash, and a garbage collection run is needed to completely clean them out. 

Reply
  • Hi Buja, 
    1. I don't see any issue of using same file for multiple entries. You can even use the same file and same record keys for multiple entries. It's just when you read them you need to loop through them. Here is from documentation:
    There is no requirement that keys or IDs must be unique. Therefore, more than one record might match the query. The find record functions return one match at a time and keep track of the progress of the operation. They return a status token that encodes the location of the latest match; this token can be used in a subsequent call to continue the search from that position. So to iterate over all matches, you can repeat the call to the find record function using the same token until no more matches are found.

    2. Correct

    3. It's written in 4-byte word. Each time you create/edit a record the record data and the record header is written to flash, 4-byte aligned. 

    If you want to replace old data you need to find a way to delete old data before writing new data. If you keep them in sequence number you can delete the oldest record. In addition, you need to run garbage collection when the flash is full. The flash is full doesn't meant they are all valid records, they can be deleted record but has not been cleared from the flash, and a garbage collection run is needed to completely clean them out. 

Children
No Data
Related