Electronic – Is it a practical technique to add a dedicated flash/RAM IC to increase a microcontroller’s memory to avoid writing to an SD card

flashintegrated-circuitmicrocontrollerramsd

I'm working with an Atmega328P microcontroller. This microcontroller will be generating data and will be storing that data onto an SD card. My project will also be battery powered. My research has shown that writing to an SD card is relatively expensive. Especially due to the fact that I'm using a 225mAH battery with a 120mA limited power regulator.

I've read that a common method for saving power is to buffer write commands into a single write. This seems relatively straightforward.

However, I'm now running into the problem that the Atmega328p only has 2kB of RAM. Thus, I really have limited buffer space.

So my question: would it be a viable technique to purchase a dedicated flash memory / RAM IC to increase buffer space? I'm curious about the practicality of this and how difficult it would be to implement.

Any thoughts? I know the obvious answer would be to purchase a microcontroller with more RAM, but I'm trying to stick with this microcontroller such that the project is Arduino language compatible.

Best Answer

I have implemented a system like this. We used non-volatile FRAM as a buffer, but SRAM would work too depending on your requirements for surviving power loss.

I buffered data into the FRAM until it was nearly full. I then wrote it to SD card. To make the system more reliable, I used checksumming of blocks in FRAM. I also wrote all the filesystem metadata from the SD card into FRAM as well. When updates were required, the FRAM was updated first and then copies to the SD card, making updates atomic (i.e. at no time in the process was it possible to lose data or leave the filesystem in a corrupt state). I used a modified FAT32 driver for this, which is unfortunately proprietary code or I would share it.

I found this to be a very efficient method. Although some time is lost to writing data three times (once to the FRAM data buffer, then to the FRAM SD card block buffer, and then to SD card) this was actually largely compensated for by being able to DMA the data out and do other processing in the mean time.

With normal volatile RAM, obviously you can't use it to make writes atomic. However, the buffering is still valuable. In my tests SD cards write significantly faster if you can save blocks of >4kB at a time, ideally 64kB or more. This is likely due to the way their internal flash memory is managed.