|
|
@ -234,11 +234,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
|
|
|
|
const millis_t init_timeout = millis() + SD_INIT_TIMEOUT;
|
|
|
|
const millis_t init_timeout = millis() + SD_INIT_TIMEOUT;
|
|
|
|
uint32_t arg;
|
|
|
|
uint32_t arg;
|
|
|
|
|
|
|
|
|
|
|
|
// If init takes more than 4s it could trigger
|
|
|
|
watchdog_refresh(); // In case init takes too long
|
|
|
|
// watchdog leading to a reboot loop.
|
|
|
|
|
|
|
|
#if ENABLED(USE_WATCHDOG)
|
|
|
|
|
|
|
|
watchdog_reset();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set pin modes
|
|
|
|
// Set pin modes
|
|
|
|
extDigitalWrite(chipSelectPin_, HIGH); // For some CPUs pinMode can write the wrong data so init desired data value first
|
|
|
|
extDigitalWrite(chipSelectPin_, HIGH); // For some CPUs pinMode can write the wrong data so init desired data value first
|
|
|
@ -252,10 +248,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
|
|
|
|
// Must supply min of 74 clock cycles with CS high.
|
|
|
|
// Must supply min of 74 clock cycles with CS high.
|
|
|
|
for (uint8_t i = 0; i < 10; i++) spiSend(0xFF);
|
|
|
|
for (uint8_t i = 0; i < 10; i++) spiSend(0xFF);
|
|
|
|
|
|
|
|
|
|
|
|
// Initialization can cause the watchdog to timeout, so reinit it here
|
|
|
|
watchdog_refresh(); // In case init takes too long
|
|
|
|
#if ENABLED(USE_WATCHDOG)
|
|
|
|
|
|
|
|
watchdog_reset();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Command to go idle in SPI mode
|
|
|
|
// Command to go idle in SPI mode
|
|
|
|
while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
|
|
|
|
while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
|
|
|
@ -269,10 +262,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
|
|
|
|
crcSupported = (cardCommand(CMD59, 1) == R1_IDLE_STATE);
|
|
|
|
crcSupported = (cardCommand(CMD59, 1) == R1_IDLE_STATE);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Initialization can cause the watchdog to timeout, so reinit it here
|
|
|
|
watchdog_refresh(); // In case init takes too long
|
|
|
|
#if ENABLED(USE_WATCHDOG)
|
|
|
|
|
|
|
|
watchdog_reset();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check SD version
|
|
|
|
// check SD version
|
|
|
|
for (;;) {
|
|
|
|
for (;;) {
|
|
|
@ -294,10 +284,7 @@ bool Sd2Card::init(const uint8_t sckRateID, const pin_t chipSelectPin) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Initialization can cause the watchdog to timeout, so reinit it here
|
|
|
|
watchdog_refresh(); // In case init takes too long
|
|
|
|
#if ENABLED(USE_WATCHDOG)
|
|
|
|
|
|
|
|
watchdog_reset();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize card and send host supports SDHC if SD2
|
|
|
|
// Initialize card and send host supports SDHC if SD2
|
|
|
|
arg = type() == SD_CARD_TYPE_SD2 ? 0x40000000 : 0;
|
|
|
|
arg = type() == SD_CARD_TYPE_SD2 ? 0x40000000 : 0;
|
|
|
|