Skip to content

Commit

Permalink
WDR crash initial
Browse files Browse the repository at this point in the history
  • Loading branch information
leptun committed Jun 9, 2021
1 parent 8c3d76f commit 1e786c7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 8 additions & 1 deletion Firmware/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1811,6 +1811,12 @@ static void lcd_dump_memory()
xfdump_dump();
lcd_return_to_status();
}

static void lcd_wdr_crash()
{
while (1);
}

#endif


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
23 changes: 15 additions & 8 deletions Firmware/xflash_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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);
}


Expand Down Expand Up @@ -79,20 +87,20 @@ 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),
(uint8_t*)RAMSTART, RAMSIZE);
}


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();
Expand All @@ -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
9 changes: 8 additions & 1 deletion Firmware/xflash_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Firmware/xflash_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Firmware/xyzcal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1e786c7

Please sign in to comment.