Non Volatile Memory Storage using C#

We are developing an embedded application using Colibri T20 SOM + Iris Carrier board shipped with windows embedded compact 7 OS. Since our main focus was display using touch interface we decided to develop our application in C# using windows form environment. Do we have any access to the non volatile memory storage like Flash directly some of our information related data. We know SQL Data base is an option but do we have any direct interface to the flash memory to retain our data on POWER OFF of the module also. What is best suited for embedded application development to store permanently?

You can save data in a file(give file path as \FlashDisk\filename) if that is an option.
If you want to frequently write data, I think you should use external memory like sd card (path \SD Card)?

you can use the database as well, check below-mentioned articles for hints:

Hope above information helps.

What is the problem in frequent write or i can say frequent overwrite of the data in the the file located at \FlashDisk\filename ?

The issue is that any kind of flash memory can survive a limited number of erase cycles. we are talking about hundred thousands or more cycles per block, but an application that writes data on a file every millisecond may corrupt the memory in the long run.
You should also consider that some filesystem like FAT are not designed to survive a power failure.
We usually format our internal memories using TFAT or TexFAT that are designed to correctly recover from a power failure losing at most the data that were not completely stored at the time of the power-down.
In general, if you need to save information every few minutes, using a file is perfectly ok.
If you have higher frequency we may discuss solution to mitigate potential flash long-term issues, but this also depends on what your application needs to store.

Thank you for the detailed description of the answer. Now if my application is using continuous read from the file (say for every 200ms) and write is occasional (only when customer want to change some of the parameter) , Is there any problem in using the file system to store my data ? If not what other options i have to my data permanently. ?

Reading is not doing any “damage” to the flash, the critical part is writing. If you are updating your data then a file or a database are perfectly suitable solutions.

Reading is not an issue. If you google for it you will find that there is also a read disturbance. Any altered data due to this will be recognized by the Error Correction Codes (ECC) / Bad Block Handling. I rather assume that the flash will be worn out by writing.

To understand how long your flash will survive you have to do some calculations. As Valter mentioned on the T20 you have around 100K write cycles on each block. Unfortunately when writing one block, often more than that is written (wear leveling, flash block size bigger than the data you actually want to write, File System overhead, …). This is called write amplification. The write amplification is typically 1.1 to 2, if you write really small amount of data this can also be much more.

So lets do a simple calculation. Let’s assume the floowing parameters:

  • You have 100MByte free disk space
  • The write amplification is 2.
  • Your user writes 100Kbyte every 10 seconds
  • You are using a NAND flash that supports 100’000 write cycles

We can basically write 100MBytes by 100’000 times until the flash is broken.

100Mbyte * 100'000 = 10 TByte

As your user writes 100Kbyte and we have a write amplification of to we write 200 KByte with every write

100KByte * 2 = 200KByte

This results in 10TByte / 200Kybte times we can write. We write every 10 sec

10TB / 200KB * 10s = 500'000'000s = 5787 days

So in this case the flash would last around 16 years.

If you only write very small chunks to the disk, I would suggest to first cache the writes you are doing. Normally the OS already can handle that, depending how you open a handle to the device. Check the “CreateFile” parameters for more details.

So what would you suggest for our application where we want to store some small information related data. around 2KB ,write is occasional and read is on every POWER ON. Can we go with the file system module and store data in the internal flash ? Or we need look for external EEPROM ?

I think that for this amount of data and read/write activity the filesystem is the perfect solution.

Than you so much for the conclusion. We have tried this and works reasonably fine. We are going ahead with this solution . In future if we find any better solution we will upgrade to that.

Thank you.