This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
// 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
|
||||
#else // SDCARD_SS_PIN
|
||||
// Assume built-in SD is used.
|
||||
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
#endif // SDCARD_SS_PIN
|
||||
@@ -30,7 +30,7 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
// Try to select the best SD card configuration.
|
||||
#if HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdioConfig(FIFO_SDIO)
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
|
||||
#else // HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
|
||||
@@ -78,9 +78,8 @@ void setup() {
|
||||
if (!sd.begin(SD_CONFIG)) {
|
||||
sd.initErrorHalt(&Serial);
|
||||
}
|
||||
if (sd.exists("Folder1")
|
||||
|| sd.exists("Folder1/file1.txt")
|
||||
|| sd.exists("Folder1/File2.txt")) {
|
||||
if (sd.exists("Folder1") || sd.exists("Folder1/file1.txt") ||
|
||||
sd.exists("Folder1/File2.txt")) {
|
||||
error("Please remove existing Folder1, file1.txt, and File2.txt");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
// 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
|
||||
#else // SDCARD_SS_PIN
|
||||
// Assume built-in SD is used.
|
||||
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
#endif // SDCARD_SS_PIN
|
||||
@@ -29,7 +29,7 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
// Try to select the best SD card configuration.
|
||||
#if HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdioConfig(FIFO_SDIO)
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
|
||||
#else // HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
|
||||
@@ -76,7 +76,7 @@ void setup() {
|
||||
sd.initErrorHalt(&Serial);
|
||||
}
|
||||
// Open root directory
|
||||
if (!dir.open("/")){
|
||||
if (!dir.open("/")) {
|
||||
error("dir.open failed");
|
||||
}
|
||||
// Open next file in root.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Quick hardware test for SPI card access.
|
||||
//
|
||||
#include <SPI.h>
|
||||
|
||||
#include "SdFat.h"
|
||||
#include "sdios.h"
|
||||
|
||||
@@ -81,17 +82,17 @@ void setup() {
|
||||
|
||||
if (DISABLE_CHIP_SELECT < 0) {
|
||||
cout << F(
|
||||
"\nBe sure to edit DISABLE_CHIP_SELECT if you have\n"
|
||||
"a second SPI device. For example, with the Ethernet\n"
|
||||
"shield, DISABLE_CHIP_SELECT should be set to 10\n"
|
||||
"to disable the Ethernet controller.\n");
|
||||
"\nBe sure to edit DISABLE_CHIP_SELECT if you have\n"
|
||||
"a second SPI device. For example, with the Ethernet\n"
|
||||
"shield, DISABLE_CHIP_SELECT should be set to 10\n"
|
||||
"to disable the Ethernet controller.\n");
|
||||
}
|
||||
cout << F(
|
||||
"\nSD chip select is the key hardware option.\n"
|
||||
"Common values are:\n"
|
||||
"Arduino Ethernet shield, pin 4\n"
|
||||
"Sparkfun SD shield, pin 8\n"
|
||||
"Adafruit SD shields and modules, pin 10\n");
|
||||
"\nSD chip select is the key hardware option.\n"
|
||||
"Common values are:\n"
|
||||
"Arduino Ethernet shield, pin 4\n"
|
||||
"Sparkfun SD shield, pin 8\n"
|
||||
"Adafruit SD shields and modules, pin 10\n");
|
||||
}
|
||||
|
||||
bool firstTry = true;
|
||||
@@ -117,8 +118,8 @@ void loop() {
|
||||
}
|
||||
if (DISABLE_CHIP_SELECT < 0) {
|
||||
cout << F(
|
||||
"\nAssuming the SD is the only SPI device.\n"
|
||||
"Edit DISABLE_CHIP_SELECT to disable another device.\n");
|
||||
"\nAssuming the SD is the only SPI device.\n"
|
||||
"Edit DISABLE_CHIP_SELECT to disable another device.\n");
|
||||
} else {
|
||||
cout << F("\nDisabling SPI device on pin ");
|
||||
cout << int(DISABLE_CHIP_SELECT) << endl;
|
||||
@@ -128,12 +129,12 @@ void loop() {
|
||||
if (!sd.begin(chipSelect, SPI_SPEED)) {
|
||||
if (sd.card()->errorCode()) {
|
||||
cout << F(
|
||||
"\nSD initialization failed.\n"
|
||||
"Do not reformat the card!\n"
|
||||
"Is the card correctly inserted?\n"
|
||||
"Is chipSelect set to the correct value?\n"
|
||||
"Does another SPI device need to be disabled?\n"
|
||||
"Is there a wiring/soldering problem?\n");
|
||||
"\nSD initialization failed.\n"
|
||||
"Do not reformat the card!\n"
|
||||
"Is the card correctly inserted?\n"
|
||||
"Is chipSelect set to the correct value?\n"
|
||||
"Does another SPI device need to be disabled?\n"
|
||||
"Is there a wiring/soldering problem?\n");
|
||||
cout << F("\nerrorCode: ") << hex << showbase;
|
||||
cout << int(sd.card()->errorCode());
|
||||
cout << F(", errorData: ") << int(sd.card()->errorData());
|
||||
@@ -169,8 +170,8 @@ void loop() {
|
||||
cout << F("Files found (date time size name):\n");
|
||||
sd.ls(LS_R | LS_DATE | LS_SIZE);
|
||||
|
||||
if ((sizeMB > 1100 && sd.vol()->sectorsPerCluster() < 64)
|
||||
|| (sizeMB < 2200 && sd.vol()->fatType() == 32)) {
|
||||
if ((sizeMB > 1100 && sd.vol()->sectorsPerCluster() < 64) ||
|
||||
(sizeMB < 2200 && sd.vol()->fatType() == 32)) {
|
||||
cout << F("\nThis card should be reformatted for best performance.\n");
|
||||
cout << F("Use a cluster size of 32 KB for cards larger than 1 GB.\n");
|
||||
cout << F("Only cards larger than 2 GB should be formatted FAT32.\n");
|
||||
|
||||
@@ -31,7 +31,7 @@ const int8_t DISABLE_CS_PIN = -1;
|
||||
// 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
|
||||
#else // SDCARD_SS_PIN
|
||||
// Assume built-in SD is used.
|
||||
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
#endif // SDCARD_SS_PIN
|
||||
@@ -42,7 +42,7 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
// Try to select the best SD card configuration.
|
||||
#if HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdioConfig(FIFO_SDIO)
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
|
||||
#else // HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
|
||||
@@ -52,14 +52,18 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
ArduinoOutStream cout(Serial);
|
||||
//------------------------------------------------------------------------------
|
||||
uint32_t cardSectorCount = 0;
|
||||
uint8_t sectorBuffer[512];
|
||||
uint8_t sectorBuffer[512];
|
||||
//------------------------------------------------------------------------------
|
||||
// SdCardFactory constructs and initializes the appropriate card.
|
||||
SdCardFactory cardFactory;
|
||||
// Pointer to generic SD card.
|
||||
SdCard* m_card = nullptr;
|
||||
//------------------------------------------------------------------------------
|
||||
#define sdError(msg) {cout << F("error: ") << F(msg) << endl; sdErrorHalt();}
|
||||
#define sdError(msg) \
|
||||
{ \
|
||||
cout << F("error: ") << F(msg) << endl; \
|
||||
sdErrorHalt(); \
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void sdErrorHalt() {
|
||||
if (!m_card) {
|
||||
@@ -73,7 +77,8 @@ void sdErrorHalt() {
|
||||
cout << F(" = ") << int(m_card->errorCode()) << endl;
|
||||
cout << F("SD errorData = ") << int(m_card->errorData()) << endl;
|
||||
}
|
||||
while (true) {}
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void clearSerialInput() {
|
||||
@@ -102,7 +107,7 @@ void eraseCard() {
|
||||
sdError("erase failed");
|
||||
}
|
||||
cout << '.';
|
||||
if ((n++)%64 == 63) {
|
||||
if ((n++) % 64 == 63) {
|
||||
cout << endl;
|
||||
}
|
||||
firstBlock += ERASE_SIZE;
|
||||
@@ -123,9 +128,9 @@ void formatCard() {
|
||||
FatFormatter fatFormatter;
|
||||
|
||||
// Format exFAT if larger than 32GB.
|
||||
bool rtn = cardSectorCount > 67108864 ?
|
||||
exFatFormatter.format(m_card, sectorBuffer, &Serial) :
|
||||
fatFormatter.format(m_card, sectorBuffer, &Serial);
|
||||
bool rtn = cardSectorCount > 67108864
|
||||
? exFatFormatter.format(m_card, sectorBuffer, &Serial)
|
||||
: fatFormatter.format(m_card, sectorBuffer, &Serial);
|
||||
|
||||
if (!rtn) {
|
||||
sdErrorHalt();
|
||||
@@ -136,8 +141,8 @@ void formatCard() {
|
||||
void printConfig(SdSpiConfig config) {
|
||||
if (DISABLE_CS_PIN < 0) {
|
||||
cout << F(
|
||||
"\nAssuming the SD is the only SPI device.\n"
|
||||
"Edit DISABLE_CS_PIN to disable an SPI device.\n");
|
||||
"\nAssuming the SD is the only SPI device.\n"
|
||||
"Edit DISABLE_CS_PIN to disable an SPI device.\n");
|
||||
} else {
|
||||
cout << F("\nDisabling SPI device on pin ");
|
||||
cout << int(DISABLE_CS_PIN) << endl;
|
||||
@@ -169,19 +174,19 @@ void setup() {
|
||||
clearSerialInput();
|
||||
|
||||
cout << F(
|
||||
"\n"
|
||||
"This program can erase and/or format SD/SDHC/SDXC cards.\n"
|
||||
"\n"
|
||||
"Erase uses the card's fast flash erase command.\n"
|
||||
"Flash erase sets all data to 0X00 for most cards\n"
|
||||
"and 0XFF for a few vendor's cards.\n"
|
||||
"\n"
|
||||
"Cards up to 2 GiB (GiB = 2^30 bytes) will be formated FAT16.\n"
|
||||
"Cards larger than 2 GiB and up to 32 GiB will be formatted\n"
|
||||
"FAT32. Cards larger than 32 GiB will be formatted exFAT.\n"
|
||||
"\n"
|
||||
"Warning, all data on the card will be erased.\n"
|
||||
"Enter 'Y' to continue: ");
|
||||
"\n"
|
||||
"This program can erase and/or format SD/SDHC/SDXC cards.\n"
|
||||
"\n"
|
||||
"Erase uses the card's fast flash erase command.\n"
|
||||
"Flash erase sets all data to 0X00 for most cards\n"
|
||||
"and 0XFF for a few vendor's cards.\n"
|
||||
"\n"
|
||||
"Cards up to 2 GiB (GiB = 2^30 bytes) will be formated FAT16.\n"
|
||||
"Cards larger than 2 GiB and up to 32 GiB will be formatted\n"
|
||||
"FAT32. Cards larger than 32 GiB will be formatted exFAT.\n"
|
||||
"\n"
|
||||
"Warning, all data on the card will be erased.\n"
|
||||
"Enter 'Y' to continue: ");
|
||||
while (!Serial.available()) {
|
||||
yield();
|
||||
}
|
||||
@@ -207,9 +212,9 @@ void setup() {
|
||||
return;
|
||||
}
|
||||
|
||||
cout << F("\nCard size: ") << cardSectorCount*5.12e-7;
|
||||
cout << F("\nCard size: ") << cardSectorCount * 5.12e-7;
|
||||
cout << F(" GB (GB = 1E9 bytes)\n");
|
||||
cout << F("Card size: ") << cardSectorCount/2097152.0;
|
||||
cout << F("Card size: ") << cardSectorCount / 2097152.0;
|
||||
cout << F(" GiB (GiB = 2^30 bytes)\n");
|
||||
|
||||
cout << F("Card will be formated ");
|
||||
@@ -221,13 +226,13 @@ void setup() {
|
||||
cout << F("FAT16\n");
|
||||
}
|
||||
cout << F(
|
||||
"\n"
|
||||
"Options are:\n"
|
||||
"E - erase the card and skip formatting.\n"
|
||||
"F - erase and then format the card. (recommended)\n"
|
||||
"Q - quick format the card without erase.\n"
|
||||
"\n"
|
||||
"Enter option: ");
|
||||
"\n"
|
||||
"Options are:\n"
|
||||
"E - erase the card and skip formatting.\n"
|
||||
"F - erase and then format the card. (recommended)\n"
|
||||
"Q - quick format the card without erase.\n"
|
||||
"\n"
|
||||
"Enter option: ");
|
||||
|
||||
while (!Serial.available()) {
|
||||
yield();
|
||||
@@ -245,5 +250,4 @@ void setup() {
|
||||
formatCard();
|
||||
}
|
||||
}
|
||||
void loop() {
|
||||
}
|
||||
void loop() {}
|
||||
@@ -20,7 +20,7 @@ const int8_t DISABLE_CS_PIN = -1;
|
||||
// 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
|
||||
#else // SDCARD_SS_PIN
|
||||
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
#endif // SDCARD_SS_PIN
|
||||
|
||||
@@ -99,7 +99,7 @@ void errorPrint() {
|
||||
bool mbrDmp() {
|
||||
MbrSector_t mbr;
|
||||
bool valid = true;
|
||||
if (!sd.card()->readSector(0, (uint8_t*)&mbr)) {
|
||||
if (!sd.card()->readSector(0, (uint8_t *)&mbr)) {
|
||||
cout << F("\nread MBR failed.\n");
|
||||
errorPrint();
|
||||
return false;
|
||||
@@ -114,11 +114,11 @@ bool mbrDmp() {
|
||||
}
|
||||
cout << int(ip) << ',' << uppercase << showbase << hex;
|
||||
cout << int(pt->boot) << ',';
|
||||
for (int i = 0; i < 3; i++ ) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
cout << int(pt->beginCHS[i]) << ',';
|
||||
}
|
||||
cout << int(pt->type) << ',';
|
||||
for (int i = 0; i < 3; i++ ) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
cout << int(pt->endCHS[i]) << ',';
|
||||
}
|
||||
cout << dec << getLe32(pt->relativeSectors) << ',';
|
||||
@@ -141,18 +141,17 @@ void dmpVol() {
|
||||
cout << F("sectorsPerCluster: ") << sd.sectorsPerCluster() << endl;
|
||||
cout << F("fatStartSector: ") << sd.fatStartSector() << endl;
|
||||
cout << F("dataStartSector: ") << sd.dataStartSector() << endl;
|
||||
cout << F("clusterCount: ") << sd.clusterCount() << endl;
|
||||
cout << F("clusterCount: ") << sd.clusterCount() << endl;
|
||||
cout << F("freeClusterCount: ");
|
||||
if (freeClusterCount >= 0) {
|
||||
cout << freeClusterCount << endl;
|
||||
} else {
|
||||
cout << F("failed\n");
|
||||
errorPrint();
|
||||
errorPrint();
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void printCardType() {
|
||||
|
||||
cout << F("\nCard type: ");
|
||||
|
||||
switch (sd.card()->type()) {
|
||||
@@ -180,8 +179,8 @@ void printCardType() {
|
||||
void printConfig(SdSpiConfig config) {
|
||||
if (DISABLE_CS_PIN < 0) {
|
||||
cout << F(
|
||||
"\nAssuming the SD is the only SPI device.\n"
|
||||
"Edit DISABLE_CS_PIN to disable an SPI device.\n");
|
||||
"\nAssuming the SD is the only SPI device.\n"
|
||||
"Edit DISABLE_CS_PIN to disable an SPI device.\n");
|
||||
} else {
|
||||
cout << F("\nDisabling SPI device on pin ");
|
||||
cout << int(DISABLE_CS_PIN) << endl;
|
||||
@@ -205,7 +204,6 @@ void setup() {
|
||||
}
|
||||
cout << F("SdFat version: ") << SD_FAT_VERSION_STR << endl;
|
||||
printConfig(SD_CONFIG);
|
||||
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {
|
||||
@@ -220,15 +218,14 @@ void loop() {
|
||||
uint32_t t = millis();
|
||||
if (!sd.cardBegin(SD_CONFIG)) {
|
||||
cout << F(
|
||||
"\nSD initialization failed.\n"
|
||||
"Do not reformat the card!\n"
|
||||
"Is the card correctly inserted?\n"
|
||||
"Is there a wiring/soldering problem?\n");
|
||||
"\nSD initialization failed.\n"
|
||||
"Do not reformat the card!\n"
|
||||
"Is the card correctly inserted?\n"
|
||||
"Is there a wiring/soldering problem?\n");
|
||||
if (isSpi(SD_CONFIG)) {
|
||||
cout << F(
|
||||
"Is SD_CS_PIN set to the correct value?\n"
|
||||
"Does another SPI device need to be disabled?\n"
|
||||
);
|
||||
"Is SD_CS_PIN set to the correct value?\n"
|
||||
"Does another SPI device need to be disabled?\n");
|
||||
}
|
||||
errorPrint();
|
||||
return;
|
||||
@@ -236,23 +233,21 @@ void loop() {
|
||||
t = millis() - t;
|
||||
cout << F("init time: ") << dec << t << " ms" << endl;
|
||||
|
||||
if (!sd.card()->readCID(&cid) ||
|
||||
!sd.card()->readCSD(&csd) ||
|
||||
!sd.card()->readOCR(&ocr) ||
|
||||
!sd.card()->readSCR(&scr)) {
|
||||
if (!sd.card()->readCID(&cid) || !sd.card()->readCSD(&csd) ||
|
||||
!sd.card()->readOCR(&ocr) || !sd.card()->readSCR(&scr)) {
|
||||
cout << F("readInfo failed\n");
|
||||
errorPrint();
|
||||
return;
|
||||
}
|
||||
printCardType();
|
||||
cout << F("sdSpecVer: ") << 0.01*scr.sdSpecVer() << endl;
|
||||
cout << F("sdSpecVer: ") << 0.01 * scr.sdSpecVer() << endl;
|
||||
cout << F("HighSpeedMode: ");
|
||||
if (scr.sdSpecVer() &&
|
||||
sd.card()->cardCMD6(0X00FFFFFF, cmd6Data) && (2 & cmd6Data[13])) {
|
||||
if (scr.sdSpecVer() && sd.card()->cardCMD6(0X00FFFFFF, cmd6Data) &&
|
||||
(2 & cmd6Data[13])) {
|
||||
cout << F("true\n");
|
||||
} else {
|
||||
cout << F("false\n");
|
||||
}
|
||||
}
|
||||
cidDmp();
|
||||
csdDmp();
|
||||
cout << F("\nOCR: ") << uppercase << showbase;
|
||||
|
||||
@@ -16,7 +16,7 @@ const uint8_t SD_CS_PIN = 10;
|
||||
// Pin numbers in templates must be constants.
|
||||
const uint8_t SOFT_MISO_PIN = 12;
|
||||
const uint8_t SOFT_MOSI_PIN = 11;
|
||||
const uint8_t SOFT_SCK_PIN = 13;
|
||||
const uint8_t SOFT_SCK_PIN = 13;
|
||||
|
||||
// SdFat software SPI template
|
||||
SoftSpiDriver<SOFT_MISO_PIN, SOFT_MOSI_PIN, SOFT_SCK_PIN> softSpi;
|
||||
@@ -77,4 +77,4 @@ void setup() {
|
||||
void loop() {}
|
||||
#else // SPI_DRIVER_SELECT
|
||||
#error SPI_DRIVER_SELECT must be two in SdFat/SdFatConfig.h
|
||||
#endif //SPI_DRIVER_SELECT
|
||||
#endif // SPI_DRIVER_SELECT
|
||||
@@ -7,7 +7,7 @@
|
||||
// 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
|
||||
#else // SDCARD_SS_PIN
|
||||
// Assume built-in SD is used.
|
||||
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
#endif // SDCARD_SS_PIN
|
||||
@@ -20,7 +20,7 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
const size_t BUF_DIM = 32768;
|
||||
|
||||
// 8 MiB file.
|
||||
const uint32_t FILE_SIZE = 256UL*BUF_DIM;
|
||||
const uint32_t FILE_SIZE = 256UL * BUF_DIM;
|
||||
|
||||
#if SD_FAT_TYPE == 0
|
||||
SdFat sd;
|
||||
@@ -72,13 +72,12 @@ void errorHalt(const char* msg) {
|
||||
Serial.print(", ErrorData: 0X");
|
||||
Serial.println(sd.sdErrorData(), HEX);
|
||||
}
|
||||
while (true) {}
|
||||
while (true) {
|
||||
}
|
||||
}
|
||||
bool ready = false;
|
||||
//------------------------------------------------------------------------------
|
||||
bool sdBusy() {
|
||||
return ready ? sd.card()->isBusy() : false;
|
||||
}
|
||||
bool sdBusy() { return ready ? sd.card()->isBusy() : false; }
|
||||
//------------------------------------------------------------------------------
|
||||
// Replace "weak" system yield() function.
|
||||
void yield() {
|
||||
@@ -110,7 +109,7 @@ void runTest() {
|
||||
Serial.println("\nsize,write,read");
|
||||
Serial.println("bytes,KB/sec,KB/sec");
|
||||
for (size_t nb = 512; nb <= BUF_DIM; nb *= 2) {
|
||||
uint32_t nRdWr = FILE_SIZE/nb;
|
||||
uint32_t nRdWr = FILE_SIZE / nb;
|
||||
if (!file.truncate(0)) {
|
||||
errorHalt("truncate failed");
|
||||
}
|
||||
@@ -121,14 +120,14 @@ void runTest() {
|
||||
for (uint32_t n = 0; n < nRdWr; n++) {
|
||||
// Set start and end of buffer.
|
||||
buf32[0] = n;
|
||||
buf32[nb/4 - 1] = n;
|
||||
buf32[nb / 4 - 1] = n;
|
||||
if (nb != file.write(buf, nb)) {
|
||||
errorHalt("write failed");
|
||||
}
|
||||
}
|
||||
t = micros() - t;
|
||||
totalMicros += t;
|
||||
Serial.print(1000.0*FILE_SIZE/t);
|
||||
Serial.print(1000.0 * FILE_SIZE / t);
|
||||
Serial.print(',');
|
||||
file.rewind();
|
||||
t = micros();
|
||||
@@ -138,13 +137,13 @@ void runTest() {
|
||||
errorHalt("read failed");
|
||||
}
|
||||
// crude check of data.
|
||||
if (buf32[0] != n || buf32[nb/4 - 1] != n) {
|
||||
if (buf32[0] != n || buf32[nb / 4 - 1] != n) {
|
||||
errorHalt("data check");
|
||||
}
|
||||
}
|
||||
t = micros() - t;
|
||||
totalMicros += t;
|
||||
Serial.println(1000.0*FILE_SIZE/t);
|
||||
Serial.println(1000.0 * FILE_SIZE / t);
|
||||
}
|
||||
file.close();
|
||||
Serial.print("\ntotalMicros ");
|
||||
@@ -155,8 +154,8 @@ void runTest() {
|
||||
Serial.println(yieldCalls);
|
||||
Serial.print("yieldMaxUsec ");
|
||||
Serial.println(yieldMaxUsec);
|
||||
// Serial.print("kHzSdClk ");
|
||||
// Serial.println(kHzSdClk());
|
||||
// Serial.print("kHzSdClk ");
|
||||
// Serial.println(kHzSdClk());
|
||||
Serial.println("Done");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -171,22 +170,22 @@ void loop() {
|
||||
if (warn) {
|
||||
warn = false;
|
||||
Serial.println(
|
||||
"SD cards must be power cycled to leave\n"
|
||||
"SPI mode so do SDIO tests first.\n"
|
||||
"\nCycle power on the card if an error occurs.");
|
||||
"SD cards must be power cycled to leave\n"
|
||||
"SPI mode so do SDIO tests first.\n"
|
||||
"\nCycle power on the card if an error occurs.");
|
||||
}
|
||||
clearSerialInput();
|
||||
|
||||
Serial.println(
|
||||
"\nType '1' for FIFO SDIO"
|
||||
"\n '2' for DMA SDIO"
|
||||
"\n '3' for Dedicated SPI"
|
||||
"\n '4' for Shared SPI");
|
||||
"\nType '1' for FIFO SDIO"
|
||||
"\n '2' for DMA SDIO"
|
||||
"\n '3' for Dedicated SPI"
|
||||
"\n '4' for Shared SPI");
|
||||
while (!Serial.available()) {
|
||||
}
|
||||
char c = Serial.read();
|
||||
|
||||
if (c =='1') {
|
||||
if (c == '1') {
|
||||
if (!sd.begin(SdioConfig(FIFO_SDIO))) {
|
||||
errorHalt("begin failed");
|
||||
}
|
||||
@@ -202,7 +201,7 @@ void loop() {
|
||||
errorHalt("begin failed");
|
||||
}
|
||||
Serial.println("\nDedicated SPI mode.");
|
||||
#else // ENABLE_DEDICATED_SPI
|
||||
#else // ENABLE_DEDICATED_SPI
|
||||
Serial.println("ENABLE_DEDICATED_SPI must be non-zero.");
|
||||
return;
|
||||
#endif // ENABLE_DEDICATED_SPI
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*
|
||||
* This program is a simple binary write/read benchmark.
|
||||
*/
|
||||
#include "FreeStack.h"
|
||||
#include "SdFat.h"
|
||||
#include "sdios.h"
|
||||
#include "FreeStack.h"
|
||||
|
||||
// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
|
||||
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
|
||||
@@ -19,7 +19,7 @@
|
||||
// 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
|
||||
#else // SDCARD_SS_PIN
|
||||
// Assume built-in SD is used.
|
||||
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
#endif // SDCARD_SS_PIN
|
||||
@@ -30,7 +30,7 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
// Try to select the best SD card configuration.
|
||||
#if HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdioConfig(FIFO_SDIO)
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
|
||||
#else // HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
|
||||
@@ -58,10 +58,10 @@ const uint8_t READ_COUNT = 2;
|
||||
// End of configuration constants.
|
||||
//------------------------------------------------------------------------------
|
||||
// File size in bytes.
|
||||
const uint32_t FILE_SIZE = 1000000UL*FILE_SIZE_MB;
|
||||
const uint32_t FILE_SIZE = 1000000UL * FILE_SIZE_MB;
|
||||
|
||||
// Insure 4-byte alignment.
|
||||
uint32_t buf32[(BUF_SIZE + 3)/4];
|
||||
uint32_t buf32[(BUF_SIZE + 3) / 4];
|
||||
uint8_t* buf = (uint8_t*)buf32;
|
||||
|
||||
#if SD_FAT_TYPE == 0
|
||||
@@ -125,8 +125,8 @@ void setup() {
|
||||
cout << F("\nUse a freshly formatted SD for best performance.\n");
|
||||
if (!ENABLE_DEDICATED_SPI) {
|
||||
cout << F(
|
||||
"\nSet ENABLE_DEDICATED_SPI nonzero in\n"
|
||||
"SdFatConfig.h for best SPI performance.\n");
|
||||
"\nSet ENABLE_DEDICATED_SPI nonzero in\n"
|
||||
"SdFatConfig.h for best SPI performance.\n");
|
||||
}
|
||||
// use uppercase in hex and use 0X base prefix
|
||||
cout << uppercase << showbase << endl;
|
||||
@@ -161,7 +161,7 @@ void loop() {
|
||||
cout << F("Type is FAT") << int(sd.fatType()) << endl;
|
||||
}
|
||||
|
||||
cout << F("Card size: ") << sd.card()->sectorCount()*512E-9;
|
||||
cout << F("Card size: ") << sd.card()->sectorCount() * 512E-9;
|
||||
cout << F(" GB (GB = 1E9 bytes)") << endl;
|
||||
|
||||
cidDmp();
|
||||
@@ -176,17 +176,17 @@ void loop() {
|
||||
for (size_t i = 0; i < (BUF_SIZE - 2); i++) {
|
||||
buf[i] = 'A' + (i % 26);
|
||||
}
|
||||
buf[BUF_SIZE-2] = '\r';
|
||||
buf[BUF_SIZE - 2] = '\r';
|
||||
}
|
||||
buf[BUF_SIZE-1] = '\n';
|
||||
buf[BUF_SIZE - 1] = '\n';
|
||||
|
||||
cout << F("FILE_SIZE_MB = ") << FILE_SIZE_MB << endl;
|
||||
cout << F("BUF_SIZE = ") << BUF_SIZE << F(" bytes\n");
|
||||
cout << F("Starting write test, please wait.") << endl << endl;
|
||||
|
||||
// do write test
|
||||
uint32_t n = FILE_SIZE/BUF_SIZE;
|
||||
cout <<F("write speed and latency") << endl;
|
||||
uint32_t n = FILE_SIZE / BUF_SIZE;
|
||||
cout << F("write speed and latency") << endl;
|
||||
cout << F("speed,max,min,avg") << endl;
|
||||
cout << F("KB/Sec,usec,usec,usec") << endl;
|
||||
for (uint8_t nTest = 0; nTest < WRITE_COUNT; nTest++) {
|
||||
@@ -223,11 +223,11 @@ void loop() {
|
||||
file.sync();
|
||||
t = millis() - t;
|
||||
s = file.fileSize();
|
||||
cout << s/t <<',' << maxLatency << ',' << minLatency;
|
||||
cout << ',' << totalLatency/n << endl;
|
||||
cout << s / t << ',' << maxLatency << ',' << minLatency;
|
||||
cout << ',' << totalLatency / n << endl;
|
||||
}
|
||||
cout << endl << F("Starting read test, please wait.") << endl;
|
||||
cout << endl <<F("read speed and latency") << endl;
|
||||
cout << endl << F("read speed and latency") << endl;
|
||||
cout << F("speed,max,min,avg") << endl;
|
||||
cout << F("KB/Sec,usec,usec,usec") << endl;
|
||||
|
||||
@@ -240,7 +240,7 @@ void loop() {
|
||||
skipLatency = SKIP_FIRST_LATENCY;
|
||||
t = millis();
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
buf[BUF_SIZE-1] = 0;
|
||||
buf[BUF_SIZE - 1] = 0;
|
||||
uint32_t m = micros();
|
||||
int32_t nr = file.read(buf, BUF_SIZE);
|
||||
if (nr != BUF_SIZE) {
|
||||
@@ -248,8 +248,7 @@ void loop() {
|
||||
}
|
||||
m = micros() - m;
|
||||
totalLatency += m;
|
||||
if (buf[BUF_SIZE-1] != '\n') {
|
||||
|
||||
if (buf[BUF_SIZE - 1] != '\n') {
|
||||
error("data check error");
|
||||
}
|
||||
if (skipLatency) {
|
||||
@@ -265,8 +264,8 @@ void loop() {
|
||||
}
|
||||
s = file.fileSize();
|
||||
t = millis() - t;
|
||||
cout << s/t <<',' << maxLatency << ',' << minLatency;
|
||||
cout << ',' << totalLatency/n << endl;
|
||||
cout << s / t << ',' << maxLatency << ',' << minLatency;
|
||||
cout << ',' << totalLatency / n << endl;
|
||||
}
|
||||
cout << endl << F("Done") << endl;
|
||||
file.close();
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
// 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
|
||||
#else // SDCARD_SS_PIN
|
||||
// Assume built-in SD is used.
|
||||
const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
#endif // SDCARD_SS_PIN
|
||||
@@ -31,7 +31,7 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
|
||||
// Try to select the best SD card configuration.
|
||||
#if HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdioConfig(FIFO_SDIO)
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#elif ENABLE_DEDICATED_SPI
|
||||
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
|
||||
#else // HAS_SDIO_CLASS
|
||||
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
|
||||
@@ -80,8 +80,7 @@ void setup() {
|
||||
// Remove file/dirs from previous run.
|
||||
if (sd.exists("dir2/DIR3/NAME3.txt")) {
|
||||
cout << F("Removing /dir2/DIR3/NAME3.txt") << endl;
|
||||
if (!sd.remove("dir2/DIR3/NAME3.txt") ||
|
||||
!sd.rmdir("dir2/DIR3/") ||
|
||||
if (!sd.remove("dir2/DIR3/NAME3.txt") || !sd.rmdir("dir2/DIR3/") ||
|
||||
!sd.rmdir("dir2/")) {
|
||||
error("remove/rmdir failed");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user