Parcourir la source

Merge pull request #6 from leptun/improve_d2

WDT crash detection
Yuri D'Elia il y a 3 ans
Parent
commit
3f7b9b42b2

+ 5 - 6
Firmware/Dcodes.cpp

@@ -72,7 +72,7 @@ enum class dcode_mem_t:uint8_t { sram, eeprom, progmem, xflash };
 
 void print_mem(daddr_t address, daddr_t count, dcode_mem_t type, uint8_t countperline = 16)
 {
-#if defined(DEBUG_DCODE6) || defined(DEBUG_DCODES)
+#if defined(DEBUG_DCODE6) || defined(DEBUG_DCODES) || defined(XFLASH_DUMP)
     if(type == dcode_mem_t::xflash)
         XFLASH_SPI_ENTER();
 #endif
@@ -89,7 +89,7 @@ void print_mem(daddr_t address, daddr_t count, dcode_mem_t type, uint8_t countpe
 			case dcode_mem_t::sram: data = *((uint8_t*)address); break;
 			case dcode_mem_t::eeprom: data = eeprom_read_byte((uint8_t*)address); break;
 			case dcode_mem_t::progmem: break;
-#if defined(DEBUG_DCODE6) || defined(DEBUG_DCODES)
+#if defined(DEBUG_DCODE6) || defined(DEBUG_DCODES) || defined(XFLASH_DUMP)
             case dcode_mem_t::xflash: xflash_rd_data(address, &data, 1); break;
 #else
             case dcode_mem_t::xflash: break;
@@ -935,9 +935,9 @@ void dcode_20()
         xfdump_full_dump_and_reset();
     else
     {
-        unsigned long ts = millis();
+        unsigned long ts = _millis();
         xfdump_dump();
-        ts = millis() - ts;
+        ts = _millis() - ts;
         DBG(_N("dump completed in %lums\n"), ts);
     }
 }
@@ -950,8 +950,7 @@ void dcode_21()
     {
         KEEPALIVE_STATE(NOT_BUSY);
         DBG(_N("D21 - read crash dump\n"));
-        print_mem(DUMP_OFFSET  + offsetof(dump_t, data),
-                  DUMP_SIZE, dcode_mem_t::xflash);
+        print_mem(DUMP_OFFSET, sizeof(dump_t), dcode_mem_t::xflash);
     }
 }
 

+ 3 - 0
Firmware/Marlin_main.cpp

@@ -1667,6 +1667,9 @@ void setup()
   KEEPALIVE_STATE(NOT_BUSY);
 #ifdef WATCHDOG
   wdt_enable(WDTO_4S);
+#ifdef XFLASH_DUMP
+  WDTCSR |= (1 << WDIE);
+#endif //XFLASH_DUMP
 #endif //WATCHDOG
 }
 

+ 8 - 1
Firmware/ultralcd.cpp

@@ -1811,6 +1811,12 @@ static void lcd_dump_memory()
     xfdump_dump();
     lcd_return_to_status();
 }
+
+static void lcd_wdr_crash()
+{
+    while (1);
+}
+
 #endif
 
 
@@ -2007,6 +2013,7 @@ static void lcd_support_menu()
 
 #ifdef MENU_DUMP
     MENU_ITEM_FUNCTION_P(_i("Dump memory"), lcd_dump_memory);
+    MENU_ITEM_FUNCTION_P(PSTR("WDR crash"), lcd_wdr_crash);
 #endif
 #ifdef DEBUG_BUILD
   MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);////MSG_DEBUG c=18
@@ -6704,7 +6711,7 @@ static void lcd_main_menu()
 void stack_error() {
     WRITE(BEEPER, HIGH);
     eeprom_update_byte((uint8_t*)EEPROM_CRASH_ACKNOWLEDGED, 0);
-    xfdump_full_dump_and_reset(true);
+    xfdump_full_dump_and_reset(dump_crash_source::stack_error);
 }
 #else
 void stack_error() {

+ 15 - 8
Firmware/xflash_dump.cpp

@@ -6,6 +6,14 @@
 #include "xflash_dump.h"
 #ifdef XFLASH_DUMP
 #include "xflash.h"
+#include "Marlin.h"
+
+ISR(WDT_vect)
+{
+    WRITE(BEEPER, 1);
+    eeprom_update_byte((uint8_t*)EEPROM_CRASH_ACKNOWLEDGED, 0);
+    xfdump_full_dump_and_reset(dump_crash_source::watchdog);
+}
 
 bool xfdump_check_state()
 {
@@ -25,10 +33,10 @@ bool xfdump_check_crash()
     if(!xfdump_check_state())
         return false;
 
-    uint8_t crash;
-    xflash_rd_data(DUMP_OFFSET + offsetof(dump_t, header.crash),
+    dump_crash_source crash;
+    xflash_rd_data(DUMP_OFFSET + offsetof(dump_t, header.crash_type),
                    (uint8_t*)&crash, sizeof(crash));
-    return crash;
+    return (crash != dump_crash_source::manual);
 }
 
 
@@ -79,7 +87,7 @@ void xfdump_dump()
     dump_header_t buf;
     buf.magic = DUMP_MAGIC;
     buf.regs_present = false;
-    buf.crash = false;
+    buf.crash_type = (uint8_t)dump_crash_source::manual;
 
     // write sram only
     xfdump_dump_core(buf, DUMP_OFFSET + offsetof(dump_t, data.sram),
@@ -87,12 +95,12 @@ void xfdump_dump()
 }
 
 
-void xfdump_full_dump_and_reset(bool crash)
+void xfdump_full_dump_and_reset(dump_crash_source crash)
 {
     dump_header_t buf;
     buf.magic = DUMP_MAGIC;
     buf.regs_present = true;
-    buf.crash = crash;
+    buf.crash_type = (uint8_t)crash;
 
     // disable interrupts for a cleaner register dump
     cli();
@@ -101,7 +109,6 @@ void xfdump_full_dump_and_reset(bool crash)
     xfdump_dump_core(buf, DUMP_OFFSET + offsetof(dump_t, data), 0, RAMEND);
 
     // force a reset soon
-    wdt_enable(0);
-    while(true);
+    softReset();
 }
 #endif

+ 8 - 1
Firmware/xflash_dump.h

@@ -8,7 +8,14 @@ bool xfdump_check_state();  // return true if a dump is present
 bool xfdump_check_crash();  // return true if a dump is present and is a crash dump
 void xfdump_dump();         // create a new SRAM memory dump
 
+enum class dump_crash_source : uint8_t
+{
+    manual = 0,
+    stack_error,
+    watchdog,
+};
+
 // create a new dump containing registers and SRAM, then reset
-void xfdump_full_dump_and_reset(bool crash = false);
+void xfdump_full_dump_and_reset(dump_crash_source crash = dump_crash_source::manual);
 
 #endif

+ 1 - 1
Firmware/xflash_layout.h

@@ -20,7 +20,7 @@ struct dump_header_t
     uint32_t magic;
 
     uint8_t regs_present; // true when the lower segment containing registers is present
-    uint8_t crash;        // true if triggered by EMERGENCY_DUMP
+    uint8_t crash_type; // uses values from dump_crash_source
 };
 
 struct dump_data_t

+ 3 - 0
Firmware/xyzcal.cpp

@@ -163,6 +163,9 @@ void xyzcal_meassure_leave(void)
 	ENABLE_STEPPER_DRIVER_INTERRUPT();
 #ifdef WATCHDOG
 	wdt_enable(WDTO_4S);
+#ifdef XFLASH_DUMP
+	WDTCSR |= (1 << WDIE);
+#endif //XFLASH_DUMP
 #endif //WATCHDOG
 	sm4_stop_cb = 0;
 	sm4_update_pos_cb = 0;