From 4e58a112e8935b5bf685e37a7cf2922b6171c6c9 Mon Sep 17 00:00:00 2001 From: rhounsell <53660397+rhounsell@users.noreply.github.com> Date: Thu, 8 Aug 2019 15:45:59 -0400 Subject: [PATCH 1/2] Fix for Toshiba FlashAir (or other) SD card initialization - add clock cycles between sending CMD0 and CMD8. Redone for MK3 branch) --- Firmware/Sd2Card.cpp | 15 +++++++++++++++ Firmware/Sd2Card.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/Firmware/Sd2Card.cpp b/Firmware/Sd2Card.cpp index c00c7ef9..cb1959be 100644 --- a/Firmware/Sd2Card.cpp +++ b/Firmware/Sd2Card.cpp @@ -319,6 +319,21 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) { goto fail; } } + + // send 0xFF until 0xFF received to give card some clock cycles + SERIAL_ECHOLNRPGM(PSTR("Sending 0xFF")); + spiSend(0XFF); + while ((status_ = spiRec()) != 0xFF) + { + spiSend(0XFF); + if (((uint16_t)_millis() - t0) > SD_CARD_ERROR_FF_TIMEOUT) + { + error(SD_CARD_ERROR_CMD8); + SERIAL_ECHOLNRPGM(PSTR("No 0xFF received")); + goto fail; + } + } + // check SD version if ((cardCommand(CMD8, 0x1AA) & R1_ILLEGAL_COMMAND)) { type(SD_CARD_TYPE_SD1); diff --git a/Firmware/Sd2Card.h b/Firmware/Sd2Card.h index 537d249c..f4cc59d7 100644 --- a/Firmware/Sd2Card.h +++ b/Firmware/Sd2Card.h @@ -105,6 +105,8 @@ uint8_t const SD_CARD_ERROR_SCK_RATE = 0X18; uint8_t const SD_CARD_ERROR_INIT_NOT_CALLED = 0X19; /** crc check error */ uint8_t const SD_CARD_ERROR_CRC = 0X20; +/** no response to sent 0xFF */ +uint8_t const SD_CARD_ERROR_FF_TIMEOUT = 0X21; /** Toshiba FlashAir: iSDIO */ uint8_t const SD_CARD_ERROR_CMD48 = 0x80; From 32fa8caab873e5b959f9393b825c236a85740347 Mon Sep 17 00:00:00 2001 From: rhounsell <53660397+rhounsell@users.noreply.github.com> Date: Sun, 11 Aug 2019 17:57:41 -0400 Subject: [PATCH 2/2] reinitialize the timestamp to ensure enough time to receive response for 0xFF sent. --- Firmware/Sd2Card.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/Sd2Card.cpp b/Firmware/Sd2Card.cpp index cb1959be..449590f1 100644 --- a/Firmware/Sd2Card.cpp +++ b/Firmware/Sd2Card.cpp @@ -321,6 +321,7 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) { } // send 0xFF until 0xFF received to give card some clock cycles + t0 = (uint16_t)_millis(); SERIAL_ECHOLNRPGM(PSTR("Sending 0xFF")); spiSend(0XFF); while ((status_ = spiRec()) != 0xFF)