mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-27 22:08:02 +00:00
Merge pull request #9163 from GMagician/2.0.x-SD-issues-fix
[2.0.x] sd issue fix
This commit is contained in:
commit
6ba8cf8405
@ -41,6 +41,8 @@
|
|||||||
#include "../Marlin.h"
|
#include "../Marlin.h"
|
||||||
|
|
||||||
#if ENABLED(SD_CHECK_AND_RETRY)
|
#if ENABLED(SD_CHECK_AND_RETRY)
|
||||||
|
static bool crcSupported = true;
|
||||||
|
|
||||||
#ifdef FAST_CRC
|
#ifdef FAST_CRC
|
||||||
static const uint8_t crctab7[] PROGMEM = {
|
static const uint8_t crctab7[] PROGMEM = {
|
||||||
0x00,0x09,0x12,0x1b,0x24,0x2d,0x36,0x3f,0x48,0x41,0x5a,0x53,0x6c,0x65,0x7e,0x77,
|
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 ENABLED(SD_CHECK_AND_RETRY)
|
||||||
if (cardCommand( CMD59, 1 ) != R1_IDLE_STATE) {
|
crcSupported = (cardCommand(CMD59, 1) == R1_IDLE_STATE);
|
||||||
error(SD_CARD_ERROR_CMD59);
|
|
||||||
goto FAIL;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// check SD version
|
// check SD version
|
||||||
@ -340,21 +339,22 @@ bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) {
|
|||||||
else if (readData(dst, 512))
|
else if (readData(dst, 512))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
chipDeselect();
|
||||||
if (!--retryCnt) break;
|
if (!--retryCnt) break;
|
||||||
|
|
||||||
chipDeselect();
|
|
||||||
cardCommand(CMD12, 0); // Try sending a stop command, ignore the result.
|
cardCommand(CMD12, 0); // Try sending a stop command, ignore the result.
|
||||||
errorCode_ = 0;
|
errorCode_ = 0;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
#else
|
#else
|
||||||
if (cardCommand(CMD17, blockNumber))
|
if (cardCommand(CMD17, blockNumber)) {
|
||||||
error(SD_CARD_ERROR_CMD17);
|
error(SD_CARD_ERROR_CMD17);
|
||||||
|
chipDeselect();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return readData(dst, 512);
|
return readData(dst, 512);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
chipDeselect();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -450,7 +450,7 @@ bool Sd2Card::readData(uint8_t* dst, uint16_t count) {
|
|||||||
#if ENABLED(SD_CHECK_AND_RETRY)
|
#if ENABLED(SD_CHECK_AND_RETRY)
|
||||||
{
|
{
|
||||||
uint16_t recvCrc = (spiRec() << 8) | spiRec();
|
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);
|
error(SD_CARD_ERROR_READ_CRC);
|
||||||
goto FAIL;
|
goto FAIL;
|
||||||
}
|
}
|
||||||
|
@ -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_WRITE_TIMEOUT = 0x17, // timeout occurred during write programming
|
||||||
SD_CARD_ERROR_SCK_RATE = 0x18, // incorrect rate selected
|
SD_CARD_ERROR_SCK_RATE = 0x18, // incorrect rate selected
|
||||||
SD_CARD_ERROR_INIT_NOT_CALLED = 0x19, // init() not called
|
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
|
SD_CARD_ERROR_READ_CRC = 0x1B; // invalid read CRC
|
||||||
|
|
||||||
// card types
|
// card types
|
||||||
|
Loading…
Reference in New Issue
Block a user