Help needed !! Anybody know fat32 - I need to write to a kl25z and so far can only read :-/

15 May 2013

Here's my project

1) Save a small file to a kl25z using USB MSD Ram ( I've managed to get the device working and recognisable and readable but I can't write to it yet)

2) The device then does a bit of processing on that file (which is basically signing a transaction with a key on the device).

3) Device generates an output file which the user can then copy off the device.

Are there any fat fs experts out there who can help me do this? The files themselves are quite small (1-2k at most) but I just can't seem to be able to get my head around creating a data structure that can be viewed as a fat file (as the usbmsd demos don't have anything beyond a pre-created byte array).

16 May 2013

Hi Richard,

Nice project :)

I just pushed a new version of RAM_DISK which should allow you to write files to the disk.

Then to achieve what you want, there are basically two solutions:

  • You can inherit from FATFileSystem in RAM_DISK. In this case all the fat fs (fopn/fread/...) functions will then be available on the ram disk. But this is quite heavy.
  • The second solution is to write a very basic fat fs parser. The key point to detect if there is a new file available is to read the root directory (sector 2) to check if there is a new entry on it. If there is a new entry, you will find all the info needed (start sector where is located the file/size of the file/...) in the entry. You can find a lot of info on fat fs here:

You can then do some processing on your file and generate a result file. Same solutions here, you can either use FATFileSystem or directly modify the root dir and write the data at a specified sector.

Once your file has been written, you have to disconnect and connect (in software) the USB device to see the result in windows.

Cheers, Sam