This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/CC3220: File system Query

Part Number: CC3220

Tool/software: TI C/C++ Compiler

Hi,

We want to use the external flash file system to store some limited information.

• if any state variable changes, we could either rewrite the entire state of the system or just store the update in the variable that changed
(depending on implementation)
• one approach is to introduce, say, 100 files that are labelled through and that we cycle through to store state information updates. 

The assumption here is that when we overwrite a file the new copy will be written in the same sector as the original file.

• a different approach would be to try and append to a file until it reaches the 4k sector size.
The idea is that we declare the file as 4k max size but initially only write the 100 bytes state info.
Then, whenever a state change occurs, we just want to append a record of the state variable that changed.
I’m not sure if the CC3220 file system allows us to do that?
Can we append to a file while it remains stored in a single sector? Or will the file system always create a new copy in a new sector whenever we append any data?

  • Hi,

    - Approach with "100 files" is possible and it is one of way how increase durability of sFlash. But do not forget that all files need to be created at the beginning (to be flash space pre-allocated).
    - Approach with append is not possible, because file-system does not support append.

    Personally I would not use approach with "100 files" in real product. Especially when product is not powered by battery. Because this approach assumpt high number of sFlash write operations. High number of write operations increase probability of failure in case of power supply is lost. I think much better will be connect another non-volatile storage to CC3220 (FRAM, EEPROM, FLASH with "append" approach).

    Jan
  • Vidushi,

    I think Jan has some good points for you to consider. At the end of the day, its up to you to decide which implementation will work best for you.

    Regards,

    VR
  • Hi


    I want to go with first approach as i have tried approach with a single file of size 100*4k sound good. So we can independently update any 4k sector in the file without the entire file (or some other header or meta-data) being re-written? How can we check/confirm that? - Independently 4K update should work as we are maintaining sector number in flash including 100 bytes if state information. So after opening 4k *100 file we can read/write using sectorn number or we can pass offset value to read/write call (OFFSET = Sector_Number * Sector_size). Where Sector_size = 4K.

    But this is not working as soon as im updating latest sector previous one getting cleared.
  • Hi,

    I think you not properly understand. You cannot create one file. You need create 100 separate files!

    You need to create you own wear-leveling algorithm inside your code. After 100 000 write cycles into one file, you will stopped re-writing this file and you will go to 2nd file, etc. It is mandatory to be files created at the beginning. You can't delete this file, you can only rewrite it.

    Jan
  • Hi Jan

    Yes i understand your point of creating 100 files & i created that & start writing on that file. Query is:

    1. How can i create my own wear-leveling algorithm inside my code? 

    2. If ill rewrite it then it will erase sector(Previously saved info ) & write again on that sector? right?

  • Hi,

    There can be more algorithms for this type of wear-leveling, implementation depends on you needs (how big is your sFlash, how much data you want to write, how much you expect free space, etc.). This is only example of one possible ways:

    Let say that you want store 3kB runtime data. You expect big free space inside your sFlash. Your flash have durability 100k write/erase cycles of sFLash.

    1. A beginning you create file with size 3kB - let say file000.dat
    2. You start saving your runtime data into this file. Part of this data will be write counter (how much times was this particular file rewritten - alternatively you can use counter from sl_FsGetFileList)
    3. When you count 100k write cycles at file file000.dat. Than you stopped writing into file file000.dat and create new file file001.dat and continue with writing into this file. Important thing. You cannot delete file file000.dat. It need be still there.
    4. Important part of your firmware will be searching for current opened file for write. This need to be done after startup. It cam be simple:
    - read file file000.dat and check write counter
    - if there is 100k, goes to file001.dat
    -etc.

    Answer to your 2nd question:
    When you open file for write, content of file is erases and write operation is done into same sectors.

    Jan
  • Hi Jan

    Thanks for your early response.

    I did same kind of thing

    I have created 100 files in the beginning name test1.txt to test100.txt.
    On first write i have opened first file config1.txt & write Version number + data & incremented current file index...
    Then called second write based on g_cur_file index it will open next file n write updated Version in this
    Then reading & printed data on all files 0 to current file index. So this is working fine to achieve wear levelling, we need to distribute erases to different sectors, instead of erasing same sector repeatedly this is what we are doing - after writing in file 1
    we are erasing & writing in file 2.

    Important part of your firmware will be searching for current opened file for write after reboot? How can i check how many files i had created last time?
  • Hi,

    I think you understand root of the case correctly. Generally there are two possible approaches:
    - you write into one file, till you exhaust write cycles and then open new file
    - you can cycle write between all files (1st write -> test1.txt, 2nd write -> test2.txt .... 101 wite -> test1.txt)

    I think easiest way is save write number together with data into file. At beginning you will read this numbers from all files and find file with highest number. This will be latest file and you can continue from this file.

    Jan