Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

5 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /**
  2. * Copyright (c) 2011-2019 Bill Greiman
  3. * This file is part of the SdFat library for SD memory cards.
  4. *
  5. * MIT License
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. /**
  26. \mainpage Arduino %SdFat Library
  27. \section Warn Warnings for SdFat V2 Alpha/Beta
  28. This is a development version of SdFat V2 and any feature may change. There
  29. are bound to be serious bugs, and stability/compatibility problems.
  30. Initially this is closer to an alpha test so expect stability problems.
  31. You can help by posting issues for bugs you find. I am doing a great deal
  32. of testing but actual applications make the best test cases.
  33. Please try to isolate the bug and post code that demonstrates the bug.
  34. The purpose of this release is to get feedback on features and address
  35. compatibility problems.
  36. You should edit SdFatConfig.h to select features. SdFatConfig.h is suitable
  37. for UNO and other small AVR boards.
  38. \section Intro Introduction
  39. The Arduino %SdFat library supports FAT16, FAT32, and exFAT file systems
  40. on Standard SD, SDHC, and SDXC cards.
  41. In %SdFat version 1, SdFat and File are the main classes.
  42. In %SdFat version 2, SdFat and File are defined by typedefs in terms of the
  43. following classes.
  44. The file system classes in the %SdFat library are SdFat32, SdExFat, and SdFs.
  45. SdFat32 supports FAT16 and FAT32. SdExFat supports exFAT, SdFs supports
  46. FAT16, FAT32, and exFAT.
  47. The corresponding file classes are File32, ExFile, and FsFile.
  48. The types for SdFat and File are defined in SdFatConfig.h. This version
  49. uses FAT16/FAT32 for small AVR boards and FAT16/FAT32/exFAT for all other
  50. boards.
  51. \code{.cpp}
  52. // File types for SdFat, File, SdFile, SdBaseFile, fstream,
  53. // ifstream, and ofstream.
  54. //
  55. // Set SDFAT_FILE_TYPE to:
  56. // 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
  57. //
  58. #if defined(__AVR__) && FLASHEND < 0X8000
  59. // FAT16/FAT32 for 32K AVR boards.
  60. #define SDFAT_FILE_TYPE 1
  61. #else // defined(__AVR__) && FLASHEND < 0X8000
  62. // FAT16/FAT32 and exFAT for all other boards.
  63. #define SDFAT_FILE_TYPE 3
  64. #endif // defined(__AVR__) && FLASHEND < 0X8000
  65. \endcode
  66. It is possible to use option three, support or FAT16/FAT32 and exFat
  67. on an Uno or other AVR board with 32KB flash and 2KB SRAM but memory
  68. will be very limited.
  69. Uno memory use for a simple data logger is:
  70. > option 1, FAT16/FAT32, 11902 bytes of flash and 855 bytes of SRAM.
  71. >
  72. > option 2, exFAT, 14942 bytes of flash and 895 bytes of SRAM.
  73. >
  74. > option 3, FAT16/FAT32 and exFAT, 21834 bytes of flash and 908 bytes of SRAM.
  75. Please read documentation under the above classes tab for more information.
  76. A number of example are provided in the %SdFat/examples folder. These were
  77. developed to test %SdFat and illustrate its use.
  78. \section exFAT exFAT Features
  79. exFAT has many features not available in FAT16/FAT32.
  80. Files larger than 4GiB, 64-bit file size and file position.
  81. Free space allocation performance improved by using a free space bitmap.
  82. Removal of the physical "." and ".." directory entries that appear in
  83. FAT16/FAT32 subdirectories.
  84. Better support for large flash pages with boundary alignment offsets
  85. for the FAT table and data region.
  86. exFAT files have two separate 64-bit length fields. The DataLength
  87. field indicate how much space is allocate to the file. The ValidDataLength
  88. field indicates how much actual data has been written to the file.
  89. An exFAT file can be contiguous with pre-allocate clusters and bypass the
  90. use of the FAT table. In this case the contiguous flag is set in the
  91. directory entry. This allows an entire file to be written as one large
  92. multi-block write.
  93. \section SDPath Paths and Working Directories
  94. Relative paths in %SdFat are resolved in a manner similar to Windows.
  95. Each instance of SdFat32, SdExFat, and SdFs has a current directory.
  96. This directory is called the volume working directory, vwd.
  97. Initially this directory is the root directory for the volume.
  98. The volume working directory is changed by calling the chdir(path).
  99. The call sd.chdir("/2014") will change the volume working directory
  100. for sd to "/2014", assuming "/2014" exists.
  101. Relative paths for member functions are resolved by starting at
  102. the volume working directory.
  103. For example, the call sd.mkdir("April") will create the directory
  104. "/2014/April" assuming the volume working directory is "/2014".
  105. There is current working directory, cwd, that is used to resolve paths
  106. for file.open() calls.
  107. For a single SD card, the current working directory is always the volume
  108. working directory for that card.
  109. For multiple SD cards the current working directory is set to the volume
  110. working directory of a card by calling the chvol() member function.
  111. The chvol() call is like the Windows \<drive letter>: command.
  112. The call sd2.chvol() will set the current working directory to the volume
  113. working directory for sd2.
  114. If the volume working directory for sd2 is "/music" the call
  115. file.open("BigBand.wav", O_READ);
  116. will open "/music/BigBand.wav" on sd2.
  117. \section Install Installation
  118. You must manually install %SdFat by renaming the download folder %SdFat
  119. and copy the %SdFat folder to the Arduino libraries folder in your
  120. sketchbook folder.
  121. It will be necessary to unzip and rename the folder if you download a zip
  122. file from GitHub.
  123. See the Manual installation section of this guide.
  124. http://arduino.cc/en/Guide/Libraries
  125. \section SDconfig SdFat Configuration
  126. Several configuration options may be changed by editing the SdFatConfig.h
  127. file in the %SdFat/src folder.
  128. Here are a few of the key options.
  129. If the symbol ENABLE_DEDICATED_SPI is nonzero, multi-block SD I/O may
  130. be used for better performance. The SPI bus may not be shared with
  131. other devices in this mode.
  132. The symbol SPI_DRIVER_SELECT is used to select the SPI driver.
  133. > If the symbol SPI_DRIVER_SELECT is:
  134. >
  135. > 0 - An optimized custom SPI driver is used if it exists
  136. > else the standard library driver is used.
  137. >
  138. > 1 - The standard library driver is always used.
  139. >
  140. > 2 - The software SPI driver is always used.
  141. To enable SD card CRC checking in SPI mode set USE_SD_CRC nonzero.
  142. See SdFatConfig.h for other options.
  143. \section Hardware Hardware Configuration
  144. The hardware interface to the SD card should not use a resistor based level
  145. shifter. Resistor based level shifters results in signal rise times that are
  146. too slow for many newer SD cards.
  147. \section HowTo How to format SD Cards as FAT Volumes
  148. The best way to restore an SD card's format on a PC or Mac is to use
  149. SDFormatter which can be downloaded from:
  150. http://www.sdcard.org/downloads
  151. A formatter program, SdFormatter.ino, is included in the
  152. %SdFat/examples/SdFormatter directory. This program attempts to
  153. emulate SD Association's SDFormatter.
  154. SDFormatter aligns flash erase boundaries with file
  155. system structures which reduces write latency and file system overhead.
  156. The PC/Mac SDFormatter does not have an option for FAT type so it may format
  157. very small cards as FAT12. Use the %SdFormatter example to force FAT16
  158. formatting of small cards.
  159. Do not format the SD card with an OS utility, OS utilities do not format SD
  160. cards in conformance with the SD standard.
  161. You should use a freshly formatted SD card for best performance. FAT
  162. file systems become slower if many files have been created and deleted.
  163. This is because the directory entry for a deleted file is marked as deleted,
  164. but is not deleted. When a new file is created, these entries must be scanned
  165. before creating the file. Also files can become
  166. fragmented which causes reads and writes to be slower.
  167. \section ExampleFiles Examples
  168. A number of examples are provided in the SdFat/examples folder.
  169. To access these examples from the Arduino development environment
  170. go to: %File -> Examples -> %SdFat -> \<program Name\>
  171. Compile, upload to your Arduino and click on Serial Monitor to run
  172. the example.
  173. Here is a list:
  174. AvrAdcLogger - Fast AVR ADC logger using Timer/ADC interrupts.
  175. BackwardCompatibility - Demonstrate SD.h compatibility with %SdFat.h.
  176. bench - A read/write benchmark.
  177. BufferedPrint - Demo a buffered print class for AVR loggers.
  178. debug folder - Some of my debug programs - will be remove in the future.
  179. DirectoryFunctions - Use of chdir(), ls(), mkdir(), and rmdir().
  180. examplesV1 folder - Examples from SdFat V1 for compatibility tests.
  181. %ExFatFormatter - Produces optimal exFAT format for smaller SD cards.
  182. ExFatLogger - A data-logger optimized for exFAT features.
  183. ExFatUnicodeTest - Test program for Unicode file names.
  184. OpenNext - Open all files in the root dir and print their filename.
  185. ReadCsvFile - Function to read a CSV text file one field at a time.
  186. RtcTimestampTest - Demonstration of timestamps with RTClib.
  187. SdErrorCodes - Produce a list of error codes.
  188. SdFormatter - This program will format an SD, SDHC, or SDXC card.
  189. SdInfo - Initialize an SD card and analyze its structure for trouble shooting.
  190. SoftwareSpi - Demo of limited Software SPI support in SdFat V2.
  191. STM32Test - Example use of two SPI ports on an STM32 board.
  192. TeensyRtcTimestamp - %File timestamps for Teensy3.
  193. TeensySdioDemo - Demo of SDIO and SPI modes for the Teensy 3.5/3.6 built-in SD.
  194. */