You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

220 lines
8.6KB

  1. /* Arduino SdFat Library
  2. * Copyright (C) 2012 by William Greiman
  3. *
  4. * This file is part of the Arduino SdFat Library
  5. *
  6. * This Library is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This Library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Arduino SdFat Library. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. \mainpage Arduino %SdFat Library
  22. <CENTER>Copyright &copy; 2012, 2013, 2014 by William Greiman
  23. </CENTER>
  24. \section Intro Introduction
  25. The Arduino %SdFat Library is a minimal implementation of FAT16 and FAT32
  26. file systems on SD flash memory cards. Standard SD and high capacity SDHC
  27. cards are supported.
  28. Experimental support for FAT12 can be enabled by setting FAT12_SUPPORT
  29. nonzero in SdFatConfig.h.
  30. The %SdFat library only supports short 8.3 names.
  31. The main classes in %SdFat are SdFat, SdFile, StdioStream, \ref fstream,
  32. \ref ifstream, and \ref ofstream.
  33. The SdFat class maintains a volume working directories, a current working
  34. directory, and simplifies initialization of other classes.
  35. The SdFile class provides binary file access functions such as open(), read(),
  36. remove(), write(), close() and sync(). This class supports access to the root
  37. directory and subdirectories.
  38. The StdioStream class implements functions similar to Linux/Unix standard
  39. buffered input/output.
  40. The \ref fstream class implements C++ iostreams for both reading and writing
  41. text files.
  42. The \ref ifstream class implements the C++ iostreams for reading text files.
  43. The \ref ofstream class implements the C++ iostreams for writing text files.
  44. The classes \ref ibufstream and \ref obufstream format and parse character
  45. strings in memory buffers.
  46. the classes ArduinoInStream and ArduinoOutStream provide iostream functions
  47. for Serial, LiquidCrystal, and other devices.
  48. The SdVolume class supports FAT16 and FAT32 partitions. Most applications
  49. will not need to call SdVolume member function.
  50. The Sd2Card class supports access to standard SD cards and SDHC cards. Most
  51. applications will not need to call Sd2Card functions. The Sd2Card class can
  52. be used for raw access to the SD card.
  53. A number of example are provided in the %SdFat/examples folder. These were
  54. developed to test %SdFat and illustrate its use.
  55. %SdFat was developed for high speed data recording. %SdFat was used to
  56. implement an audio record/play class, WaveRP, for the Adafruit Wave Shield.
  57. This application uses special Sd2Card calls to write to contiguous files in
  58. raw mode. These functions reduce write latency so that audio can be
  59. recorded with the small amount of RAM in the Arduino.
  60. \section SDcard SD\SDHC Cards
  61. Arduinos access SD cards using the cards SPI protocol. PCs, Macs, and
  62. most consumer devices use the 4-bit parallel SD protocol. A card that
  63. functions well on A PC or Mac may not work well on the Arduino.
  64. Most cards have good SPI read performance but cards vary widely in SPI
  65. write performance. Write performance is limited by how efficiently the
  66. card manages internal erase/remapping operations. The Arduino cannot
  67. optimize writes to reduce erase operations because of its limit RAM.
  68. SanDisk cards generally have good write performance. They seem to have
  69. more internal RAM buffering than other cards and therefore can limit
  70. the number of flash erase operations that the Arduino forces due to its
  71. limited RAM.
  72. \section Hardware Hardware Configuration
  73. %SdFat was developed using an
  74. <A HREF = "http://www.adafruit.com/"> Adafruit Industries</A>
  75. Data Logging Shield.
  76. The hardware interface to the SD card should not use a resistor based level
  77. shifter. %SdFat sets the SPI bus frequency to 8 MHz which results in signal
  78. rise times that are too slow for the edge detectors in many newer SD card
  79. controllers when resistor voltage dividers are used.
  80. The 5 to 3.3 V level shifter for 5 V Arduinos should be IC based like the
  81. 74HC4050N based circuit shown in the file SdLevel.png. The Adafruit Wave Shield
  82. uses a 74AHC125N. Gravitech sells SD and MicroSD Card Adapters based on the
  83. 74LCX245.
  84. If you are using a resistor based level shifter and are having problems try
  85. setting the SPI bus frequency to 4 MHz. This can be done by using
  86. card.init(SPI_HALF_SPEED) to initialize the SD card.
  87. \section comment Bugs and Comments
  88. If you wish to report bugs or have comments, send email to fat16lib@sbcglobal.net.
  89. \section SdFatClass SdFat Usage
  90. %SdFat uses a slightly restricted form of short names.
  91. Only printable ASCII characters are supported. No characters with code point
  92. values greater than 127 are allowed. Space is not allowed even though space
  93. was allowed in the API of early versions of DOS.
  94. Short names are limited to 8 characters followed by an optional period (.)
  95. and extension of up to 3 characters. The characters may be any combination
  96. of letters and digits. The following special characters are also allowed:
  97. $ % ' - _ @ ~ ` ! ( ) { } ^ # &
  98. Short names are always converted to upper case and their original case
  99. value is lost.
  100. \par
  101. An application which writes to a file using print(), println() or
  102. \link SdFile::write write() \endlink must call \link SdFile::sync() sync() \endlink
  103. at the appropriate time to force data and directory information to be written
  104. to the SD Card. Data and directory information are also written to the SD card
  105. when \link SdFile::close() close() \endlink is called.
  106. \par
  107. Applications must use care calling \link SdFile::sync() sync() \endlink
  108. since 2048 bytes of I/O is required to update file and
  109. directory information. This includes writing the current data block, reading
  110. the block that contains the directory entry for update, writing the directory
  111. block back and reading back the current data block.
  112. It is possible to open a file with two or more instances of SdFile. A file may
  113. be corrupted if data is written to the file by more than one instance of SdFile.
  114. \section HowTo How to format SD Cards as FAT Volumes
  115. You should use a freshly formatted SD card for best performance. FAT
  116. file systems become slower if many files have been created and deleted.
  117. This is because the directory entry for a deleted file is marked as deleted,
  118. but is not deleted. When a new file is created, these entries must be scanned
  119. before creating the file, a flaw in the FAT design. Also files can become
  120. fragmented which causes reads and writes to be slower.
  121. A formatter sketch, SdFormatter.pde, is included in the
  122. %SdFat/examples/SdFormatter directory. This sketch attempts to
  123. emulate SD Association's SDFormatter.
  124. The best way to restore an SD card's format on a PC is to use SDFormatter
  125. which can be downloaded from:
  126. http://www.sdcard.org/consumers/formatter/
  127. SDFormatter aligns flash erase boundaries with file
  128. system structures which reduces write latency and file system overhead.
  129. SDFormatter does not have an option for FAT type so it may format
  130. small cards as FAT12.
  131. After the MBR is restored by SDFormatter you may need to reformat small
  132. cards that have been formatted FAT12 to force the volume type to be FAT16.
  133. If you reformat the SD card with an OS utility, choose a cluster size that
  134. will result in:
  135. 4084 < CountOfClusters && CountOfClusters < 65525
  136. The volume will then be FAT16.
  137. If you are formatting an SD card on OS X or Linux, be sure to use the first
  138. partition. Format this partition with a cluster count in above range for FAT16.
  139. SDHC cards should be formatted FAT32 with a cluster size of 32 KB.
  140. Microsoft operating systems support removable media formatted with a
  141. Master Boot Record, MBR, or formatted as a super floppy with a FAT Boot Sector
  142. in block zero.
  143. Microsoft operating systems expect MBR formatted removable media
  144. to have only one partition. The first partition should be used.
  145. Microsoft operating systems do not support partitioning SD flash cards.
  146. If you erase an SD card with a program like KillDisk, Most versions of
  147. Windows will format the card as a super floppy.
  148. \section References References
  149. The Arduino site:
  150. http://www.arduino.cc/
  151. For more information about FAT file systems see:
  152. http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx
  153. For information about using SD cards as SPI devices see:
  154. http://www.sdcard.org/developers/tech/sdcard/pls/Simplified_Physical_Layer_Spec.pdf
  155. The ATmega328 datasheet:
  156. http://www.atmel.com/dyn/resources/prod_documents/doc8161.pdf
  157. */