MBED - File system - virtual drive

01 Jul 2009

When i plug the MBED in to the Pc, it comes up as a virtual drive, E:This makes dragging and dropping files (firmware) on the device very easily.

I would like in addition to the firmware to drop some .wav files across and to be able to read them from software on the module. I presume they are stored in the on board flash of the MCU or possibly external flash and it would be useful to be able to access these.

A read only file may be easier to implement than a full read write but it think a read only one would be useful.

You could store serial numbers for example in a text file or a wave file to be played by an audio decoder.

Best Regards

David Giles

 

01 Jul 2009

Hi David,

You might want to look at this Project http://mbed.co.uk/projects/cookbook/wiki/WavePlayer

But it uses for speed reasons an external SDCard over SPI.

The Datalogger is a good example how to use the LocalFileSystem class to use the internal flash with your program.

http://mbed.co.uk/projects/cookbook/wiki/AccelerationDatalogger

To use the ANSI fopen, fread, fwrite, fseek, fclose ... functions on your local flash drive you have just to make an instance of the LocalFileSystem class with a mount point in the constructor like:

...

LocalFileSystem("local");

int main() {
  FILE *file = fopen("/local/foo.txt", "r");

...

This would open a file stored on your drive as "e:\foo.txt".

But there are some things to keep in mind:

  • The file system does not allow long filenames.
  • And at the moment there is no support for folders.
Best Regards
Rolf

07 Jul 2009

David, as Rolf noted there is a LocalFilesystem that does just what you asked.  However it's very slow.  See the filesystem benchmarking results I posted in the cookbook area.  It's not nearly fast enough to play back a wave file, I tried that very thing myself and had to put it on hold until Simon and the other mbed gurus came up with the SDCard filesystem.  Actually the SDCard filesystem isn't really fast enough either, but it's easy enough to hotrod the SPI clock and get as much throughput as you need.  See the above mentioned benchmarking results for details.  Also, I've posted my wave file playing code if you'd like to take a look.  I think it's fairly robust, it's played back all the wave files I've thrown at it, both stereo and mono, and various sample rates.