Sunday, January 10, 2010

fat32lib 0.1, zap your card edition.

This is the first alpha, and does not include source except for the main.c menued demo.

fat32lib-0.1b.zip (Update, filename editing, linux test version)

Runs on SparklFun's openlog and any 3.3V arduino with the SDHC attached to the SPI pins.

FAT32 ONLY, no FAT16 support, but will work on any card, e.g. a 512 byte SD card.  (I have only one which maybe should be FAT16 - a legacy spinrite and general fixup DOS boot USB with uSDHC - under 1024 cylinders for really old bioses).  Anything current typically uses FAT16.  No long filename support (see below).

I'm still refactoring, which means in practice that half the lines can be changed, moved, removed, or replaced, and need to clean up some things (like using unsigned long instead of u32).  The library is fairly machine agnostic and I test using linux and ordinary 512 byte reads and writes to /dev/sdX.

Right now it takes just over 8k for FAT32 with everything included, just over 1k for the SD/SDHC driver.  Just under 16K out the door with main.c and libraries (the library and driver don't need any external libraries).


A flashable hex file is included in the zip.  Also the library, driver, main.c, the headers and a Makefile are included which is a menued demo program similar to what OpenLog does, but no eeprom, and fixed at 57600 baud.  A space or any other unrecognized character brings up a menu.  It follows the API in fat32.h.  For logging, N return W will open a sequential log and start sending data into it.  control-z gets back to command, E and F sync the buffer and directory.

Fairly feature complete - extended partitions are disabled in this build (350 bytes).  And I interlock not writing when the "current file" is a directory and not deleting directories (until I can add a directory empty check).  But it is still dangerous.

I've tried to minimize extra reads and writes, but there are still a few places where it could be improved (cluster linking)

Long filenames are not supported because they can straddle three sectors, have to be read backward, and need to work with unicode.  This results in ugly buffer read-writing or shuffling and would need a huge string match buffer.  For embedded applications, reading and writing 8.3 DOS names should suffice.

Version 0.1b includes my high-performance SD driver source. Verified on everything from 512Mb to 16Gb, the Eye-Fi, HC and normal, version 1 and 2. I went through the spec and tried to do the initialization properly. The transfer loops should optimize well and run fast (copyright, use at your own risk, but free for educational use, post comment for other terms).

No comments:

Post a Comment