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.

ExFatFormatter.ino 2.0KB

5 yıl önce
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Force exFAT formatting for all SD cards larger than 512MB.
  2. #include "SdFat.h"
  3. /*
  4. Change the value of SD_CS_PIN if you are using SPI and
  5. your hardware does not use the default value, SS.
  6. Common values are:
  7. Arduino Ethernet shield: pin 4
  8. Sparkfun SD shield: pin 8
  9. Adafruit SD shields and modules: pin 10
  10. */
  11. // SDCARD_SS_PIN is defined for the built-in SD on some boards.
  12. #ifndef SDCARD_SS_PIN
  13. const uint8_t SD_CS_PIN = SS;
  14. #else // SDCARD_SS_PIN
  15. // Assume built-in SD is used.
  16. const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
  17. #endif // SDCARD_SS_PIN
  18. // Select fastest interface.
  19. #if HAS_SDIO_CLASS
  20. // SD config for Teensy 3.6 SDIO.
  21. #define SD_CONFIG SdioConfig(FIFO_SDIO)
  22. //#define SD_CONFIG SdioConfig(DMA_SDIO)
  23. #elif ENABLE_DEDICATED_SPI
  24. #define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI)
  25. #else // HAS_SDIO_CLASS
  26. #define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI)
  27. #endif // HAS_SDIO_CLASS
  28. SdExFat sd;
  29. //------------------------------------------------------------------------------
  30. void errorHalt() {
  31. sd.printSdError(&Serial);
  32. SysCall::halt();
  33. }
  34. #define error(s) (Serial.println(F(s)),errorHalt())
  35. //------------------------------------------------------------------------------
  36. void setup() {
  37. Serial.begin(9600);
  38. while (!Serial) {}
  39. Serial.println(F("Type any character to begin"));
  40. while (!Serial.available()) {
  41. yield();
  42. }
  43. do {
  44. delay(10);
  45. } while(Serial.read() >= 0);
  46. Serial.println();
  47. Serial.println(F(
  48. "Your SD will be formated exFAT.\r\n"
  49. "All data on the SD will be lost.\r\n"
  50. "Type 'Y' to continue.\r\n"));
  51. while (!Serial.available()) {
  52. yield();
  53. }
  54. if (Serial.read() != 'Y') {
  55. Serial.println(F("Exiting, 'Y' not typed."));
  56. return;
  57. }
  58. if (!sd.cardBegin(SD_CONFIG)) {
  59. error("cardBegin failed");
  60. }
  61. if(!sd.format(&Serial)) {
  62. error("format failed");
  63. }
  64. if (!sd.volumeBegin()) {
  65. error("volumeBegin failed");
  66. }
  67. Serial.print(F("Bytes per cluster: "));
  68. Serial.println(sd.bytesPerCluster());
  69. Serial.println(F("Done"));
  70. }
  71. void loop() {
  72. }