浏览代码

Merge pull request #9163 from GMagician/2.0.x-SD-issues-fix

[2.0.x] sd issue fix
Scott Lahteine 7 年前
父节点
当前提交
6ba8cf8405
没有帐户链接到提交者的电子邮件
共有 2 个文件被更改,包括 11 次插入11 次删除
  1. 10
    10
      Marlin/src/sd/Sd2Card.cpp
  2. 1
    1
      Marlin/src/sd/Sd2Card.h

+ 10
- 10
Marlin/src/sd/Sd2Card.cpp 查看文件

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
340
       else if (readData(dst, 512))
339
       else if (readData(dst, 512))
341
         return true;
340
         return true;
342
 
341
 
342
+      chipDeselect();
343
       if (!--retryCnt) break;
343
       if (!--retryCnt) break;
344
 
344
 
345
-      chipDeselect();
346
       cardCommand(CMD12, 0); // Try sending a stop command, ignore the result.
345
       cardCommand(CMD12, 0); // Try sending a stop command, ignore the result.
347
       errorCode_ = 0;
346
       errorCode_ = 0;
348
     }
347
     }
348
+    return false;
349
   #else
349
   #else
350
-    if (cardCommand(CMD17, blockNumber))
350
+    if (cardCommand(CMD17, blockNumber)) {
351
       error(SD_CARD_ERROR_CMD17);
351
       error(SD_CARD_ERROR_CMD17);
352
+      chipDeselect();
353
+      return false;
354
+    }
352
     else
355
     else
353
       return readData(dst, 512);
356
       return readData(dst, 512);
354
   #endif
357
   #endif
355
-
356
-  chipDeselect();
357
-  return false;
358
 }
358
 }
359
 
359
 
360
 /**
360
 /**
450
 #if ENABLED(SD_CHECK_AND_RETRY)
450
 #if ENABLED(SD_CHECK_AND_RETRY)
451
   {
451
   {
452
     uint16_t recvCrc = (spiRec() << 8) | spiRec();
452
     uint16_t recvCrc = (spiRec() << 8) | spiRec();
453
-    if (recvCrc != CRC_CCITT(dst, count)) {
453
+    if (crcSupported && recvCrc != CRC_CCITT(dst, count)) {
454
       error(SD_CARD_ERROR_READ_CRC);
454
       error(SD_CARD_ERROR_READ_CRC);
455
       goto FAIL;
455
       goto FAIL;
456
     }
456
     }

+ 1
- 1
Marlin/src/sd/Sd2Card.h 查看文件

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

正在加载...
取消
保存