@@ -35,28 +35,27 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
3535
3636// ------------------------------------------------------------------------------
3737SdFs 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;
4244static ArduinoOutStream cout (Serial);
4345// ------------------------------------------------------------------------------
44- bool cidDmp () {
46+ void cidDmp () {
4547 cout << F (" \n Manufacturer 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 (" \n Version: " );
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 (" \n Revision: " ) << 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// ------------------------------------------------------------------------------
6261void 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// ------------------------------------------------------------------------------
9790void 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// ------------------------------------------------------------------------------
140133void dmpVol () {
141134 cout << F (" \n Scanning FAT, please wait.\n " );
142- uint32_t freeClusterCount = sd.freeClusterCount ();
135+ int32_t freeClusterCount = sd.freeClusterCount ();
143136 if (sd.fatType () <= 32 ) {
144137 cout << F (" \n Volume is FAT" ) << int (sd.fatType ()) << endl;
145138 } else {
146139 cout << F (" \n Volume 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 (" \n OCR: " ) << uppercase << showbase;
255- cout << hex << m_ocr << dec << endl;
259+ cout << hex << ocr << dec << endl;
256260 if (!mbrDmp ()) {
257261 return ;
258262 }
0 commit comments