PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

203 line
8.0KB

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