From 5530b99882c90bbc67b69eb18d64743abf4643ab Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 12 Aug 2020 12:46:35 +0300 Subject: [PATCH] Reboot after factory reset --- Firmware/Dcodes.cpp | 13 ++++--------- Firmware/Marlin.h | 2 ++ Firmware/Marlin_main.cpp | 11 ++++++++--- Firmware/bootapp.c | 8 ++++---- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index 1f902c5e..85d78001 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -226,9 +226,7 @@ void dcode_0() LOG("D0 - Reset\n"); if (code_seen('B')) //bootloader { - cli(); - wdt_enable(WDTO_15MS); - while(1); + softReset(); } else //reset { @@ -252,8 +250,7 @@ void dcode_1() cli(); for (int i = 0; i < 8192; i++) eeprom_write_byte((unsigned char*)i, (unsigned char)0xff); - wdt_enable(WDTO_15MS); - while(1); + softReset(); } /*! @@ -420,8 +417,7 @@ void dcode_5() boot_dst_addr = (uint32_t)address; boot_src_addr = (uint32_t)(&data); bootapp_print_vars(); - wdt_enable(WDTO_15MS); - while(1); + softReset(); } while (count) { @@ -467,8 +463,7 @@ void dcode_7() boot_copy_size = (uint16_t)0xc00; boot_src_addr = (uint32_t)0x0003e400; boot_dst_addr = (uint32_t)0x0003f400; - wdt_enable(WDTO_15MS); - while(1); + softReset(); */ } diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 5c03552b..2585d0c8 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -512,4 +512,6 @@ void load_filament_final_feed(); void marlin_wait_for_click(); void raise_z_above(float target, bool plan=true); +void softReset(); + #endif diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 2a261db2..fa02a956 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -762,6 +762,7 @@ static void factory_reset(char level) } } + softReset(); break; @@ -3813,9 +3814,7 @@ void process_commands() #if (defined(WATCHDOG) && (MOTHERBOARD == BOARD_EINSY_1_0a)) boot_app_magic = BOOT_APP_MAGIC; boot_app_flags = BOOT_APP_FLG_RUN; - wdt_enable(WDTO_15MS); - cli(); - while(1); + softReset(); #else //WATCHDOG asm volatile("jmp 0x3E000"); #endif //WATCHDOG @@ -11716,6 +11715,12 @@ void disable_force_z() #endif // TMC2130 } +void softReset() +{ + cli(); + wdt_enable(WDTO_15MS); + while(1); +} void enable_force_z() { diff --git a/Firmware/bootapp.c b/Firmware/bootapp.c index 4fd67db2..c4585af5 100644 --- a/Firmware/bootapp.c +++ b/Firmware/bootapp.c @@ -9,6 +9,8 @@ extern FILE _uartout; #define uartout (&_uartout) +extern void softReset(); + void bootapp_print_vars(void) { fprintf_P(uartout, PSTR("boot_src_addr =0x%08lx\n"), boot_src_addr); @@ -39,8 +41,7 @@ void bootapp_ram2flash(uint16_t rptr, uint16_t fptr, uint16_t size) boot_src_addr = (uint32_t)rptr; boot_dst_addr = (uint32_t)fptr; bootapp_print_vars(); - wdt_enable(WDTO_15MS); - while(1); + softReset(); } void bootapp_reboot_user0(uint8_t reserved) @@ -50,6 +51,5 @@ void bootapp_reboot_user0(uint8_t reserved) boot_app_flags = BOOT_APP_FLG_USER0; boot_reserved = reserved; bootapp_print_vars(); - wdt_enable(WDTO_15MS); - while(1); + softReset(); }