User`s manual

Dynamic C Users Manual digi.com 141
10.2.1 Overview of FAT Documentation
A sample program is reviewed in Section 10.2.2. Two additional sample programs, one for use with the
blocking mode of the FAT and the other for use with the non-blocking mode are described in
Section 10.2.3. Then Section 10.2.4 gives detailed descriptions of the various FAT file system functions
(formatting, opening, reading, writing, and closing). Short, focused examples accompany each description.
There is some general information about FAT file systems and also some web links for further study in
Section 10.2.5.
10.2.2 Running Your First FAT Sample Program
To run FAT samples, you need a Rabbit-based board with a supported flash type, such as the SPI-based
serial flash device available on the RCM3300 or the RCM3700. FAT versions 2.01 and 2.05 require
Dynamic C 9.01 or later. FAT version 2.05 extends the list of supported flash types to include NAND flash
devices, such as those on the RCM3360 and 3370. FAT version 2.13 requires Dynamic C 9.60 or later and
adds support for SD cards, available on the RCM3900 and 3910.
The board must be powered up and connected to a serial port on your PC through the programming cable
to download a sample program.
In this section we look at fat_create.c, which demonstrate the basic use of the FAT file system. If
you are using a serial or NAND flash device that has not been formatted or a removable device that was
not formatted using Dynamic C, you must run Samples\FileSystem\Fmt_Device.c before you
can run any other sample FAT program. The program, Fmt_Device.c, creates the default configuration
of one partition that takes up the entire device.
If you are using an SD card, run Fmt_Device.c to remove the factory FAT32 partition and create a
FAT16 partition. Be aware that although multiple partitions are possible on removable cards, most PC’s
will not support cards formatted in this fashion.
If you are using a removable NAND flash (XD cards), running Fmt_Device.c causes the device to no
longer be usable without the Rabbit-based board or the Rabbit USB Reader for XD cards. Insert the
NAND flash device into a USB-based flash card reader and format it to regain this usability. Note that this
will only work if you have not defined the macro NFLASH_CANERASEBADBLOCKS. Defining this
macro in a running application destroys proprietary information on the first block of the device, making it
difficult to regain the usability of the NAND device when used without the Rabbit-based board.
If you are using FAT version 2.01 or later, you do not have to run Fmt_Device.c if you initialize the
FAT file system with a call to fat_AutoMount() instead of fat_Init(). The function
fat_AutoMount() can optionally format the device if it is unformatted; however,
fat_AutoMount() will not erase and overwrite a factory-formatted removable device such as an SD
card. If you are using an SD card, run Fmt_Device.c or erase the first three pages with the appropriate
flash utitity (sdflash_inspect.c or nflash_inspect.c).
After the device has been formatted, open Samples\FileSystem\fat_create.c. Compile and run
the program by pressing function key F9.
In a nutshell, fat_create.c initializes FAT, then creates a file, writes “Hello world!” to it, and then
closes the file. The file is re-opened and the file is read, which displays “Hello world!” in the Dynamic C
Stdio window. Understanding this sample will make writing your own FAT application easier.