Sorted by Squirrels.

Thursday, 22 January 2009

Say Hello to uFat2

There has been a flurry of activity recently and a number of uFat users have been in touch, which is nice! In response to this I think it's about time that I posted my latest updates. The code is thoroughly commented and should answer most questions.

Most notably I have broken the dependency on a particular device library. Now you can use any code capable of reading 512byte sectors from any FAT formatted device.

Since a number of you dear readers asked about traversing FAT directories I've abstracted this requirement into a core feature. By providing a function callback you can now process FAT directory entries to your heart's desire!

It's still a lightweight library but there may be new ideas here for some beginner programmers. I don't think there's anything that should scare anyone though. Concepts such as pointers to functions and PROGMEM data storage are used throughout, but you should be able to use this as it stands without this knowledge. The example sketch should cover the most obvious use cases of printing a listing of files and updating a file on the card.

I developed this under the latest IDE at time of writing which is Arduino-0012. As usual, I'm happy to help with any problems or queries you might have.

Here's the goods: SMB_LIBRARIES and for pudding: The demo sketch

The code is now hosted on Google Code. You can download it here

Refer to the header files for usage, tips, and perhaps a LOL or two. If you're lucky ;)

Written, admired and duly


Osma said...

Thanks, this is a really nice library!

Just a small fix: I had trouble compiling the libraries and example using arduino-0012 under Linux. The problem is that you have used #import "wprogram.h" and #import "wconstants.h" in the code (in all these files: mmc.h, mmc.cpp, microfat2.h, microfat2.cpp, uFat_Example.pde). These imports probably work in Windows where filenames are case-insensitive, but not necessary in other operating systems.

I changed these to "WProgram.h" and "WConstants.h" respectively and the code compiled without hitch.

Now I should get on wiring my SD slot (btw, NKC Electronics makes great SD socket breakout boards!) to my Arduino to really try this out...

Sir Morris said...

Thanks very much for letting me know! I'll update the code.

Good luck with the project!

MAL said...

Thanks for all of your hard work and detailed explaination. uFAT seems like just what I need. I'll surely have questions later as I try to interface to a microSD card.

Sir Morris said...

Thanks! It's lovely to get feed-back!

Any problems with this just yell.

There's a little action happening here:

This jumps in at (what is at this time) the end of the discussion, but I always find that's a good place to start!

Tinnio said...

Has uFat_Example.pde been excluded from the SMB package?

Sir Morris said...

I'm away from fun at the moment but I will check and update accordingly.

Moris said...

Hi Sir Morris ,
I tried using the uFAT on my Arduino and managed to get it to identify the SD with the file on it but it doesn't write anything to it .
If the file is removed I get an error but if fie is in then I only get :
"uFat / DevicePrint Demo

All initialised OK!

but nothing actually happens .
Do you have any pde file with an example that enables reading / writing the SD via UART ?
Thank a lot.
Moris Zen.
(email is moriszen[DEL THIS]

bigwave said...

Can this library be used with the SD card socket on the official ethernet shield?


Sir Morris said...

Now there's a question :)

I'm certain the answer is yes. I've never even been close to one of these but I suspect they all work the same way. The Atmel chip has built-in hardware support for SPI and this is one way that the sd/mmc card can be interfaced. It would be a lot of bother to try and make it happen any other way...

Sir Morris said...


(Great name!)

Sorry - I don't have anything like this.

bigwave said...


Thanks for the quick response!
I think I've found part of the solution here:
And it says "But you have to change the CS Pin in the Code to Pin 6, since the default CS Pin is used for the Ethernet Device."

However I am already using pin 6 for my LCD display.

So my question is, Can you use any pin for the chip select (CS) line? Or does it need to be a PWM pin?

Sir Morris said...

You are complete liberty to choose any pin you like for /cs. Only MOSI/MISO/CLK are predetermined in the hardware.

It should be a simple enough matter to fiddle the firmware...

steinmap said...

I found this great library uFat2 and thought I'll try it out. Thanks very much for it!

But I've a problem that I can't solve. I uploaded the "DevicePrintDemo" to my Arduino and I keep getting the message "Error couldn't initialise microfat". I tried the sketch "dptest" and there it said the same error with the number 2. So the arduino couldn't read the boot sector. I don't know, what that means and what I should do now.

As I didn't found a single word about this problem in the internet, I thought I ask here.

Sir Morris said...

Hi there.

Can you possibly try with a different card? One problem with uFat being so ultra-minimal (and old!) is compatibility.

I'll suggest some improvements to the initialisation code as soon as I can can.

Swiss Arduiner said...

Thank you for your answer.

I tried an other card (an older one with 512MB instead of 1GB) and there was no more errors!
So I think the uFat library works only with old cards (not HC).

So everything is fine now. Thank you another time for having written this great library!

hobby16 said...

Hi, Sir Morris,
Thanks for your AMAZING ufat.

I've got an arduino chip with a 16Mhz quartz on a breadboard powered with 3.3V (must reprogram hfuse to 0xDE otherwise brownout kicks in and the AtMega never starts), an 128M SDCard directly connected to arduino without the divider resistors (since 3.3V is used instead of 5V), text file DATA.TXT on the SDCard and guess what, it works flawlessly without any soft & hardware debugging whatsoever (got DATA.TXT written to by the Arduino)!

Now a question : why is there no other examples than DevicePrintDemo.pde ? (uFat_Example.pde is missing or I can't find it).
Thanks again for your great library.

Sir Morris said...


I can't remember what socks I have on most days - I'd love to know where I put the other demo :)

I think it was probably absorbed into the deviceprint stuff, which also functions as a full-fledged demo of ufat.

Thanks for your comment!

jcarrr said...


I once came across a description of the use of ufat2 functions, but cannot find my way back. Please point me in the right direction.

Where is the declaration of the chip select line made?


Monty said...

uFat2 sounds great, but smb_libraries appears to be missing from Google Groups. (
Same w/ DevicePrintDemo.
Have they moved?



Daryl Wilding-McBride said...

Same problem here. The download link doesn't work. Can we download this nice-sounding library from somewhere else please?

Sir Morris said...

Apologies! I've looked over the file set and it appears that all .zip files are reporting 'page not found' errors. The rest of the file types are ok. It's most queer.

I have uploaded a new copy of the files as 'ufat-dprint.rar'. Sorry for the inconvenience!

I wonder if there's a way to see all the links I've used to these files so I can amend them?

Justin said...

try the download all button at the bottom, it still lets you download all the files that are uploaded.

Thanks for the library!

Anonymous said...

Dear Sir Morris,
Could you perhaps also upload the example files as .rar files? I've looked everywhere but can't find them - the .zip seems gone as you pointed.
Thank you!

zoomx said...

Files are unreachables since the google group micro-hacker doesn't exist any more.

Anonymous said...

Google Code is going away. Are you planning on moving to github?

This is how we do it

MMC (9) acorn atom (7) zx81 (7) arduino (5) Atari 800 (3) c128 (3) sd card (3) sd2iec (3) sio2sd (3) tatung einstein (3) 6502 (2) Chuckie egg (2) M5 (2) Max6956 (2) QL (2) RCM (2) Sord (2) assembler (2) avr (2) c64 (2) cadsoft eagle (2) eeprom (2) einSDein (2) mmbeeb (2) multi-cart (2) spi (2) system 80 (2) ufat2 (2) vic20 (2) video genie (2) 6502 second processor (1) 6522 (1) 8255 (1) Acorn BBC Micro (1) Apple 2e (1) Apple ][ 2 two (1) BBC 6502 second processor (1) BBC micro (1) DevicePrint (1) Double Choc Chip Muffins (1) FAT (1) IO (1) Jupiter Ace (1) LED (1) Master 128 (1) PCB (1) PIC (1) POV (1) PROGMEM (1) ST (1) Spectrum 128 (1) antex (1) arcade spinner (1) arduino shield (1) atari (1) atmel (1) bakewell tart (1) beer (1) bird's nest (1) bitbucket (1) brokenated XC special (1) cake (1) cassette (1) cassette interface (1) compact flash (1) convert (1) dac (1) de-yellowing (1) eaca (1) efficient (1) einsdein. z80 (1) eye strain (1) failosophy (1) filesystem (1) finally (1) fram (1) french polishing (1) fuse (1) fuses (1) gaming (1) github (1) glue (1) google chrome (1) heroic failure (1) high voltage programming (1) hot irons (1) if (1) jiffydos (1) joey beltram (1) lego robot (1) library (1) lying (1) machine code (1) matron (1) microcode (1) mmc interface (1) mmc2iec (1) mmm (1) mouse guts (1) multicart (1) oscilloscopes (1) pcm (1) pic32mx (1) porn (1) proto shield (1) purple (1) repo (1) retro computer museum (1) retro hard-on (1) rom box (1) sd (1) sd2mmc (1) seadragon (1) silliness (1) small (1) software master (1) soldering (1) sord m5 (1) spi software master (1) stray capacitance (1) string (1) techadventure (1) test equipment porn (1) ts1000 (1) turtle cheesecake (1) tweaking (1) vc20 (1) video head (1) video ram replacement (1) weewee (1) wingasm (1) wire library (1) wodges of IO (1) xilinx cpld (1) yellowing (1) zx spectrum (1) zxpander (1)

About Sir Morris

My photo

Loves: Old computers, Old Techno, Old ladies. Cake.
Hates: New computers.

Unless otherwise stated all of the original work presented here is:

Creative Commons License
Licensed under a Creative Commons Attribution-Noncommercial 2.5 Generic License.

The work of others where referenced will be attributed appropriately. If I've failed to do this please let me know.