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.
79 lines
2.0 KiB
79 lines
2.0 KiB
5 years ago
|
// Force exFAT formatting for all SD cards larger than 512MB.
|
||
|
#include "SdFs.h"
|
||
|
|
||
|
/*
|
||
|
Change the value of SD_CS_PIN if you are using SPI and
|
||
|
your hardware does not use the default value, SS.
|
||
|
Common values are:
|
||
|
Arduino Ethernet shield: pin 4
|
||
|
Sparkfun SD shield: pin 8
|
||
|
Adafruit SD shields and modules: pin 10
|
||
|
*/
|
||
|
|
||
|
// SDCARD_SS_PIN is defined for the built-in SD on some boards.
|
||
|
#ifndef SDCARD_SS_PIN
|
||
|
const uint8_t SD_CS_PIN = SS;
|
||
|
#else // SDCARD_SS_PIN
|
||
|
// Assume built-in SD is used.
|
||
|
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||
|
#endif // SDCARD_SS_PIN
|
||
|
|
||
|
// Select fastest interface.
|
||
|
#if HAS_SDIO_CLASS
|
||
|
// SD config for Teensy 3.6 SDIO.
|
||
|
#define SD_CONFIG SdioConfig(FIFO_SDIO)
|
||
|
//#define SD_CONFIG SdioConfig(DMA_SDIO)
|
||
|
#elif ENABLE_DEDICATED_SPI
|
||
|
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI)
|
||
|
#else // HAS_SDIO_CLASS
|
||
|
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI)
|
||
|
#endif // HAS_SDIO_CLASS
|
||
|
|
||
|
SdExFat sd;
|
||
|
//------------------------------------------------------------------------------
|
||
|
void errorHalt() {
|
||
|
sd.printSdError(&Serial);
|
||
|
SysCall::halt();
|
||
|
}
|
||
|
#define error(s) (Serial.println(F(s)),errorHalt())
|
||
|
//------------------------------------------------------------------------------
|
||
|
void setup() {
|
||
|
Serial.begin(9600);
|
||
|
while (!Serial) {}
|
||
|
Serial.println(F("Type any character to begin"));
|
||
|
|
||
|
while (!Serial.available()) {
|
||
|
yield();
|
||
|
}
|
||
|
do {
|
||
|
delay(10);
|
||
|
} while(Serial.read() >= 0);
|
||
|
|
||
|
Serial.println();
|
||
|
Serial.println(F(
|
||
|
"Your SD will be formated exFAT.\r\n"
|
||
|
"All data on the SD will be lost.\r\n"
|
||
|
"Type 'Y' to continue.\r\n"));
|
||
|
|
||
|
while (!Serial.available()) {
|
||
|
yield();
|
||
|
}
|
||
|
if (Serial.read() != 'Y') {
|
||
|
Serial.println(F("Exiting, 'Y' not typed."));
|
||
|
return;
|
||
|
}
|
||
|
if (!sd.cardBegin(SD_CONFIG)) {
|
||
|
error("cardBegin failed");
|
||
|
}
|
||
|
if(!sd.format(&Serial)) {
|
||
|
error("format failed");
|
||
|
}
|
||
|
if (!sd.volumeBegin()) {
|
||
|
error("volumeBegin failed");
|
||
|
}
|
||
|
Serial.print(F("Bytes per cluster: "));
|
||
|
Serial.println(sd.bytesPerCluster());
|
||
|
Serial.println(F("Done"));
|
||
|
}
|
||
|
void loop() {
|
||
|
}
|