Skip to content

Commit 544dd23

Browse files
bilsefvgadreau
authored andcommitted
Fix onboard SD card support for Teensy 3.6 & 4.1 (MarlinFirmware#19593)
1 parent 30995c7 commit 544dd23

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Marlin/src/sd/Sd2Card.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ bool Sd2Card::eraseSingleBlockEnable() {
231231
* The reason for failure can be determined by calling errorCode() and errorData().
232232
*/
233233
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+
234241
errorCode_ = type_ = 0;
235242
chipSelectPin_ = chipSelectPin;
236243
// 16-bit init start time allows over a minute
@@ -332,6 +339,10 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
332339
* \return true for success, false for failure.
333340
*/
334341
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+
335346
if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9; // Use address if not SDHC card
336347

337348
#if ENABLED(SD_CHECK_AND_RETRY)
@@ -547,6 +558,10 @@ bool Sd2Card::waitNotBusy(const millis_t timeout_ms) {
547558
bool Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
548559
if (ENABLED(SDCARD_READONLY)) return false;
549560

561+
#if IS_TEENSY_35_36 || IS_TEENSY_40_41
562+
return 0 == SDHC_CardWriteBlock(src, blockNumber);
563+
#endif
564+
550565
bool success = false;
551566
if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9; // Use address if not SDHC card
552567
if (!cardCommand(CMD24, blockNumber)) {

Marlin/src/sd/Sd2Card.h

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ uint8_t const SD_CARD_TYPE_SD1 = 1, // Standard capacity V1
8484
#define SOFTWARE_SPI
8585
#endif
8686

87+
#if IS_TEENSY_35_36 || IS_TEENSY_40_41
88+
#include "NXP_SDHC.h"
89+
#define BUILTIN_SDCARD 254
90+
#endif
91+
8792
/**
8893
* \class Sd2Card
8994
* \brief Raw access to SD and SDHC flash memory cards.

0 commit comments

Comments
 (0)