Browse Source

Fix onboard SD card support for Teensy 3.6 & 4.1 (#19593)

bilsef 4 years ago
parent
commit
90801f8815
2 changed files with 20 additions and 0 deletions
  1. 15
    0
      Marlin/src/sd/Sd2Card.cpp
  2. 5
    0
      Marlin/src/sd/Sd2Card.h

+ 15
- 0
Marlin/src/sd/Sd2Card.cpp View File

231
  * The reason for failure can be determined by calling errorCode() and errorData().
231
  * The reason for failure can be determined by calling errorCode() and errorData().
232
  */
232
  */
233
 bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
233
 bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
234
+  #if IS_TEENSY_35_36 || IS_TEENSY_40_41
235
+    chipSelectPin_ = BUILTIN_SDCARD;
236
+    const uint8_t ret = SDHC_CardInit();
237
+    type_ = SDHC_CardGetType();
238
+    return (ret == 0);
239
+  #endif
240
+
234
   errorCode_ = type_ = 0;
241
   errorCode_ = type_ = 0;
235
   chipSelectPin_ = chipSelectPin;
242
   chipSelectPin_ = chipSelectPin;
236
   // 16-bit init start time allows over a minute
243
   // 16-bit init start time allows over a minute
332
  * \return true for success, false for failure.
339
  * \return true for success, false for failure.
333
  */
340
  */
334
 bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) {
341
 bool Sd2Card::readBlock(uint32_t blockNumber, uint8_t* dst) {
342
+  #if IS_TEENSY_35_36 || IS_TEENSY_40_41
343
+    return 0 == SDHC_CardReadBlock(dst, blockNumber);
344
+  #endif
345
+
335
   if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;   // Use address if not SDHC card
346
   if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;   // Use address if not SDHC card
336
 
347
 
337
   #if ENABLED(SD_CHECK_AND_RETRY)
348
   #if ENABLED(SD_CHECK_AND_RETRY)
547
 bool Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
558
 bool Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
548
   if (ENABLED(SDCARD_READONLY)) return false;
559
   if (ENABLED(SDCARD_READONLY)) return false;
549
 
560
 
561
+  #if IS_TEENSY_35_36 || IS_TEENSY_40_41
562
+    return 0 == SDHC_CardWriteBlock(src, blockNumber);
563
+  #endif
564
+
550
   bool success = false;
565
   bool success = false;
551
   if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;   // Use address if not SDHC card
566
   if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;   // Use address if not SDHC card
552
   if (!cardCommand(CMD24, blockNumber)) {
567
   if (!cardCommand(CMD24, blockNumber)) {

+ 5
- 0
Marlin/src/sd/Sd2Card.h View File

84
   #define SOFTWARE_SPI
84
   #define SOFTWARE_SPI
85
 #endif
85
 #endif
86
 
86
 
87
+#if IS_TEENSY_35_36 || IS_TEENSY_40_41
88
+  #include "NXP_SDHC.h"
89
+  #define BUILTIN_SDCARD 254
90
+#endif
91
+
87
 /**
92
 /**
88
  * \class Sd2Card
93
  * \class Sd2Card
89
  * \brief Raw access to SD and SDHC flash memory cards.
94
  * \brief Raw access to SD and SDHC flash memory cards.

Loading…
Cancel
Save