Browse Source

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
GMagician 6 years ago
parent
commit
f37c64ee5b
2 changed files with 5 additions and 6 deletions
  1. 4
    5
      Marlin/src/sd/Sd2Card.cpp
  2. 1
    1
      Marlin/src/sd/Sd2Card.h

+ 4
- 5
Marlin/src/sd/Sd2Card.cpp View File

41
 #include "../Marlin.h"
41
 #include "../Marlin.h"
42
 
42
 
43
 #if ENABLED(SD_CHECK_AND_RETRY)
43
 #if ENABLED(SD_CHECK_AND_RETRY)
44
+  static bool crcSupported = true;
45
+
44
   #ifdef FAST_CRC
46
   #ifdef FAST_CRC
45
     static const uint8_t crctab7[] PROGMEM = {
47
     static const uint8_t crctab7[] PROGMEM = {
46
       0x00,0x09,0x12,0x1b,0x24,0x2d,0x36,0x3f,0x48,0x41,0x5a,0x53,0x6c,0x65,0x7e,0x77,
48
       0x00,0x09,0x12,0x1b,0x24,0x2d,0x36,0x3f,0x48,0x41,0x5a,0x53,0x6c,0x65,0x7e,0x77,
267
   }
269
   }
268
 
270
 
269
 #if ENABLED(SD_CHECK_AND_RETRY)
271
 #if ENABLED(SD_CHECK_AND_RETRY)
270
-  if (cardCommand( CMD59, 1 ) != R1_IDLE_STATE) {
271
-    error(SD_CARD_ERROR_CMD59);
272
-    goto FAIL;
273
-  }
272
+  crcSupported = (cardCommand(CMD59, 1) == R1_IDLE_STATE);
274
 #endif
273
 #endif
275
 
274
 
276
   // check SD version
275
   // check SD version
450
 #if ENABLED(SD_CHECK_AND_RETRY)
449
 #if ENABLED(SD_CHECK_AND_RETRY)
451
   {
450
   {
452
     uint16_t recvCrc = (spiRec() << 8) | spiRec();
451
     uint16_t recvCrc = (spiRec() << 8) | spiRec();
453
-    if (recvCrc != CRC_CCITT(dst, count)) {
452
+    if (crcSupported && recvCrc != CRC_CCITT(dst, count)) {
454
       error(SD_CARD_ERROR_READ_CRC);
453
       error(SD_CARD_ERROR_READ_CRC);
455
       goto FAIL;
454
       goto FAIL;
456
     }
455
     }

+ 1
- 1
Marlin/src/sd/Sd2Card.h View File

71
               SD_CARD_ERROR_WRITE_TIMEOUT = 0x17,       // timeout occurred during write programming
71
               SD_CARD_ERROR_WRITE_TIMEOUT = 0x17,       // timeout occurred during write programming
72
               SD_CARD_ERROR_SCK_RATE = 0x18,            // incorrect rate selected
72
               SD_CARD_ERROR_SCK_RATE = 0x18,            // incorrect rate selected
73
               SD_CARD_ERROR_INIT_NOT_CALLED = 0x19,     // init() not called
73
               SD_CARD_ERROR_INIT_NOT_CALLED = 0x19,     // init() not called
74
-              SD_CARD_ERROR_CMD59 = 0x1A,               // card returned an error for CMD59 (CRC_ON_OFF)
74
+              // 0x1A is unused now, it was: card returned an error for CMD59 (CRC_ON_OFF)
75
               SD_CARD_ERROR_READ_CRC = 0x1B;            // invalid read CRC
75
               SD_CARD_ERROR_READ_CRC = 0x1B;            // invalid read CRC
76
 
76
 
77
 // card types
77
 // card types

Loading…
Cancel
Save