Browse Source

Fix interrupts not enabled during setup()

Alex Voinea 2 years ago
parent
commit
c5d406d12f
1 changed files with 6 additions and 4 deletions
  1. 6 4
      Firmware/Marlin_main.cpp

+ 6 - 4
Firmware/Marlin_main.cpp

@@ -84,6 +84,7 @@
 #include "Prusa_farm.h"
 
 #include <avr/wdt.h>
+#include <util/atomic.h>
 #include <avr/pgmspace.h>
 
 #include "Tcodes.h"
@@ -692,10 +693,11 @@ void watchdogEarlyDisable(void) {
     // leaving it enabled when jumping to the program. This could cause another watchdog reset
     // during setup() if not handled properly. So to avoid any issue of this kind, stop the
     // watchdog timer manually.
-    cli();
-    wdt_reset();
-    MCUSR &= ~_BV(WDRF);
-    wdt_disable();
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
+      wdt_reset();
+      MCUSR &= ~_BV(WDRF);
+      wdt_disable();
+    }
 }
 
 void softReset(void) {