From d29cc8f7bc43c4f27973de9a2e0e9b62c8433eba Mon Sep 17 00:00:00 2001 From: Hans Raaf Date: Thu, 12 Jan 2017 04:24:49 +0100 Subject: [PATCH] Reset watchdog in SD init to prevent reboot If the watchdog is enabled and bootscreen + SD card checks take too long, Marlin may hang at boot time because of the reset loop. We have this happen all the time with the Anet board if no SD card is inserted. --- Marlin/Sd2Card.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Marlin/Sd2Card.cpp b/Marlin/Sd2Card.cpp index 900c73b53..6293d6f9e 100644 --- a/Marlin/Sd2Card.cpp +++ b/Marlin/Sd2Card.cpp @@ -31,6 +31,10 @@ #if ENABLED(SDSUPPORT) #include "Sd2Card.h" +#if ENABLED(USE_WATCHDOG) + #include "watchdog.h" +#endif + //------------------------------------------------------------------------------ #if DISABLED(SOFTWARE_SPI) // functions for hardware SPI @@ -299,6 +303,12 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) { uint16_t t0 = (uint16_t)millis(); uint32_t arg; + // If init takes more than 4s it could trigger + // watchdog leading to a reboot loop. + #if ENABLED(USE_WATCHDOG) + watchdog_reset(); + #endif + // set pin modes pinMode(chipSelectPin_, OUTPUT); chipSelectHigh();