FIRST Robotics Competition Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it safe to continously write to flash

Looking over the CompactRIO cRIO-FRC Operating Instructions and Specifications, I don't see any reference to the lifetime of the flash memory on the cRIO. Some older flash memory is only guaranteed for 10k write cycles, while newer flash memories may be good for a million write cycles or more, and may have sector wear leveling to extend it further. What is the lifetime for the flash in the cRIO?

I would like to, every 10 seconds, open a file, write to it, then close it. Should I expect any long term problems with this type of behaviour?

0 Kudos
Message 1 of 6
(9,033 Views)

Hi,

The flash memory has a wear leveling algorithm, which means successive writes to the same file will use different sectors on the flash memory array.  Generally the lifetime is flash memory isn't specified, since it is entirely dependent on how often it is being written to, and how much data is being written.  However, you can figure a rough estimate: ((size of memory)/(size of write))*1000000 = number of writes.  Thats assuming 1,000,000 writes per sector, which is also an average case, some sectors will fail sooner, and some will fail later (also I'm not sure what the exact spec on the cRIO's flash is, but 1,000,000 is pretty common these days).  For all intents and purposes however, you aren't going to wear out the memory.  Just avoid writing an infinite loop that continually rewrites a 50 megabyte file and letting it run for several months 🙂

Regards,

JeremyB
Applications Engineer
National Instruments

Regards,

Jeremy_B

Applications Engineer
National Instruments
0 Kudos
Message 2 of 6
(3,139 Views)

Sciencewhiz,

You should have no issues writing files to the cRIO flash.  Many industrial embedded applications utilize the flash memory on the cRIO to log data.  But I do have a couple recommendations for you.

1.  Try to avoid opening, read/writing, and closing in a loop.  Open and closing the file incurs additional CPU overhead and could lead to decreased performance.  This can be avoided by opening and leaving the file open while your program is running and writing to the file as needed (every 10 seconds on your case).  You can close the file when your program shuts down.

2.  Place your file I/O code in a separate loop that iterates once every 10 seconds and is passed data with global variables.  This will help ensure the file I/O code does not effect the performance of any of your other loops.  This is an example of the Producer/Consumer application design pattern. 

Cheers,

Mark

Mark
NI App Software R&D
0 Kudos
Message 3 of 6
(3,139 Views)

As the robot could be turned off at any point, is there any problem with leaving a file open? My assumption was that it was safer to close the file.

Thanks for the tip about the seperate loop. That's how I was planning on implementing it.

0 Kudos
Message 4 of 6
(3,139 Views)

Hi,

Generally leaving a file open shouldn't be a problem.  If you lose power while writing to it, you could lose some of the data you were trying to write, but the rest of the file should be intact.

Regards,

JeremyB
Applications Engineer
National Instruments

Regards,

Jeremy_B

Applications Engineer
National Instruments
0 Kudos
Message 5 of 6
(3,139 Views)

If you are going to leave it open, make sure that the write is flushing to the disk.

0 Kudos
Message 6 of 6
(3,139 Views)