Skip to content

Commit 628effa

Browse files
committed
New features, major internal changes, bug fixes
1 parent bab0061 commit 628effa

File tree

117 files changed

+949
-2304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+949
-2304
lines changed

doc/SdErrorCodes.txt

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
2021-01-06
1+
2022-07-01
22

33
Run the SdErrorCode example to produce an updated list.
44

@@ -27,24 +27,25 @@ Code,Symbol - failed operation
2727
0X15,SD_CARD_ERROR_ACMD13 - Read extended status
2828
0X16,SD_CARD_ERROR_ACMD23 - Set pre-erased count
2929
0X17,SD_CARD_ERROR_ACMD41 - Activate card initialization
30-
0X18,SD_CARD_ERROR_READ_TOKEN - Bad read data token
31-
0X19,SD_CARD_ERROR_READ_CRC - Read CRC error
32-
0X1A,SD_CARD_ERROR_READ_FIFO - SDIO fifo read timeout
33-
0X1B,SD_CARD_ERROR_READ_REG - Read CID or CSD failed.
34-
0X1C,SD_CARD_ERROR_READ_START - Bad readStart argument
35-
0X1D,SD_CARD_ERROR_READ_TIMEOUT - Read data timeout
36-
0X1E,SD_CARD_ERROR_STOP_TRAN - Multiple block stop failed
37-
0X1F,SD_CARD_ERROR_TRANSFER_COMPLETE - SDIO transfer complete
38-
0X20,SD_CARD_ERROR_WRITE_DATA - Write data not accepted
39-
0X21,SD_CARD_ERROR_WRITE_FIFO - SDIO fifo write timeout
40-
0X22,SD_CARD_ERROR_WRITE_START - Bad writeStart argument
41-
0X23,SD_CARD_ERROR_WRITE_PROGRAMMING - Flash programming
42-
0X24,SD_CARD_ERROR_WRITE_TIMEOUT - Write timeout
43-
0X25,SD_CARD_ERROR_DMA - DMA transfer failed
44-
0X26,SD_CARD_ERROR_ERASE - Card did not accept erase commands
45-
0X27,SD_CARD_ERROR_ERASE_SINGLE_SECTOR - Card does not support erase
46-
0X28,SD_CARD_ERROR_ERASE_TIMEOUT - Erase command timeout
47-
0X29,SD_CARD_ERROR_INIT_NOT_CALLED - Card has not been initialized
48-
0X2A,SD_CARD_ERROR_INVALID_CARD_CONFIG - Invalid card config
49-
0X2B,SD_CARD_ERROR_FUNCTION_NOT_SUPPORTED - Unsupported SDIO command
50-
0X2C,SD_CARD_ERROR_UNKNOWN - Unknown error
30+
0X18,SD_CARD_ERROR_ACMD51 - Read SCR data
31+
0X19,SD_CARD_ERROR_READ_TOKEN - Bad read data token
32+
0X1A,SD_CARD_ERROR_READ_CRC - Read CRC error
33+
0X1B,SD_CARD_ERROR_READ_FIFO - SDIO fifo read timeout
34+
0X1C,SD_CARD_ERROR_READ_REG - Read CID or CSD failed.
35+
0X1D,SD_CARD_ERROR_READ_START - Bad readStart argument
36+
0X1E,SD_CARD_ERROR_READ_TIMEOUT - Read data timeout
37+
0X1F,SD_CARD_ERROR_STOP_TRAN - Multiple block stop failed
38+
0X20,SD_CARD_ERROR_TRANSFER_COMPLETE - SDIO transfer complete
39+
0X21,SD_CARD_ERROR_WRITE_DATA - Write data not accepted
40+
0X22,SD_CARD_ERROR_WRITE_FIFO - SDIO fifo write timeout
41+
0X23,SD_CARD_ERROR_WRITE_START - Bad writeStart argument
42+
0X24,SD_CARD_ERROR_WRITE_PROGRAMMING - Flash programming
43+
0X25,SD_CARD_ERROR_WRITE_TIMEOUT - Write timeout
44+
0X26,SD_CARD_ERROR_DMA - DMA transfer failed
45+
0X27,SD_CARD_ERROR_ERASE - Card did not accept erase commands
46+
0X28,SD_CARD_ERROR_ERASE_SINGLE_SECTOR - Card does not support erase
47+
0X29,SD_CARD_ERROR_ERASE_TIMEOUT - Erase command timeout
48+
0X2A,SD_CARD_ERROR_INIT_NOT_CALLED - Card has not been initialized
49+
0X2B,SD_CARD_ERROR_INVALID_CARD_CONFIG - Invalid card config
50+
0X2C,SD_CARD_ERROR_FUNCTION_NOT_SUPPORTED - Unsupported SDIO command
51+
0X2D,SD_CARD_ERROR_UNKNOWN - Unknown error

doc/html.zip

29.5 KB
Binary file not shown.

doc/mainpage.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ This is a major new version of SdFat. It is mostly
3131
backward compatible with SdFat Version 1 for FAT16/FAT32 cards.
3232
3333
You should edit SdFatConfig.h to select features. The default version of
34-
SdFatConfig.h is suitable for UNO and other small AVR boards.
34+
SdFatConfig.h is suitable for UNO and other small AVR boards.
3535
3636
\section Intro Introduction
37-
38-
The Arduino %SdFat library supports FAT16, FAT32, and exFAT file systems
37+
38+
The Arduino %SdFat library supports FAT16, FAT32, and exFAT file systems
3939
on Standard SD, SDHC, and SDXC cards.
40-
40+
4141
In %SdFat version 1, SdFat and File are the main classes.
4242
4343
In %SdFat version 2, SdFat and File are defined by typedefs in terms of the
44-
following classes.
44+
following classes.
4545
46-
The file system classes in the %SdFat library are SdFat32, SdExFat, and SdFs.
46+
The file system classes in the %SdFat library are SdFat32, SdExFat, and SdFs.
4747
SdFat32 supports FAT16 and FAT32. SdExFat supports exFAT, SdFs supports
4848
FAT16, FAT32, and exFAT.
4949
@@ -69,7 +69,7 @@ boards.
6969
#endif // defined(__AVR__) && FLASHEND < 0X8000
7070
\endcode
7171
72-
It is possible to use option three, support or FAT16/FAT32 and exFat
72+
It is possible to use option three, support or FAT16/FAT32 and exFat
7373
on an Uno or other AVR board with 32KB flash and 2KB SRAM but memory
7474
will be very limited.
7575
@@ -79,7 +79,7 @@ Uno memory use for a simple data logger is:
7979
>
8080
> option 2, exFAT, 14942 bytes of flash and 895 bytes of SRAM.
8181
>
82-
> option 3, FAT16/FAT32 and exFAT, 21834 bytes of flash and 908 bytes of SRAM.
82+
> option 3, FAT16/FAT32 and exFAT, 21834 bytes of flash and 908 bytes of SRAM.
8383
8484
Please read documentation under the above classes tab for more information.
8585
@@ -113,8 +113,8 @@ multi-block write.
113113
114114
Relative paths in %SdFat are resolved in a manner similar to Windows.
115115
116-
Each instance of SdFat32, SdExFat, and SdFs has a current directory.
117-
This directory is called the volume working directory, vwd.
116+
Each instance of SdFat32, SdExFat, and SdFs has a current directory.
117+
This directory is called the volume working directory, vwd.
118118
Initially this directory is the root directory for the volume.
119119
120120
The volume working directory is changed by calling the chdir(path).
@@ -149,9 +149,9 @@ will open "/music/BigBand.wav" on sd2.
149149
150150
\section Install Installation
151151
152-
You must manually install %SdFat by renaming the download folder %SdFat
152+
You must manually install %SdFat by renaming the download folder %SdFat
153153
and copy the %SdFat folder to the Arduino libraries folder in your
154-
sketchbook folder.
154+
sketchbook folder.
155155
156156
It will be necessary to unzip and rename the folder if you download a zip
157157
file from GitHub.

examples/AvrAdcLogger/AvrAdcLogger.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ const uint32_t MAX_FILE_SIZE = MAX_FILE_SIZE_MiB << 20;
151151

152152
// Max SPI rate for AVR is 10 MHz for F_CPU 20 MHz, 8 MHz for F_CPU 16 MHz.
153153
#define SPI_CLOCK SD_SCK_MHZ(10)
154+
154155
// Select fastest interface.
155156
#if ENABLE_DEDICATED_SPI
156157
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)

examples/SdInfo/SdInfo.ino

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,27 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
3535

3636
//------------------------------------------------------------------------------
3737
SdFs sd;
38-
cid_t m_cid;
39-
csd_t m_csd;
40-
uint32_t m_eraseSize;
41-
uint32_t m_ocr;
38+
cid_t cid;
39+
csd_t csd;
40+
scr_t scr;
41+
uint8_t cmd6Data[64];
42+
uint32_t eraseSize;
43+
uint32_t ocr;
4244
static ArduinoOutStream cout(Serial);
4345
//------------------------------------------------------------------------------
44-
bool cidDmp() {
46+
void cidDmp() {
4547
cout << F("\nManufacturer ID: ");
46-
cout << uppercase << showbase << hex << int(m_cid.mid) << dec << endl;
47-
cout << F("OEM ID: ") << m_cid.oid[0] << m_cid.oid[1] << endl;
48+
cout << uppercase << showbase << hex << int(cid.mid) << dec << endl;
49+
cout << F("OEM ID: ") << cid.oid[0] << cid.oid[1] << endl;
4850
cout << F("Product: ");
4951
for (uint8_t i = 0; i < 5; i++) {
50-
cout << m_cid.pnm[i];
52+
cout << cid.pnm[i];
5153
}
52-
cout << F("\nVersion: ");
53-
cout << int(m_cid.prv_n) << '.' << int(m_cid.prv_m) << endl;
54-
cout << F("Serial number: ") << hex << m_cid.psn << dec << endl;
54+
cout << F("\nRevision: ") << cid.prvN() << '.' << cid.prvM() << endl;
55+
cout << F("Serial number: ") << hex << cid.psn() << dec << endl;
5556
cout << F("Manufacturing date: ");
56-
cout << int(m_cid.mdt_month) << '/';
57-
cout << (2000 + 16*m_cid.mdt_year_high + m_cid.mdt_year_low) << endl;
57+
cout << cid.mdtMonth() << '/' << cid.mdtYear() << endl;
5858
cout << endl;
59-
return true;
6059
}
6160
//------------------------------------------------------------------------------
6261
void clearSerialInput() {
@@ -68,38 +67,32 @@ void clearSerialInput() {
6867
} while (micros() - m < 10000);
6968
}
7069
//------------------------------------------------------------------------------
71-
bool csdDmp() {
72-
bool eraseSingleBlock;
73-
if (m_csd.v1.csd_ver == 0) {
74-
eraseSingleBlock = m_csd.v1.erase_blk_en;
75-
m_eraseSize = (m_csd.v1.sector_size_high << 1) | m_csd.v1.sector_size_low;
76-
} else if (m_csd.v2.csd_ver == 1) {
77-
eraseSingleBlock = m_csd.v2.erase_blk_en;
78-
m_eraseSize = (m_csd.v2.sector_size_high << 1) | m_csd.v2.sector_size_low;
79-
} else {
80-
cout << F("m_csd version error\n");
81-
return false;
82-
}
83-
m_eraseSize++;
84-
cout << F("cardSize: ") << 0.000512 * sdCardCapacity(&m_csd);
70+
void csdDmp() {
71+
eraseSize = csd.eraseSize();
72+
cout << F("cardSize: ") << 0.000512 * csd.capacity();
8573
cout << F(" MB (MB = 1,000,000 bytes)\n");
8674

87-
cout << F("flashEraseSize: ") << int(m_eraseSize) << F(" blocks\n");
75+
cout << F("flashEraseSize: ") << int(eraseSize) << F(" blocks\n");
8876
cout << F("eraseSingleBlock: ");
89-
if (eraseSingleBlock) {
77+
if (csd.eraseSingleBlock()) {
9078
cout << F("true\n");
9179
} else {
9280
cout << F("false\n");
9381
}
94-
return true;
82+
cout << F("dataAfterErase: ");
83+
if (scr.dataAfterErase()) {
84+
cout << F("ones\n");
85+
} else {
86+
cout << F("zeros\n");
87+
}
9588
}
9689
//------------------------------------------------------------------------------
9790
void errorPrint() {
9891
if (sd.sdErrorCode()) {
9992
cout << F("SD errorCode: ") << hex << showbase;
10093
printSdErrorSymbol(&Serial, sd.sdErrorCode());
10194
cout << F(" = ") << int(sd.sdErrorCode()) << endl;
102-
cout << F("SD errorData = ") << int(sd.sdErrorData()) << endl;
95+
cout << F("SD errorData = ") << int(sd.sdErrorData()) << dec << endl;
10396
}
10497
}
10598
//------------------------------------------------------------------------------
@@ -116,7 +109,7 @@ bool mbrDmp() {
116109
for (uint8_t ip = 1; ip < 5; ip++) {
117110
MbrPart_t *pt = &mbr.part[ip - 1];
118111
if ((pt->boot != 0 && pt->boot != 0X80) ||
119-
getLe32(pt->relativeSectors) > sdCardCapacity(&m_csd)) {
112+
getLe32(pt->relativeSectors) > csd.capacity()) {
120113
valid = false;
121114
}
122115
cout << int(ip) << ',' << uppercase << showbase << hex;
@@ -139,20 +132,22 @@ bool mbrDmp() {
139132
//------------------------------------------------------------------------------
140133
void dmpVol() {
141134
cout << F("\nScanning FAT, please wait.\n");
142-
uint32_t freeClusterCount = sd.freeClusterCount();
135+
int32_t freeClusterCount = sd.freeClusterCount();
143136
if (sd.fatType() <= 32) {
144137
cout << F("\nVolume is FAT") << int(sd.fatType()) << endl;
145138
} else {
146139
cout << F("\nVolume is exFAT\n");
147140
}
148141
cout << F("sectorsPerCluster: ") << sd.sectorsPerCluster() << endl;
149-
cout << F("clusterCount: ") << sd.clusterCount() << endl;
150-
cout << F("freeClusterCount: ") << freeClusterCount << endl;
151142
cout << F("fatStartSector: ") << sd.fatStartSector() << endl;
152143
cout << F("dataStartSector: ") << sd.dataStartSector() << endl;
153-
if (sd.dataStartSector() % m_eraseSize) {
154-
cout << F("Data area is not aligned on flash erase boundary!\n");
155-
cout << F("Download and use formatter from www.sdcard.org!\n");
144+
cout << F("clusterCount: ") << sd.clusterCount() << endl;
145+
cout << F("freeClusterCount: ");
146+
if (freeClusterCount >= 0) {
147+
cout << freeClusterCount << endl;
148+
} else {
149+
cout << F("failed\n");
150+
errorPrint();
156151
}
157152
}
158153
//------------------------------------------------------------------------------
@@ -170,7 +165,7 @@ void printCardType() {
170165
break;
171166

172167
case SD_CARD_TYPE_SDHC:
173-
if (sdCardCapacity(&m_csd) < 70000000) {
168+
if (csd.capacity() < 70000000) {
174169
cout << F("SDHC\n");
175170
} else {
176171
cout << F("SDXC\n");
@@ -239,20 +234,29 @@ void loop() {
239234
return;
240235
}
241236
t = millis() - t;
242-
cout << F("init time: ") << t << " ms" << endl;
237+
cout << F("init time: ") << dec << t << " ms" << endl;
243238

244-
if (!sd.card()->readCID(&m_cid) ||
245-
!sd.card()->readCSD(&m_csd) ||
246-
!sd.card()->readOCR(&m_ocr)) {
239+
if (!sd.card()->readCID(&cid) ||
240+
!sd.card()->readCSD(&csd) ||
241+
!sd.card()->readOCR(&ocr) ||
242+
!sd.card()->readSCR(&scr)) {
247243
cout << F("readInfo failed\n");
248244
errorPrint();
249245
return;
250246
}
251247
printCardType();
248+
cout << F("sdSpecVer: ") << 0.01*scr.sdSpecVer() << endl;
249+
cout << F("HighSpeedMode: ");
250+
if (scr.sdSpecVer() &&
251+
sd.card()->cardCMD6(0X00FFFFFF, cmd6Data) && (2 & cmd6Data[13])) {
252+
cout << F("true\n");
253+
} else {
254+
cout << F("false\n");
255+
}
252256
cidDmp();
253257
csdDmp();
254258
cout << F("\nOCR: ") << uppercase << showbase;
255-
cout << hex << m_ocr << dec << endl;
259+
cout << hex << ocr << dec << endl;
256260
if (!mbrDmp()) {
257261
return;
258262
}

examples/bench/bench.ino

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
3030
// Try to select the best SD card configuration.
3131
#if HAS_SDIO_CLASS
3232
#define SD_CONFIG SdioConfig(FIFO_SDIO)
33-
#elif ENABLE_DEDICATED_SPI
33+
#elif ENABLE_DEDICATED_SPI
3434
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
3535
#else // HAS_SDIO_CLASS
3636
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
@@ -89,22 +89,19 @@ ArduinoOutStream cout(Serial);
8989
void cidDmp() {
9090
cid_t cid;
9191
if (!sd.card()->readCID(&cid)) {
92-
9392
error("readCID failed");
9493
}
9594
cout << F("\nManufacturer ID: ");
96-
cout << hex << int(cid.mid) << dec << endl;
95+
cout << uppercase << showbase << hex << int(cid.mid) << dec << endl;
9796
cout << F("OEM ID: ") << cid.oid[0] << cid.oid[1] << endl;
9897
cout << F("Product: ");
9998
for (uint8_t i = 0; i < 5; i++) {
10099
cout << cid.pnm[i];
101100
}
102-
cout << F("\nVersion: ");
103-
cout << int(cid.prv_n) << '.' << int(cid.prv_m) << endl;
104-
cout << F("Serial number: ") << hex << cid.psn << dec << endl;
101+
cout << F("\nRevision: ") << cid.prvN() << '.' << cid.prvM() << endl;
102+
cout << F("Serial number: ") << hex << cid.psn() << dec << endl;
105103
cout << F("Manufacturing date: ");
106-
cout << int(cid.mdt_month) << '/';
107-
cout << (2000 + cid.mdt_year_low + 10 * cid.mdt_year_high) << endl;
104+
cout << cid.mdtMonth() << '/' << cid.mdtYear() << endl;
108105
cout << endl;
109106
}
110107
//------------------------------------------------------------------------------
@@ -273,4 +270,5 @@ void loop() {
273270
}
274271
cout << endl << F("Done") << endl;
275272
file.close();
273+
sd.end();
276274
}

0 commit comments

Comments
 (0)