APPLICATION NOTE 4074

Adding a FAT-Formatted SD Card to MxTNI's File System

Jul 27, 2007

Abstract: By using the SPI interface in the MxTNI™ platform, Secure Digital (SD) cards can easily be accessed. This application note includes all of the necessary code for reading from and writing to an SD card that has been formatted with a FAT file system. That SD card will then provide extra file space which the TINIOS can access.

Introduction

The standard file system for any embedded system is usually small in size. The storage space of the Maxim Tiny Network Interface (MxTNI) platform is no exception. MxTNI's file system resides in the on-board RAM, and is limited by the size of this RAM. Because of this memory constraint, it is important to provide alternatives for data storage. This application note describes how to install an additional file system that resides on a FAT-formatted Secure Digital (SD) card.
By accessing this alternate FAT-formatted file system, MxTNI users are no longer limited in the type and amount of information that they can process. Since MxTNI also uses its RAM for dynamic memory allocations during its runtime, using a supplemental FAT-formatted file system makes more of MxTNI's RAM available for running applications. Since the files stored on the SD card are stored in a FAT file system, the card can easily be read by other systems as well. A standard PC equipped with an SD card reader, for example, could read and write to the same card, thereby allowing easy transfer of files.
Once the SD card's file system has been mounted, there will be no apparent difference between a file that resides on the local file system and one located on the SD card. All interactions with files occur through the standard java.io classes and the com.dalsemi.fs.DSFile class.

Connecting the SD Card

Using SPI is the most convenient way to interface an SD card to the MxTNI platform on the DS80C400 networked microcontroller.
First consider the physical connections between the SPI in the MxTNI platform and the SD card. SPI requires six connections to the card. Wire the SD card to the DSTINIS400 board as described in Table 1.
Table 1. SD Card Connections to the DSTINIs400 Sockets Evaluation Board
SD Card DSTINIs400 SPI Header J21
CLK Pin 1
DI Pin 3
VCC Pin 4
DO Pin 5
GND Pin 6
CS Pin 7

Building and Installing the Example

All of the code required for this application note is available for download (ZIP). The steps for building and installing the code are outlined below. The download also includes prebuilt binaries for MxTNI SDK version 1.17. If you want to use these prebuilt files, skip to step 9.
  1. Download and install the latest Software Development Kit.
  2. Download and extract the source code for this example.
  3. Open a command prompt window and change to the directory where you extracted the example. All of the commands for steps 4 through 10 should be entered at this prompt.
  4. Set a TINI_HOME environment variable to the path where you installed the MxTNI SDK:
    set TINI_HOME=C:\tini1.15
    
    (Note: Steps 5 through 9 below can be performed by running the build.bat file included with the example.)
  5. Extract the SlushSrc.jar file found in the MxTNI SDK to the src directory:
    cd src
    jar -xf %TINI_HOME%\src\SlushSrc.jar
    cd ..
    
  6. Extract the MountCommand.java and UnmountCommand.java files from the OptionalSlushCommandsSrc.jar file found in the MxTNI SDK:
    cd src
    jar -xf %TINI_HOME%\src\OptionalSlushCommandsSrc.jar 
        com\dalsemi\slush\command\MountCommand.java 
        com\dalsemi\slush\command\UnmountCommand.java
    cd ..
    
  7. Add the above Mount and Unmount commands to the list of the commands loaded when Slush boots. To do this, edit the com\dalsemi\slush\Slush.java file. Add the following lines to the initializeShellCommands method:
    CommandInterpreter.addCommand("mount", new MountCommand());
    CommandInterpreter.addCommand("unmount", new UnmountCommand());
    
  8. Rebuild Slush, adding in the native library:
    dir src\*.java /B /S /ON > files
    javac -bootclasspath %TINI_HOME%\bin\tiniclasses.jar;%TINI_HOME%\bin\modules.jar -d bin @files
    java -classpath %TINI_HOME%\bin\tini.jar BuildDependency -f bin 
         -d %TINI_HOME%\bin\tini.db -o bin\slush_fat32.tbin -l -p 
         %TINI_HOME%\bin\modules.jar -add FTPCLIENT;MAILTO;SPI400 -
         fake -noreflect -ref com.dalsemi.slush.util.FakeMainMaker -
         ref com.dalsemi.slush.command.SlushCommand 
         -ref com.dalsemi.protocol.mailto.Handler -t 470100 -ref FATFS -x %TINI_HOME%\bin\owapi_dep.txt
    
  9. Load the new slush_fat32.tbin file into your MxTNI by using JavaKit:
    java -classpath %TINI_HOME%\bin\tini.jar;%classpath% JavaKit -flash 40 -m400
    
  10. Log in to Slush and run the Mount command to add the FAT32 file system:
    mount mnt FATFS
    
You will now see a directory called mnt in the root of your MxTNI's file system. This directory and its files can be accessed exactly like any of MxTNI's traditional files, however, all files and directories found here will be stored in the attached SD card.

Conclusion

By using MxTNI's built-in support for mounting additional file systems, MxTNI's storage capacity can be extended without much overhead. This process frees the applications developed for MxTNI from the constraints of the internal file system. Using an SD card also allows for easy sharing of data files and log files with other FAT-compatible systems.

References

The example code used by this application note can be obtained from Maxim at: files.dalsemi.com/microcontroller/app_note_software/an4074_sw.zip. Further information on the SD media format can be obtained from the Secure Digital Association at:
www.sdcard.org/. The SD media breakout board used in this project can be ordered from Spark Fun Electronics at: www.sparkfun.com/commerce/product_info.php?products_id=204. Further information on the FAT file system can be obtained from Microsoft at: www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx.

MxTNI is a trademark of Maxim Integrated Products, Inc.



Next Steps
EE-Mail Subscribe to EE-Mail and receive automatic notice of new documents in your areas of interest.
Download Download, PDF Format (33.6kB)  
Share
Other Channels  E-Mail this page to an associate or friend. 




APP 4074: Jul 27, 2007
APPLICATION NOTE 4074, AN4074, AN 4074, APP4074, Appnote4074, Appnote 4074

Share



More




Contact Us     |     Privacy Policy     |     Legal Notices
Copyright © 2012 by Maxim Integrated Products