From f37c64ee5b640ef9c2e295db792c34c9f1f8369f Mon Sep 17 00:00:00 2001 From: GMagician Date: Sat, 13 Jan 2018 08:53:12 +0100 Subject: [PATCH 1/3] Fix unsupported CMD59 It seems that some SD cards don't support CRC_ON_OFF command. This fix will permit to use also these cards but leaving CRC check active on the system --- Marlin/src/sd/Sd2Card.cpp | 9 ++++----- Marlin/src/sd/Sd2Card.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Marlin/src/sd/Sd2Card.cpp b/Marlin/src/sd/Sd2Card.cpp index 4392c06b2..adecc8e61 100644 --- a/Marlin/src/sd/Sd2Card.cpp +++ b/Marlin/src/sd/Sd2Card.cpp @@ -41,6 +41,8 @@ #include "../Marlin.h" #if ENABLED(SD_CHECK_AND_RETRY) + static bool crcSupported = true; + #ifdef FAST_CRC static const uint8_t crctab7[] PROGMEM = { 0x00,0x09,0x12,0x1b,0x24,0x2d,0x36,0x3f,0x48,0x41,0x5a,0x53,0x6c,0x65,0x7e,0x77, @@ -267,10 +269,7 @@ bool Sd2Card::init(uint8_t sckRateID, pin_t chipSelectPin) { } #if ENABLED(SD_CHECK_AND_RETRY) - if (cardCommand( CMD59, 1 ) != R1_IDLE_STATE) { - error(SD_CARD_ERROR_CMD59); - goto FAIL; - } + crcSupported = (cardCommand(CMD59, 1) == R1_IDLE_STATE); #endif // check SD version @@ -450,7 +449,7 @@ bool Sd2Card::readData(uint8_t* dst, uint16_t count) { #if ENABLED(SD_CHECK_AND_RETRY) { uint16_t recvCrc = (spiRec() << 8) | spiRec(); - if (recvCrc != CRC_CCITT(dst, count)) { + if (crcSupported && recvCrc != CRC_CCITT(dst, count)) { error(SD_CARD_ERROR_READ_CRC); goto FAIL; } diff --git a/Marlin/src/sd/Sd2Card.h b/Marlin/src/sd/Sd2Card.h index 65633aa8c..0df9c0ba6 100644 --- a/Marlin/src/sd/Sd2Card.h +++ b/Marlin/src/sd/Sd2Card.h @@ -71,7 +71,7 @@ uint8_t const SD_CARD_ERROR_CMD0 = 0x01, // timeout error for com SD_CARD_ERROR_WRITE_TIMEOUT = 0x17, // timeout occurred during write programming SD_CARD_ERROR_SCK_RATE = 0x18, // incorrect rate selected SD_CARD_ERROR_INIT_NOT_CALLED = 0x19, // init() not called - SD_CARD_ERROR_CMD59 = 0x1A, // card returned an error for CMD59 (CRC_ON_OFF) + // 0x1A is unused now, it was: card returned an error for CMD59 (CRC_ON_OFF) SD_CARD_ERROR_READ_CRC = 0x1B; // invalid read CRC // card types From be717b3c07e15b81c3e4ba8b5d839f66fbdf42a1 Mon Sep 17 00:00:00 2001 From: GMagician Date: Sat, 13 Jan 2018 08:56:51 +0100 Subject: [PATCH 2/3] Save some program memory This will save some program memory with no speed lose --- Marlin/src/sd/Sd2Card.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Marlin/src/sd/Sd2Card.cpp b/Marlin/src/sd/Sd2Card.cpp index adecc8e61..ba26243c9 100644 --- a/Marlin/src/sd/Sd2Card.cpp +++ b/Marlin/src/sd/Sd2Card.cpp @@ -339,21 +339,22 @@ bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) { else if (readData(dst, 512)) return true; + chipDeselect(); if (!--retryCnt) break; - chipDeselect(); cardCommand(CMD12, 0); // Try sending a stop command, ignore the result. errorCode_ = 0; } + return false; #else - if (cardCommand(CMD17, blockNumber)) + if (cardCommand(CMD17, blockNumber)) { error(SD_CARD_ERROR_CMD17); + chipDeselect(); + return false; + } else return readData(dst, 512); #endif - - chipDeselect(); - return false; } /** From 6667a916a4f6341316bf155c1f88f8003feca0a6 Mon Sep 17 00:00:00 2001 From: GMagician Date: Sat, 13 Jan 2018 09:48:26 +0100 Subject: [PATCH 3/3] Indentation fix --- Marlin/src/sd/Sd2Card.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/sd/Sd2Card.cpp b/Marlin/src/sd/Sd2Card.cpp index ba26243c9..ff82cdaac 100644 --- a/Marlin/src/sd/Sd2Card.cpp +++ b/Marlin/src/sd/Sd2Card.cpp @@ -345,7 +345,7 @@ bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) { cardCommand(CMD12, 0); // Try sending a stop command, ignore the result. errorCode_ = 0; } - return false; + return false; #else if (cardCommand(CMD17, blockNumber)) { error(SD_CARD_ERROR_CMD17);