fix watchdog not getting disabled on user app boot

This commit is contained in:
Alex Voinea 2022-12-16 16:01:29 +01:00
parent d80e32fa31
commit d43a7da20d
1 changed files with 6 additions and 3 deletions

View File

@ -685,17 +685,18 @@ void failstats_reset_print()
eeprom_update_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL, 0); eeprom_update_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL, 0);
} }
extern "C" { void watchdogEarlyDisable(void) {
void __attribute__ ((naked)) __attribute__ ((section (".init3"))) stopWatchdogOnInit(void) {
// Regardless if the watchdog support is enabled or not, disable the watchdog very early // Regardless if the watchdog support is enabled or not, disable the watchdog very early
// after the program starts since there's no danger in doing this. // after the program starts since there's no danger in doing this.
// The reason for this is because old bootloaders might not handle the watchdog timer at all, // The reason for this is because old bootloaders might not handle the watchdog timer at all,
// leaving it enabled when jumping to the program. This could cause another watchdog reset // 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 // during setup() if not handled properly. So to avoid any issue of this kind, stop the
// watchdog timer manually. // watchdog timer manually.
cli();
wdt_reset();
MCUSR &= ~_BV(WDRF);
wdt_disable(); wdt_disable();
} }
}
void softReset(void) { void softReset(void) {
cli(); cli();
@ -1063,6 +1064,8 @@ static void xflash_err_msg()
// are initialized by the main() routine provided by the Arduino framework. // are initialized by the main() routine provided by the Arduino framework.
void setup() void setup()
{ {
watchdogEarlyDisable();
timer2_init(); // enables functional millis timer2_init(); // enables functional millis