#include <FreeStack.h>#include <MinimumSerial.h>#include <SdFat.h>#include <SdFatConfig.h>#include <sdios.h>#include <SPI.h>// Set USE_SDIO to zero for SPI card access. #define USE_SDIO 0const uint8_t SD_CHIP_SELECT = 10; // SD Chip select pin.const int8_t DISABLE_CHIP_SELECT = -1; // Disable a second SPI device.#if USE_SDIO// Use faster SdioCardEXSdFatSdioEX sd;// SdFatSdio sd;#else // USE_SDIOSdFat sd;#endif // USE_SDIOArduinoOutStream cout(Serial); // serial output steamuint32_t cardSize; // global for card sizeuint32_t eraseSize; // global for card erase size//------------------------------------------------------------------------------// store error strings in flash#define sdErrorMsg(msg) sd.errorPrint(F(msg));//------------------------------------------------------------------------------uint8_t cidDmp() { cid_t cid; if (!sd.card()->readCID(&cid)) { sdErrorMsg("readCID failed"); return false; } cout << F("\nManufacturer ID : "); cout << 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 : ") << cid.psn << " (Hex : " << 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 << endl; cout << F("*****************************************") << endl; cout << F("* CID: "); if (int(cid.mid) <= 9) { cout << F("0"); } cout << hex << int(cid.mid) << int(cid.oid[0]) << int(cid.oid[1]) << int(cid.pnm[0]) << int(cid.pnm[1]) << int(cid.pnm[2]) << int(cid.pnm[3]) << int(cid.pnm[4]) << int(cid.prv_n) << int(cid.prv_m) << cid.psn << "00" << int(cid.mdt_year_low) << int(cid.mdt_month) << int(cid.crc) << " *" << endl; cout << F("*****************************************") << endl; return true;}void setup() { Serial.begin(9600); // Wait for USB Serial while (!Serial) { SysCall::yield(); } // cout << uppercase << showbase << endl; // use uppercase in hex and use 0X base prefix // F stores strings in flash to save RAM cout << F("SdFat version: ") << SD_FAT_VERSION << " (CID_Mod_Lite)" << endl;#if !USE_SDIO if (DISABLE_CHIP_SELECT < 0) { } else { cout << F("\nDisabling SPI device on pin "); cout << int(DISABLE_CHIP_SELECT) << endl; pinMode(DISABLE_CHIP_SELECT, OUTPUT); digitalWrite(DISABLE_CHIP_SELECT, HIGH); }#endif // !USE_SDIO }//------------------------------------------------------------------------------void loop() { // Read any existing Serial data. do { delay(10); } while (Serial.available() && Serial.read() >= 0); // F stores strings in flash to save RAM cout << F("\n!!! Type any character to START !!!\n"); while (!Serial.available()) { SysCall::yield(); } uint32_t t = millis();#if USE_SDIO if (!sd.cardBegin()) { sdErrorMsg("\ncardBegin failed"); return; }#else // USE_SDIO // Initialize at the highest speed supported by the board that is // not over 50 MHz. Try a lower speed if SPI errors occur. if (!sd.cardBegin(SD_CHIP_SELECT, SD_SCK_MHZ(50))) { sdErrorMsg("cardBegin failed"); return; } #endif // USE_SDIO t = millis() - t; cardSize = sd.card()->cardSize(); if (cardSize == 0) { sdErrorMsg("cardSize failed"); return; } cout << "Size: " << cardSize << endl; cout << F("\n*****************************************************"); cout << endl; cout << F("\nInit time : ") << t << "(ms)" << endl; cout << F("Card type : "); switch (sd.card()->type()) { case SD_CARD_TYPE_SD1: cout << F("SD1\n"); break; case SD_CARD_TYPE_SD2: cout << F("SD2\n"); break; case SD_CARD_TYPE_SDHC: if (cardSize < 70000000) { cout << F("SDHC\n"); } else { cout << F("SDXC\n"); } break; default: cout << F("Unknown\n"); } if (!cidDmp()) { return; }}