Parcourir la source

🐛 Prevent AVR watchdogpile (#23075)

Skruppy il y a 2 ans
Parent
révision
f53d627750
Aucun compte lié à l'adresse e-mail de l'auteur

+ 3
- 0
Marlin/Configuration_adv.h Voir le fichier

@@ -4224,3 +4224,6 @@
4224 4224
  */
4225 4225
 //#define SOFT_RESET_VIA_SERIAL         // 'KILL' and '^X' commands will soft-reset the controller
4226 4226
 //#define SOFT_RESET_ON_KILL            // Use a digital button to soft-reset the controller after KILL
4227
+
4228
+// Report uncleaned reset reason from register r2 instead of MCUSR. Supported by Optiboot on AVR.
4229
+//#define OPTIBOOT_RESET_REASON

+ 20
- 1
Marlin/src/HAL/AVR/HAL.cpp Voir le fichier

@@ -35,12 +35,31 @@
35 35
 // Public Variables
36 36
 // ------------------------
37 37
 
38
-//uint8_t MCUSR;
38
+// Don't initialize/override variable (which would happen in .init4)
39
+uint8_t reset_reason __attribute__((section(".noinit")));
39 40
 
40 41
 // ------------------------
41 42
 // Public functions
42 43
 // ------------------------
43 44
 
45
+__attribute__((naked))             // Don't output function pro- and epilogue
46
+__attribute__((used))              // Output the function, even if "not used"
47
+__attribute__((section(".init3"))) // Put in an early user definable section
48
+void HAL_save_reset_reason() {
49
+  #if ENABLED(OPTIBOOT_RESET_REASON)
50
+    __asm__ __volatile__(
51
+      A("STS %0, r2")
52
+      : "=m"(reset_reason)
53
+    );
54
+  #else
55
+    reset_reason = MCUSR;
56
+  #endif
57
+
58
+  // Clear within 16ms since WDRF bit enables a 16ms watchdog timer -> Boot loop
59
+  MCUSR = 0;
60
+  wdt_disable();
61
+}
62
+
44 63
 void HAL_init() {
45 64
   // Init Servo Pins
46 65
   #define INIT_SERVO(N) OUT_WRITE(SERVO##N##_PIN, LOW)

+ 3
- 3
Marlin/src/HAL/AVR/HAL.h Voir le fichier

@@ -91,7 +91,7 @@ typedef int8_t pin_t;
91 91
 // Public Variables
92 92
 // ------------------------
93 93
 
94
-//extern uint8_t MCUSR;
94
+extern uint8_t reset_reason;
95 95
 
96 96
 // Serial ports
97 97
 #ifdef USBCON
@@ -152,8 +152,8 @@ void HAL_init();
152 152
 
153 153
 //void _delay_ms(const int delay);
154 154
 
155
-inline void HAL_clear_reset_source() { MCUSR = 0; }
156
-inline uint8_t HAL_get_reset_source() { return MCUSR; }
155
+inline void HAL_clear_reset_source() { }
156
+inline uint8_t HAL_get_reset_source() { return reset_reason; }
157 157
 
158 158
 void HAL_reboot();
159 159
 

+ 5
- 0
Marlin/src/inc/SanityCheck.h Voir le fichier

@@ -2489,6 +2489,11 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
2489 2489
   #error "An encoder button is required or SOFT_RESET_ON_KILL will reset the printer without notice!"
2490 2490
 #endif
2491 2491
 
2492
+// Reset reason for AVR
2493
+#if ENABLED(OPTIBOOT_RESET_REASON) && !defined(__AVR__)
2494
+  #error "OPTIBOOT_RESET_REASON only applies to AVR."
2495
+#endif
2496
+
2492 2497
 /**
2493 2498
  * I2C bus
2494 2499
  */

Chargement…
Annuler
Enregistrer