Skip to content

Commit

Permalink
New features, major internal changes, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
greiman committed Jul 4, 2022
1 parent bab0061 commit 628effa
Show file tree
Hide file tree
Showing 117 changed files with 949 additions and 2,304 deletions.
45 changes: 23 additions & 22 deletions doc/SdErrorCodes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
2021-01-06
2022-07-01

Run the SdErrorCode example to produce an updated list.

Expand Down Expand Up @@ -27,24 +27,25 @@ Code,Symbol - failed operation
0X15,SD_CARD_ERROR_ACMD13 - Read extended status
0X16,SD_CARD_ERROR_ACMD23 - Set pre-erased count
0X17,SD_CARD_ERROR_ACMD41 - Activate card initialization
0X18,SD_CARD_ERROR_READ_TOKEN - Bad read data token
0X19,SD_CARD_ERROR_READ_CRC - Read CRC error
0X1A,SD_CARD_ERROR_READ_FIFO - SDIO fifo read timeout
0X1B,SD_CARD_ERROR_READ_REG - Read CID or CSD failed.
0X1C,SD_CARD_ERROR_READ_START - Bad readStart argument
0X1D,SD_CARD_ERROR_READ_TIMEOUT - Read data timeout
0X1E,SD_CARD_ERROR_STOP_TRAN - Multiple block stop failed
0X1F,SD_CARD_ERROR_TRANSFER_COMPLETE - SDIO transfer complete
0X20,SD_CARD_ERROR_WRITE_DATA - Write data not accepted
0X21,SD_CARD_ERROR_WRITE_FIFO - SDIO fifo write timeout
0X22,SD_CARD_ERROR_WRITE_START - Bad writeStart argument
0X23,SD_CARD_ERROR_WRITE_PROGRAMMING - Flash programming
0X24,SD_CARD_ERROR_WRITE_TIMEOUT - Write timeout
0X25,SD_CARD_ERROR_DMA - DMA transfer failed
0X26,SD_CARD_ERROR_ERASE - Card did not accept erase commands
0X27,SD_CARD_ERROR_ERASE_SINGLE_SECTOR - Card does not support erase
0X28,SD_CARD_ERROR_ERASE_TIMEOUT - Erase command timeout
0X29,SD_CARD_ERROR_INIT_NOT_CALLED - Card has not been initialized
0X2A,SD_CARD_ERROR_INVALID_CARD_CONFIG - Invalid card config
0X2B,SD_CARD_ERROR_FUNCTION_NOT_SUPPORTED - Unsupported SDIO command
0X2C,SD_CARD_ERROR_UNKNOWN - Unknown error
0X18,SD_CARD_ERROR_ACMD51 - Read SCR data
0X19,SD_CARD_ERROR_READ_TOKEN - Bad read data token
0X1A,SD_CARD_ERROR_READ_CRC - Read CRC error
0X1B,SD_CARD_ERROR_READ_FIFO - SDIO fifo read timeout
0X1C,SD_CARD_ERROR_READ_REG - Read CID or CSD failed.
0X1D,SD_CARD_ERROR_READ_START - Bad readStart argument
0X1E,SD_CARD_ERROR_READ_TIMEOUT - Read data timeout
0X1F,SD_CARD_ERROR_STOP_TRAN - Multiple block stop failed
0X20,SD_CARD_ERROR_TRANSFER_COMPLETE - SDIO transfer complete
0X21,SD_CARD_ERROR_WRITE_DATA - Write data not accepted
0X22,SD_CARD_ERROR_WRITE_FIFO - SDIO fifo write timeout
0X23,SD_CARD_ERROR_WRITE_START - Bad writeStart argument
0X24,SD_CARD_ERROR_WRITE_PROGRAMMING - Flash programming
0X25,SD_CARD_ERROR_WRITE_TIMEOUT - Write timeout
0X26,SD_CARD_ERROR_DMA - DMA transfer failed
0X27,SD_CARD_ERROR_ERASE - Card did not accept erase commands
0X28,SD_CARD_ERROR_ERASE_SINGLE_SECTOR - Card does not support erase
0X29,SD_CARD_ERROR_ERASE_TIMEOUT - Erase command timeout
0X2A,SD_CARD_ERROR_INIT_NOT_CALLED - Card has not been initialized
0X2B,SD_CARD_ERROR_INVALID_CARD_CONFIG - Invalid card config
0X2C,SD_CARD_ERROR_FUNCTION_NOT_SUPPORTED - Unsupported SDIO command
0X2D,SD_CARD_ERROR_UNKNOWN - Unknown error
Binary file modified doc/html.zip
Binary file not shown.
24 changes: 12 additions & 12 deletions doc/mainpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ This is a major new version of SdFat. It is mostly
backward compatible with SdFat Version 1 for FAT16/FAT32 cards.
You should edit SdFatConfig.h to select features. The default version of
SdFatConfig.h is suitable for UNO and other small AVR boards.
SdFatConfig.h is suitable for UNO and other small AVR boards.
\section Intro Introduction
The Arduino %SdFat library supports FAT16, FAT32, and exFAT file systems
The Arduino %SdFat library supports FAT16, FAT32, and exFAT file systems
on Standard SD, SDHC, and SDXC cards.
In %SdFat version 1, SdFat and File are the main classes.
In %SdFat version 2, SdFat and File are defined by typedefs in terms of the
following classes.
following classes.
The file system classes in the %SdFat library are SdFat32, SdExFat, and SdFs.
The file system classes in the %SdFat library are SdFat32, SdExFat, and SdFs.
SdFat32 supports FAT16 and FAT32. SdExFat supports exFAT, SdFs supports
FAT16, FAT32, and exFAT.
Expand All @@ -69,7 +69,7 @@ boards.
#endif // defined(__AVR__) && FLASHEND < 0X8000
\endcode
It is possible to use option three, support or FAT16/FAT32 and exFat
It is possible to use option three, support or FAT16/FAT32 and exFat
on an Uno or other AVR board with 32KB flash and 2KB SRAM but memory
will be very limited.
Expand All @@ -79,7 +79,7 @@ Uno memory use for a simple data logger is:
>
> option 2, exFAT, 14942 bytes of flash and 895 bytes of SRAM.
>
> option 3, FAT16/FAT32 and exFAT, 21834 bytes of flash and 908 bytes of SRAM.
> option 3, FAT16/FAT32 and exFAT, 21834 bytes of flash and 908 bytes of SRAM.
Please read documentation under the above classes tab for more information.
Expand Down Expand Up @@ -113,8 +113,8 @@ multi-block write.
Relative paths in %SdFat are resolved in a manner similar to Windows.
Each instance of SdFat32, SdExFat, and SdFs has a current directory.
This directory is called the volume working directory, vwd.
Each instance of SdFat32, SdExFat, and SdFs has a current directory.
This directory is called the volume working directory, vwd.
Initially this directory is the root directory for the volume.
The volume working directory is changed by calling the chdir(path).
Expand Down Expand Up @@ -149,9 +149,9 @@ will open "/music/BigBand.wav" on sd2.
\section Install Installation
You must manually install %SdFat by renaming the download folder %SdFat
You must manually install %SdFat by renaming the download folder %SdFat
and copy the %SdFat folder to the Arduino libraries folder in your
sketchbook folder.
sketchbook folder.
It will be necessary to unzip and rename the folder if you download a zip
file from GitHub.
Expand Down
1 change: 1 addition & 0 deletions examples/AvrAdcLogger/AvrAdcLogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const uint32_t MAX_FILE_SIZE = MAX_FILE_SIZE_MiB << 20;

// Max SPI rate for AVR is 10 MHz for F_CPU 20 MHz, 8 MHz for F_CPU 16 MHz.
#define SPI_CLOCK SD_SCK_MHZ(10)

// Select fastest interface.
#if ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
Expand Down
94 changes: 49 additions & 45 deletions examples/SdInfo/SdInfo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,27 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;

//------------------------------------------------------------------------------
SdFs sd;
cid_t m_cid;
csd_t m_csd;
uint32_t m_eraseSize;
uint32_t m_ocr;
cid_t cid;
csd_t csd;
scr_t scr;
uint8_t cmd6Data[64];
uint32_t eraseSize;
uint32_t ocr;
static ArduinoOutStream cout(Serial);
//------------------------------------------------------------------------------
bool cidDmp() {
void cidDmp() {
cout << F("\nManufacturer ID: ");
cout << uppercase << showbase << hex << int(m_cid.mid) << dec << endl;
cout << F("OEM ID: ") << m_cid.oid[0] << m_cid.oid[1] << endl;
cout << uppercase << showbase << hex << int(cid.mid) << dec << endl;
cout << F("OEM ID: ") << cid.oid[0] << cid.oid[1] << endl;
cout << F("Product: ");
for (uint8_t i = 0; i < 5; i++) {
cout << m_cid.pnm[i];
cout << cid.pnm[i];
}
cout << F("\nVersion: ");
cout << int(m_cid.prv_n) << '.' << int(m_cid.prv_m) << endl;
cout << F("Serial number: ") << hex << m_cid.psn << dec << endl;
cout << F("\nRevision: ") << cid.prvN() << '.' << cid.prvM() << endl;
cout << F("Serial number: ") << hex << cid.psn() << dec << endl;
cout << F("Manufacturing date: ");
cout << int(m_cid.mdt_month) << '/';
cout << (2000 + 16*m_cid.mdt_year_high + m_cid.mdt_year_low) << endl;
cout << cid.mdtMonth() << '/' << cid.mdtYear() << endl;
cout << endl;
return true;
}
//------------------------------------------------------------------------------
void clearSerialInput() {
Expand All @@ -68,38 +67,32 @@ void clearSerialInput() {
} while (micros() - m < 10000);
}
//------------------------------------------------------------------------------
bool csdDmp() {
bool eraseSingleBlock;
if (m_csd.v1.csd_ver == 0) {
eraseSingleBlock = m_csd.v1.erase_blk_en;
m_eraseSize = (m_csd.v1.sector_size_high << 1) | m_csd.v1.sector_size_low;
} else if (m_csd.v2.csd_ver == 1) {
eraseSingleBlock = m_csd.v2.erase_blk_en;
m_eraseSize = (m_csd.v2.sector_size_high << 1) | m_csd.v2.sector_size_low;
} else {
cout << F("m_csd version error\n");
return false;
}
m_eraseSize++;
cout << F("cardSize: ") << 0.000512 * sdCardCapacity(&m_csd);
void csdDmp() {
eraseSize = csd.eraseSize();
cout << F("cardSize: ") << 0.000512 * csd.capacity();
cout << F(" MB (MB = 1,000,000 bytes)\n");

cout << F("flashEraseSize: ") << int(m_eraseSize) << F(" blocks\n");
cout << F("flashEraseSize: ") << int(eraseSize) << F(" blocks\n");
cout << F("eraseSingleBlock: ");
if (eraseSingleBlock) {
if (csd.eraseSingleBlock()) {
cout << F("true\n");
} else {
cout << F("false\n");
}
return true;
cout << F("dataAfterErase: ");
if (scr.dataAfterErase()) {
cout << F("ones\n");
} else {
cout << F("zeros\n");
}
}
//------------------------------------------------------------------------------
void errorPrint() {
if (sd.sdErrorCode()) {
cout << F("SD errorCode: ") << hex << showbase;
printSdErrorSymbol(&Serial, sd.sdErrorCode());
cout << F(" = ") << int(sd.sdErrorCode()) << endl;
cout << F("SD errorData = ") << int(sd.sdErrorData()) << endl;
cout << F("SD errorData = ") << int(sd.sdErrorData()) << dec << endl;
}
}
//------------------------------------------------------------------------------
Expand All @@ -116,7 +109,7 @@ bool mbrDmp() {
for (uint8_t ip = 1; ip < 5; ip++) {
MbrPart_t *pt = &mbr.part[ip - 1];
if ((pt->boot != 0 && pt->boot != 0X80) ||
getLe32(pt->relativeSectors) > sdCardCapacity(&m_csd)) {
getLe32(pt->relativeSectors) > csd.capacity()) {
valid = false;
}
cout << int(ip) << ',' << uppercase << showbase << hex;
Expand All @@ -139,20 +132,22 @@ bool mbrDmp() {
//------------------------------------------------------------------------------
void dmpVol() {
cout << F("\nScanning FAT, please wait.\n");
uint32_t freeClusterCount = sd.freeClusterCount();
int32_t freeClusterCount = sd.freeClusterCount();
if (sd.fatType() <= 32) {
cout << F("\nVolume is FAT") << int(sd.fatType()) << endl;
} else {
cout << F("\nVolume is exFAT\n");
}
cout << F("sectorsPerCluster: ") << sd.sectorsPerCluster() << endl;
cout << F("clusterCount: ") << sd.clusterCount() << endl;
cout << F("freeClusterCount: ") << freeClusterCount << endl;
cout << F("fatStartSector: ") << sd.fatStartSector() << endl;
cout << F("dataStartSector: ") << sd.dataStartSector() << endl;
if (sd.dataStartSector() % m_eraseSize) {
cout << F("Data area is not aligned on flash erase boundary!\n");
cout << F("Download and use formatter from www.sdcard.org!\n");
cout << F("clusterCount: ") << sd.clusterCount() << endl;
cout << F("freeClusterCount: ");
if (freeClusterCount >= 0) {
cout << freeClusterCount << endl;
} else {
cout << F("failed\n");
errorPrint();
}
}
//------------------------------------------------------------------------------
Expand All @@ -170,7 +165,7 @@ void printCardType() {
break;

case SD_CARD_TYPE_SDHC:
if (sdCardCapacity(&m_csd) < 70000000) {
if (csd.capacity() < 70000000) {
cout << F("SDHC\n");
} else {
cout << F("SDXC\n");
Expand Down Expand Up @@ -239,20 +234,29 @@ void loop() {
return;
}
t = millis() - t;
cout << F("init time: ") << t << " ms" << endl;
cout << F("init time: ") << dec << t << " ms" << endl;

if (!sd.card()->readCID(&m_cid) ||
!sd.card()->readCSD(&m_csd) ||
!sd.card()->readOCR(&m_ocr)) {
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("HighSpeedMode: ");
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;
cout << hex << m_ocr << dec << endl;
cout << hex << ocr << dec << endl;
if (!mbrDmp()) {
return;
}
Expand Down
14 changes: 6 additions & 8 deletions examples/bench/bench.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -89,22 +89,19 @@ ArduinoOutStream cout(Serial);
void cidDmp() {
cid_t cid;
if (!sd.card()->readCID(&cid)) {

error("readCID failed");
}
cout << F("\nManufacturer ID: ");
cout << hex << int(cid.mid) << dec << endl;
cout << uppercase << showbase << hex << int(cid.mid) << dec << endl;
cout << F("OEM ID: ") << cid.oid[0] << cid.oid[1] << endl;
cout << F("Product: ");
for (uint8_t i = 0; i < 5; i++) {
cout << cid.pnm[i];
}
cout << F("\nVersion: ");
cout << int(cid.prv_n) << '.' << int(cid.prv_m) << endl;
cout << F("Serial number: ") << hex << cid.psn << dec << endl;
cout << F("\nRevision: ") << cid.prvN() << '.' << cid.prvM() << endl;
cout << F("Serial number: ") << hex << cid.psn() << dec << endl;
cout << F("Manufacturing date: ");
cout << int(cid.mdt_month) << '/';
cout << (2000 + cid.mdt_year_low + 10 * cid.mdt_year_high) << endl;
cout << cid.mdtMonth() << '/' << cid.mdtYear() << endl;
cout << endl;
}
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -273,4 +270,5 @@ void loop() {
}
cout << endl << F("Done") << endl;
file.close();
sd.end();
}
Loading

0 comments on commit 628effa

Please sign in to comment.