♻️ Move watchdog to MarlinHAL
This commit is contained in:
parent
209c792ef7
commit
07cd248b91
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "HAL.h"
|
#include "HAL.h"
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
|
||||||
#ifdef USBCON
|
#ifdef USBCON
|
||||||
DefaultSerial1 MSerial0(false, Serial);
|
DefaultSerial1 MSerial0(false, Serial);
|
||||||
|
@ -88,6 +89,58 @@ void MarlinHAL::reboot() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
// Watchdog Timer
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
#include "../../MarlinCore.h"
|
||||||
|
|
||||||
|
// Initialize watchdog with 8s timeout, if possible. Otherwise, make it 4s.
|
||||||
|
void MarlinHAL::watchdog_init() {
|
||||||
|
#if ENABLED(WATCHDOG_DURATION_8S) && defined(WDTO_8S)
|
||||||
|
#define WDTO_NS WDTO_8S
|
||||||
|
#else
|
||||||
|
#define WDTO_NS WDTO_4S
|
||||||
|
#endif
|
||||||
|
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
||||||
|
// Enable the watchdog timer, but only for the interrupt.
|
||||||
|
// Take care, as this requires the correct order of operation, with interrupts disabled.
|
||||||
|
// See the datasheet of any AVR chip for details.
|
||||||
|
wdt_reset();
|
||||||
|
cli();
|
||||||
|
_WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
|
||||||
|
_WD_CONTROL_REG = _BV(WDIE) | (WDTO_NS & 0x07) | ((WDTO_NS & 0x08) << 2); // WDTO_NS directly does not work. bit 0-2 are consecutive in the register but the highest value bit is at bit 5
|
||||||
|
// So worked for up to WDTO_2S
|
||||||
|
sei();
|
||||||
|
wdt_reset();
|
||||||
|
#else
|
||||||
|
wdt_enable(WDTO_NS); // The function handles the upper bit correct.
|
||||||
|
#endif
|
||||||
|
//delay(10000); // test it!
|
||||||
|
}
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//=================================== ISR ===================================
|
||||||
|
//===========================================================================
|
||||||
|
|
||||||
|
// Watchdog timer interrupt, called if main program blocks >4sec and manual reset is enabled.
|
||||||
|
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
||||||
|
ISR(WDT_vect) {
|
||||||
|
sei(); // With the interrupt driven serial we need to allow interrupts.
|
||||||
|
SERIAL_ERROR_MSG(STR_WATCHDOG_FIRED);
|
||||||
|
minkill(); // interrupt-safe final kill and infinite loop
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Reset watchdog. MUST be called at least every 4 seconds after the
|
||||||
|
// first watchdog_init or AVR will go into emergency procedures.
|
||||||
|
void MarlinHAL::watchdog_refresh() { wdt_reset(); }
|
||||||
|
|
||||||
|
#endif // USE_WATCHDOG
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Free Memory Accessor
|
// Free Memory Accessor
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "../shared/Marduino.h"
|
#include "../shared/Marduino.h"
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
|
||||||
#ifdef USBCON
|
#ifdef USBCON
|
||||||
|
@ -185,6 +184,10 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
static void init(); // Called early in setup()
|
static void init(); // Called early in setup()
|
||||||
static void init_board() {} // Called less early in setup()
|
static void init_board() {} // Called less early in setup()
|
||||||
static void reboot(); // Restart the firmware from 0x0
|
static void reboot(); // Restart the firmware from 0x0
|
||||||
|
|
|
@ -1,70 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifdef __AVR__
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#include "../../MarlinCore.h"
|
|
||||||
|
|
||||||
// Initialize watchdog with 8s timeout, if possible. Otherwise, make it 4s.
|
|
||||||
void watchdog_init() {
|
|
||||||
#if ENABLED(WATCHDOG_DURATION_8S) && defined(WDTO_8S)
|
|
||||||
#define WDTO_NS WDTO_8S
|
|
||||||
#else
|
|
||||||
#define WDTO_NS WDTO_4S
|
|
||||||
#endif
|
|
||||||
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
|
||||||
// Enable the watchdog timer, but only for the interrupt.
|
|
||||||
// Take care, as this requires the correct order of operation, with interrupts disabled.
|
|
||||||
// See the datasheet of any AVR chip for details.
|
|
||||||
wdt_reset();
|
|
||||||
cli();
|
|
||||||
_WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
|
|
||||||
_WD_CONTROL_REG = _BV(WDIE) | (WDTO_NS & 0x07) | ((WDTO_NS & 0x08) << 2); // WDTO_NS directly does not work. bit 0-2 are consecutive in the register but the highest value bit is at bit 5
|
|
||||||
// So worked for up to WDTO_2S
|
|
||||||
sei();
|
|
||||||
wdt_reset();
|
|
||||||
#else
|
|
||||||
wdt_enable(WDTO_NS); // The function handles the upper bit correct.
|
|
||||||
#endif
|
|
||||||
//delay(10000); // test it!
|
|
||||||
}
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
//=================================== ISR ===================================
|
|
||||||
//===========================================================================
|
|
||||||
|
|
||||||
// Watchdog timer interrupt, called if main program blocks >4sec and manual reset is enabled.
|
|
||||||
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
|
||||||
ISR(WDT_vect) {
|
|
||||||
sei(); // With the interrupt driven serial we need to allow interrupts.
|
|
||||||
SERIAL_ERROR_MSG(STR_WATCHDOG_FIRED);
|
|
||||||
minkill(); // interrupt-safe final kill and infinite loop
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // USE_WATCHDOG
|
|
||||||
#endif // __AVR__
|
|
|
@ -1,31 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <avr/wdt.h>
|
|
||||||
|
|
||||||
// Initialize watchdog with a 4 second interrupt time
|
|
||||||
void watchdog_init();
|
|
||||||
|
|
||||||
// Reset watchdog. MUST be called at least every 4 seconds after the
|
|
||||||
// first watchdog_init or AVR will go into emergency procedures.
|
|
||||||
inline void HAL_watchdog_refresh() { wdt_reset(); }
|
|
|
@ -25,7 +25,7 @@
|
||||||
#ifdef ARDUINO_ARCH_SAM
|
#ifdef ARDUINO_ARCH_SAM
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
#include "HAL.h"
|
#include "../../MarlinCore.h"
|
||||||
|
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include "usb/usb_task.h"
|
#include "usb/usb_task.h"
|
||||||
|
@ -73,6 +73,99 @@ uint8_t MarlinHAL::get_reset_source() {
|
||||||
|
|
||||||
void MarlinHAL::reboot() { rstc_start_software_reset(RSTC); }
|
void MarlinHAL::reboot() { rstc_start_software_reset(RSTC); }
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
// Watchdog Timer
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
// Initialize watchdog - On SAM3X, Watchdog was already configured
|
||||||
|
// and enabled or disabled at startup, so no need to reconfigure it
|
||||||
|
// here.
|
||||||
|
void MarlinHAL::watchdog_init() { WDT_Restart(WDT); } // Reset watchdog to start clean
|
||||||
|
|
||||||
|
// Reset watchdog. MUST be called at least every 4 seconds after the
|
||||||
|
// first watchdog_init or AVR will go into emergency procedures.
|
||||||
|
void MarlinHAL::watchdog_refresh() { watchdogReset(); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Override Arduino runtime to either config or disable the watchdog
|
||||||
|
//
|
||||||
|
// We need to configure the watchdog as soon as possible in the boot
|
||||||
|
// process, because watchdog initialization at hardware reset on SAM3X8E
|
||||||
|
// is unreliable, and there is risk of unintended resets if we delay
|
||||||
|
// that initialization to a later time.
|
||||||
|
void watchdogSetup() {
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
// 4 seconds timeout
|
||||||
|
uint32_t timeout = TERN(WATCHDOG_DURATION_8S, 8000, 4000);
|
||||||
|
|
||||||
|
// Calculate timeout value in WDT counter ticks: This assumes
|
||||||
|
// the slow clock is running at 32.768 kHz watchdog
|
||||||
|
// frequency is therefore 32768 / 128 = 256 Hz
|
||||||
|
timeout = (timeout << 8) / 1000;
|
||||||
|
if (timeout == 0)
|
||||||
|
timeout = 1;
|
||||||
|
else if (timeout > 0xFFF)
|
||||||
|
timeout = 0xFFF;
|
||||||
|
|
||||||
|
// We want to enable the watchdog with the specified timeout
|
||||||
|
uint32_t value =
|
||||||
|
WDT_MR_WDV(timeout) | // With the specified timeout
|
||||||
|
WDT_MR_WDD(timeout) | // and no invalid write window
|
||||||
|
#if !(SAMV70 || SAMV71 || SAME70 || SAMS70)
|
||||||
|
WDT_MR_WDRPROC | // WDT fault resets processor only - We want
|
||||||
|
// to keep PIO controller state
|
||||||
|
#endif
|
||||||
|
WDT_MR_WDDBGHLT | // WDT stops in debug state.
|
||||||
|
WDT_MR_WDIDLEHLT; // WDT stops in idle state.
|
||||||
|
|
||||||
|
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
||||||
|
// We enable the watchdog timer, but only for the interrupt.
|
||||||
|
|
||||||
|
// Configure WDT to only trigger an interrupt
|
||||||
|
value |= WDT_MR_WDFIEN; // Enable WDT fault interrupt.
|
||||||
|
|
||||||
|
// Disable WDT interrupt (just in case, to avoid triggering it!)
|
||||||
|
NVIC_DisableIRQ(WDT_IRQn);
|
||||||
|
|
||||||
|
// We NEED memory barriers to ensure Interrupts are actually disabled!
|
||||||
|
// ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
|
||||||
|
// Initialize WDT with the given parameters
|
||||||
|
WDT_Enable(WDT, value);
|
||||||
|
|
||||||
|
// Configure and enable WDT interrupt.
|
||||||
|
NVIC_ClearPendingIRQ(WDT_IRQn);
|
||||||
|
NVIC_SetPriority(WDT_IRQn, 0); // Use highest priority, so we detect all kinds of lockups
|
||||||
|
NVIC_EnableIRQ(WDT_IRQn);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
// a WDT fault triggers a reset
|
||||||
|
value |= WDT_MR_WDRSTEN;
|
||||||
|
|
||||||
|
// Initialize WDT with the given parameters
|
||||||
|
WDT_Enable(WDT, value);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Reset the watchdog
|
||||||
|
WDT_Restart(WDT);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
// Make sure to completely disable the Watchdog
|
||||||
|
WDT_Disable(WDT);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Free Memory Accessor
|
// Free Memory Accessor
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include "../shared/math_32bit.h"
|
#include "../shared/math_32bit.h"
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -176,9 +175,13 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
static void init(); // Called early in setup()
|
static void init(); // Called early in setup()
|
||||||
static void init_board(); // Called less early in setup()
|
static void init_board(); // Called less early in setup()
|
||||||
static void reboot(); // Software reset
|
static void reboot(); // Restart the firmware
|
||||||
|
|
||||||
// Interrupts
|
// Interrupts
|
||||||
static bool isr_state() { return !__get_PRIMASK(); }
|
static bool isr_state() { return !__get_PRIMASK(); }
|
||||||
|
|
|
@ -1,114 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifdef ARDUINO_ARCH_SAM
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
#include "../../MarlinCore.h"
|
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
// Override Arduino runtime to either config or disable the watchdog
|
|
||||||
//
|
|
||||||
// We need to configure the watchdog as soon as possible in the boot
|
|
||||||
// process, because watchdog initialization at hardware reset on SAM3X8E
|
|
||||||
// is unreliable, and there is risk of unintended resets if we delay
|
|
||||||
// that initialization to a later time.
|
|
||||||
void watchdogSetup() {
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
// 4 seconds timeout
|
|
||||||
uint32_t timeout = TERN(WATCHDOG_DURATION_8S, 8000, 4000);
|
|
||||||
|
|
||||||
// Calculate timeout value in WDT counter ticks: This assumes
|
|
||||||
// the slow clock is running at 32.768 kHz watchdog
|
|
||||||
// frequency is therefore 32768 / 128 = 256 Hz
|
|
||||||
timeout = (timeout << 8) / 1000;
|
|
||||||
if (timeout == 0)
|
|
||||||
timeout = 1;
|
|
||||||
else if (timeout > 0xFFF)
|
|
||||||
timeout = 0xFFF;
|
|
||||||
|
|
||||||
// We want to enable the watchdog with the specified timeout
|
|
||||||
uint32_t value =
|
|
||||||
WDT_MR_WDV(timeout) | // With the specified timeout
|
|
||||||
WDT_MR_WDD(timeout) | // and no invalid write window
|
|
||||||
#if !(SAMV70 || SAMV71 || SAME70 || SAMS70)
|
|
||||||
WDT_MR_WDRPROC | // WDT fault resets processor only - We want
|
|
||||||
// to keep PIO controller state
|
|
||||||
#endif
|
|
||||||
WDT_MR_WDDBGHLT | // WDT stops in debug state.
|
|
||||||
WDT_MR_WDIDLEHLT; // WDT stops in idle state.
|
|
||||||
|
|
||||||
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
|
||||||
// We enable the watchdog timer, but only for the interrupt.
|
|
||||||
|
|
||||||
// Configure WDT to only trigger an interrupt
|
|
||||||
value |= WDT_MR_WDFIEN; // Enable WDT fault interrupt.
|
|
||||||
|
|
||||||
// Disable WDT interrupt (just in case, to avoid triggering it!)
|
|
||||||
NVIC_DisableIRQ(WDT_IRQn);
|
|
||||||
|
|
||||||
// We NEED memory barriers to ensure Interrupts are actually disabled!
|
|
||||||
// ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
|
|
||||||
__DSB();
|
|
||||||
__ISB();
|
|
||||||
|
|
||||||
// Initialize WDT with the given parameters
|
|
||||||
WDT_Enable(WDT, value);
|
|
||||||
|
|
||||||
// Configure and enable WDT interrupt.
|
|
||||||
NVIC_ClearPendingIRQ(WDT_IRQn);
|
|
||||||
NVIC_SetPriority(WDT_IRQn, 0); // Use highest priority, so we detect all kinds of lockups
|
|
||||||
NVIC_EnableIRQ(WDT_IRQn);
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// a WDT fault triggers a reset
|
|
||||||
value |= WDT_MR_WDRSTEN;
|
|
||||||
|
|
||||||
// Initialize WDT with the given parameters
|
|
||||||
WDT_Enable(WDT, value);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Reset the watchdog
|
|
||||||
WDT_Restart(WDT);
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// Make sure to completely disable the Watchdog
|
|
||||||
WDT_Disable(WDT);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
// Initialize watchdog - On SAM3X, Watchdog was already configured
|
|
||||||
// and enabled or disabled at startup, so no need to reconfigure it
|
|
||||||
// here.
|
|
||||||
void watchdog_init() {
|
|
||||||
// Reset watchdog to start clean
|
|
||||||
WDT_Restart(WDT);
|
|
||||||
}
|
|
||||||
#endif // USE_WATCHDOG
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,33 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// Arduino Due core now has watchdog support
|
|
||||||
|
|
||||||
#include "HAL.h"
|
|
||||||
|
|
||||||
// Initialize watchdog with a 4 second interrupt time
|
|
||||||
void watchdog_init();
|
|
||||||
|
|
||||||
// Reset watchdog. MUST be called at least every 4 seconds after the
|
|
||||||
// first watchdog_init or AVR will go into emergency procedures.
|
|
||||||
inline void HAL_watchdog_refresh() { watchdogReset(); }
|
|
|
@ -179,6 +179,31 @@ void _delay_ms(int delay_ms) { delay(delay_ms); }
|
||||||
// return free memory between end of heap (or end bss) and whatever is current
|
// return free memory between end of heap (or end bss) and whatever is current
|
||||||
int MarlinHAL::freeMemory() { return ESP.getFreeHeap(); }
|
int MarlinHAL::freeMemory() { return ESP.getFreeHeap(); }
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
// Watchdog Timer
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
esp_err_t esp_task_wdt_reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void watchdogSetup() {
|
||||||
|
// do whatever. don't remove this function.
|
||||||
|
}
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_init() {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset watchdog.
|
||||||
|
void MarlinHAL::watchdog_refresh() { esp_task_wdt_reset(); }
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// ADC
|
// ADC
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
|
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
#include "i2s.h"
|
#include "i2s.h"
|
||||||
|
|
||||||
#if ENABLED(WIFISUPPORT)
|
#if ENABLED(WIFISUPPORT)
|
||||||
|
@ -172,6 +171,10 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
static void init() {} // Called early in setup()
|
static void init() {} // Called early in setup()
|
||||||
static void init_board(); // Called less early in setup()
|
static void init_board(); // Called less early in setup()
|
||||||
static void reboot(); // Restart the firmware
|
static void reboot(); // Restart the firmware
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
|
|
||||||
|
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
void watchdogSetup() {
|
|
||||||
// do whatever. don't remove this function.
|
|
||||||
}
|
|
||||||
|
|
||||||
void watchdog_init() {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // USE_WATCHDOG
|
|
||||||
|
|
||||||
#endif // ARDUINO_ARCH_ESP32
|
|
|
@ -1,38 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
esp_err_t esp_task_wdt_reset();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Initialize watchdog with a 4 second interrupt time
|
|
||||||
void watchdog_init();
|
|
||||||
|
|
||||||
// Reset watchdog.
|
|
||||||
inline void HAL_watchdog_refresh() { esp_task_wdt_reset(); }
|
|
|
@ -45,7 +45,3 @@ extern MarlinHAL hal;
|
||||||
#ifndef PGMSTR
|
#ifndef PGMSTR
|
||||||
#define PGMSTR(NAM,STR) const char NAM[] = STR
|
#define PGMSTR(NAM,STR) const char NAM[] = STR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline void watchdog_refresh() {
|
|
||||||
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
|
|
||||||
}
|
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../inc/MarlinConfigPre.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
@ -29,12 +31,10 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include "hardware/Clock.h"
|
#include "hardware/Clock.h"
|
||||||
|
|
||||||
#include "../shared/Marduino.h"
|
#include "../shared/Marduino.h"
|
||||||
#include "../shared/math_32bit.h"
|
#include "../shared/math_32bit.h"
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
@ -106,6 +106,10 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() {}
|
||||||
|
static void watchdog_refresh() {}
|
||||||
|
|
||||||
static void init() {} // Called early in setup()
|
static void init() {} // Called early in setup()
|
||||||
static void init_board() {} // Called less early in setup()
|
static void init_board() {} // Called less early in setup()
|
||||||
static void reboot(); // Reset the application state and GPIO
|
static void reboot(); // Reset the application state and GPIO
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifdef __PLAT_LINUX__
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
|
|
||||||
|
|
||||||
void watchdog_init() {}
|
|
||||||
void HAL_watchdog_refresh() {}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // __PLAT_LINUX__
|
|
|
@ -1,25 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
void watchdog_init();
|
|
||||||
void HAL_watchdog_refresh();
|
|
|
@ -25,10 +25,6 @@
|
||||||
#include "../shared/Delay.h"
|
#include "../shared/Delay.h"
|
||||||
#include "../../../gcode/parser.h"
|
#include "../../../gcode/parser.h"
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
#include "watchdog.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DefaultSerial1 USBSerial(false, UsbSerial);
|
DefaultSerial1 USBSerial(false, UsbSerial);
|
||||||
|
|
||||||
uint32_t MarlinHAL::adc_result = 0;
|
uint32_t MarlinHAL::adc_result = 0;
|
||||||
|
@ -61,9 +57,7 @@ uint8_t MarlinHAL::get_reset_source() {
|
||||||
return RST_POWER_ON;
|
return RST_POWER_ON;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarlinHAL::clear_reset_source() {
|
void MarlinHAL::clear_reset_source() { watchdog_clear_timeout_flag(); }
|
||||||
TERN_(USE_WATCHDOG, watchdog_clear_timeout_flag());
|
|
||||||
}
|
|
||||||
|
|
||||||
void flashFirmware(const int16_t) {
|
void flashFirmware(const int16_t) {
|
||||||
delay(500); // Give OS time to disconnect
|
delay(500); // Give OS time to disconnect
|
||||||
|
@ -72,6 +66,52 @@ void flashFirmware(const int16_t) {
|
||||||
hal.reboot();
|
hal.reboot();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
#include <lpc17xx_wdt.h>
|
||||||
|
|
||||||
|
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_init() {
|
||||||
|
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
||||||
|
// We enable the watchdog timer, but only for the interrupt.
|
||||||
|
|
||||||
|
// Configure WDT to only trigger an interrupt
|
||||||
|
// Disable WDT interrupt (just in case, to avoid triggering it!)
|
||||||
|
NVIC_DisableIRQ(WDT_IRQn);
|
||||||
|
|
||||||
|
// We NEED memory barriers to ensure Interrupts are actually disabled!
|
||||||
|
// ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
|
||||||
|
__DSB();
|
||||||
|
__ISB();
|
||||||
|
|
||||||
|
// Configure WDT to only trigger an interrupt
|
||||||
|
// Initialize WDT with the given parameters
|
||||||
|
WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_INT_ONLY);
|
||||||
|
|
||||||
|
// Configure and enable WDT interrupt.
|
||||||
|
NVIC_ClearPendingIRQ(WDT_IRQn);
|
||||||
|
NVIC_SetPriority(WDT_IRQn, 0); // Use highest priority, so we detect all kinds of lockups
|
||||||
|
NVIC_EnableIRQ(WDT_IRQn);
|
||||||
|
#else
|
||||||
|
WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET);
|
||||||
|
#endif
|
||||||
|
WDT_Start(WDT_TIMEOUT_US);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_refresh() {
|
||||||
|
WDT_Feed();
|
||||||
|
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
|
||||||
|
TOGGLE(LED_PIN); // heartbeat indicator
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timeout state
|
||||||
|
bool MarlinHAL::watchdog_timed_out() { return TEST(WDT_ReadTimeOutFlag(), 0); }
|
||||||
|
void MarlinHAL::watchdog_clear_timeout_flag() { WDT_ClrTimeOutFlag(); }
|
||||||
|
|
||||||
|
#endif // USE_WATCHDOG
|
||||||
|
|
||||||
// For M42/M43, scan command line for pin code
|
// For M42/M43, scan command line for pin code
|
||||||
// return index into pin map array if found and the pin is valid.
|
// return index into pin map array if found and the pin is valid.
|
||||||
// return dval if not found or not a valid pin.
|
// return dval if not found or not a valid pin.
|
||||||
|
|
|
@ -38,7 +38,6 @@ extern "C" volatile uint32_t _millis;
|
||||||
#include "../shared/math_32bit.h"
|
#include "../shared/math_32bit.h"
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
#include "MarlinSerial.h"
|
#include "MarlinSerial.h"
|
||||||
|
|
||||||
#include <adc.h>
|
#include <adc.h>
|
||||||
|
@ -210,6 +209,12 @@ public:
|
||||||
|
|
||||||
static void delay_ms(const int ms) { _delay_ms(ms); }
|
static void delay_ms(const int ms) { _delay_ms(ms); }
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static bool watchdog_timed_out() IF_DISABLED(USE_WATCHDOG, { return false; });
|
||||||
|
static void watchdog_clear_timeout_flag() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
// Tasks, called from idle()
|
// Tasks, called from idle()
|
||||||
static void idletask();
|
static void idletask();
|
||||||
|
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifdef TARGET_LPC1768
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
#include <lpc17xx_wdt.h>
|
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
|
|
||||||
|
|
||||||
void watchdog_init() {
|
|
||||||
#if ENABLED(WATCHDOG_RESET_MANUAL)
|
|
||||||
// We enable the watchdog timer, but only for the interrupt.
|
|
||||||
|
|
||||||
// Configure WDT to only trigger an interrupt
|
|
||||||
// Disable WDT interrupt (just in case, to avoid triggering it!)
|
|
||||||
NVIC_DisableIRQ(WDT_IRQn);
|
|
||||||
|
|
||||||
// We NEED memory barriers to ensure Interrupts are actually disabled!
|
|
||||||
// ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the )
|
|
||||||
__DSB();
|
|
||||||
__ISB();
|
|
||||||
|
|
||||||
// Configure WDT to only trigger an interrupt
|
|
||||||
// Initialize WDT with the given parameters
|
|
||||||
WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_INT_ONLY);
|
|
||||||
|
|
||||||
// Configure and enable WDT interrupt.
|
|
||||||
NVIC_ClearPendingIRQ(WDT_IRQn);
|
|
||||||
NVIC_SetPriority(WDT_IRQn, 0); // Use highest priority, so we detect all kinds of lockups
|
|
||||||
NVIC_EnableIRQ(WDT_IRQn);
|
|
||||||
#else
|
|
||||||
WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET);
|
|
||||||
#endif
|
|
||||||
WDT_Start(WDT_TIMEOUT_US);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_watchdog_refresh() {
|
|
||||||
WDT_Feed();
|
|
||||||
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
|
|
||||||
TOGGLE(LED_PIN); // heartbeat indicator
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Timeout state
|
|
||||||
bool watchdog_timed_out() { return TEST(WDT_ReadTimeOutFlag(), 0); }
|
|
||||||
void watchdog_clear_timeout_flag() { WDT_ClrTimeOutFlag(); }
|
|
||||||
|
|
||||||
#endif // USE_WATCHDOG
|
|
||||||
#endif // TARGET_LPC1768
|
|
|
@ -1,28 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
void watchdog_init();
|
|
||||||
void HAL_watchdog_refresh();
|
|
||||||
|
|
||||||
bool watchdog_timed_out();
|
|
||||||
void watchdog_clear_timeout_flag();
|
|
|
@ -45,7 +45,6 @@ uint8_t _getc();
|
||||||
#include "../shared/math_32bit.h"
|
#include "../shared/math_32bit.h"
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
@ -208,6 +207,10 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
static void init() {} // Called early in setup()
|
static void init() {} // Called early in setup()
|
||||||
static void init_board() {} // Called less early in setup()
|
static void init_board() {} // Called less early in setup()
|
||||||
static void reboot(); // Restart the firmware from 0x0
|
static void reboot(); // Restart the firmware from 0x0
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#define WDT_TIMEOUT 4000000 // 4 second timeout
|
|
||||||
|
|
||||||
void watchdog_init();
|
|
||||||
void HAL_watchdog_refresh();
|
|
|
@ -203,6 +203,40 @@ enum ADCIndex {
|
||||||
ADC_COUNT
|
ADC_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
#define WDT_TIMEOUT_REG TERN(WATCHDOG_DURATION_8S, WDT_CONFIG_PER_CYC8192, WDT_CONFIG_PER_CYC4096) // 4 or 8 second timeout
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_init() {
|
||||||
|
// The low-power oscillator used by the WDT runs at 32,768 Hz with
|
||||||
|
// a 1:32 prescale, thus 1024 Hz, though probably not super precise.
|
||||||
|
|
||||||
|
// Setup WDT clocks
|
||||||
|
MCLK->APBAMASK.bit.OSC32KCTRL_ = true;
|
||||||
|
MCLK->APBAMASK.bit.WDT_ = true;
|
||||||
|
OSC32KCTRL->OSCULP32K.bit.EN1K = true; // Enable out 1K (this is what WDT uses)
|
||||||
|
|
||||||
|
WDT->CTRLA.bit.ENABLE = false; // Disable watchdog for config
|
||||||
|
SYNC(WDT->SYNCBUSY.bit.ENABLE);
|
||||||
|
|
||||||
|
WDT->INTENCLR.reg = WDT_INTENCLR_EW; // Disable early warning interrupt
|
||||||
|
WDT->CONFIG.reg = WDT_TIMEOUT_REG; // Set a 4s or 8s period for chip reset
|
||||||
|
|
||||||
|
hal.watchdog_refresh();
|
||||||
|
|
||||||
|
WDT->CTRLA.reg = WDT_CTRLA_ENABLE; // Start watchdog now in normal mode
|
||||||
|
SYNC(WDT->SYNCBUSY.bit.ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset watchdog. MUST be called at least every 4 seconds after the
|
||||||
|
// first watchdog_init or SAMD will go into emergency procedures.
|
||||||
|
void MarlinHAL::watchdog_refresh() {
|
||||||
|
SYNC(WDT->SYNCBUSY.bit.CLEAR); // Test first if previous is 'ongoing' to save time waiting for command execution
|
||||||
|
WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// Types
|
// Types
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "../shared/math_32bit.h"
|
#include "../shared/math_32bit.h"
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
|
#ifdef ADAFRUIT_GRAND_CENTRAL_M4
|
||||||
#include "MarlinSerial_AGCM4.h"
|
#include "MarlinSerial_AGCM4.h"
|
||||||
|
@ -157,6 +156,10 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
static void init(); // Called early in setup()
|
static void init(); // Called early in setup()
|
||||||
static void init_board() {} // Called less early in setup()
|
static void init_board() {} // Called less early in setup()
|
||||||
static void reboot(); // Restart the firmware from 0x0
|
static void reboot(); // Restart the firmware from 0x0
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifdef __SAMD51__
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#define WDT_TIMEOUT_REG TERN(WATCHDOG_DURATION_8S, WDT_CONFIG_PER_CYC8192, WDT_CONFIG_PER_CYC4096) // 4 or 8 second timeout
|
|
||||||
|
|
||||||
void watchdog_init() {
|
|
||||||
// The low-power oscillator used by the WDT runs at 32,768 Hz with
|
|
||||||
// a 1:32 prescale, thus 1024 Hz, though probably not super precise.
|
|
||||||
|
|
||||||
// Setup WDT clocks
|
|
||||||
MCLK->APBAMASK.bit.OSC32KCTRL_ = true;
|
|
||||||
MCLK->APBAMASK.bit.WDT_ = true;
|
|
||||||
OSC32KCTRL->OSCULP32K.bit.EN1K = true; // Enable out 1K (this is what WDT uses)
|
|
||||||
|
|
||||||
WDT->CTRLA.bit.ENABLE = false; // Disable watchdog for config
|
|
||||||
SYNC(WDT->SYNCBUSY.bit.ENABLE);
|
|
||||||
|
|
||||||
WDT->INTENCLR.reg = WDT_INTENCLR_EW; // Disable early warning interrupt
|
|
||||||
WDT->CONFIG.reg = WDT_TIMEOUT_REG; // Set a 4s or 8s period for chip reset
|
|
||||||
|
|
||||||
HAL_watchdog_refresh();
|
|
||||||
|
|
||||||
WDT->CTRLA.reg = WDT_CTRLA_ENABLE; // Start watchdog now in normal mode
|
|
||||||
SYNC(WDT->SYNCBUSY.bit.ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // USE_WATCHDOG
|
|
||||||
|
|
||||||
#endif // __SAMD51__
|
|
|
@ -1,31 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
*
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
* SAMD51 HAL developed by Giuliano Zaro (AKA GMagician)
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
// Initialize watchdog with a 4 second interrupt time
|
|
||||||
void watchdog_init();
|
|
||||||
|
|
||||||
// Reset watchdog. MUST be called at least every 4 seconds after the
|
|
||||||
// first watchdog_init or SAMD will go into emergency procedures.
|
|
||||||
inline void HAL_watchdog_refresh() {
|
|
||||||
SYNC(WDT->SYNCBUSY.bit.CLEAR); // Test first if previous is 'ongoing' to save time waiting for command execution
|
|
||||||
WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY;
|
|
||||||
}
|
|
|
@ -140,6 +140,29 @@ uint8_t MarlinHAL::get_reset_source() {
|
||||||
|
|
||||||
void MarlinHAL::clear_reset_source() { __HAL_RCC_CLEAR_RESET_FLAGS(); }
|
void MarlinHAL::clear_reset_source() { __HAL_RCC_CLEAR_RESET_FLAGS(); }
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
// Watchdog Timer
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
|
||||||
|
|
||||||
|
#include <IWatchdog.h>
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_init() {
|
||||||
|
IF_DISABLED(DISABLE_WATCHDOG_INIT, IWatchdog.begin(WDT_TIMEOUT_US));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_refresh() {
|
||||||
|
IWatchdog.reload();
|
||||||
|
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
|
||||||
|
TOGGLE(LED_PIN); // heartbeat indicator
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
extern unsigned int _ebss; // end of bss section
|
extern unsigned int _ebss; // end of bss section
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "Servo.h"
|
#include "Servo.h"
|
||||||
#include "watchdog.h"
|
|
||||||
#include "MarlinSerial.h"
|
#include "MarlinSerial.h"
|
||||||
|
|
||||||
#include "../../inc/MarlinConfigPre.h"
|
#include "../../inc/MarlinConfigPre.h"
|
||||||
|
@ -218,6 +217,10 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
static void init(); // Called early in setup()
|
static void init(); // Called early in setup()
|
||||||
static void init_board() {} // Called less early in setup()
|
static void init_board() {} // Called less early in setup()
|
||||||
static void reboot(); // Restart the firmware from 0x0
|
static void reboot(); // Restart the firmware from 0x0
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#if ENABLED(POSTMORTEM_DEBUGGING)
|
#if ENABLED(POSTMORTEM_DEBUGGING)
|
||||||
|
|
||||||
#include "../shared/MinSerial.h"
|
#include "../shared/MinSerial.h"
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
/* Instruction Synchronization Barrier */
|
/* Instruction Synchronization Barrier */
|
||||||
#define isb() __asm__ __volatile__ ("isb" : : : "memory")
|
#define isb() __asm__ __volatile__ ("isb" : : : "memory")
|
||||||
|
@ -120,7 +119,7 @@ static void TX(char c) {
|
||||||
#if WITHIN(SERIAL_PORT, 1, 6)
|
#if WITHIN(SERIAL_PORT, 1, 6)
|
||||||
constexpr uint32_t usart_sr_txe = _BV(7);
|
constexpr uint32_t usart_sr_txe = _BV(7);
|
||||||
while (!(regs->SR & usart_sr_txe)) {
|
while (!(regs->SR & usart_sr_txe)) {
|
||||||
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
|
hal.watchdog_refresh();
|
||||||
sw_barrier();
|
sw_barrier();
|
||||||
}
|
}
|
||||||
regs->DR = c;
|
regs->DR = c;
|
||||||
|
|
|
@ -57,7 +57,7 @@ public:
|
||||||
auto sd2card = diskIODriver();
|
auto sd2card = diskIODriver();
|
||||||
// single block
|
// single block
|
||||||
if (blkLen == 1) {
|
if (blkLen == 1) {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
sd2card->writeBlock(blkAddr, pBuf);
|
sd2card->writeBlock(blkAddr, pBuf);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public:
|
||||||
// multi block optimization
|
// multi block optimization
|
||||||
sd2card->writeStart(blkAddr, blkLen);
|
sd2card->writeStart(blkAddr, blkLen);
|
||||||
while (blkLen--) {
|
while (blkLen--) {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
sd2card->writeData(pBuf);
|
sd2card->writeData(pBuf);
|
||||||
pBuf += BLOCK_SIZE;
|
pBuf += BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public:
|
||||||
auto sd2card = diskIODriver();
|
auto sd2card = diskIODriver();
|
||||||
// single block
|
// single block
|
||||||
if (blkLen == 1) {
|
if (blkLen == 1) {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
sd2card->readBlock(blkAddr, pBuf);
|
sd2card->readBlock(blkAddr, pBuf);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ public:
|
||||||
// multi block optimization
|
// multi block optimization
|
||||||
sd2card->readStart(blkAddr);
|
sd2card->readStart(blkAddr);
|
||||||
while (blkLen--) {
|
while (blkLen--) {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
sd2card->readData(pBuf);
|
sd2card->readData(pBuf);
|
||||||
pBuf += BLOCK_SIZE;
|
pBuf += BLOCK_SIZE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,7 +208,7 @@ bool SDIO_Init() {
|
||||||
|
|
||||||
uint8_t retry_Cnt = retryCnt;
|
uint8_t retry_Cnt = retryCnt;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
|
hal.watchdog_refresh();
|
||||||
status = (bool) HAL_SD_Init(&hsd);
|
status = (bool) HAL_SD_Init(&hsd);
|
||||||
if (!status) break;
|
if (!status) break;
|
||||||
if (!--retry_Cnt) return false; // return failing status if retries are exhausted
|
if (!--retry_Cnt) return false; // return failing status if retries are exhausted
|
||||||
|
@ -219,7 +219,7 @@ bool SDIO_Init() {
|
||||||
#if PINS_EXIST(SDIO_D1, SDIO_D2, SDIO_D3) // go to 4 bit wide mode if pins are defined
|
#if PINS_EXIST(SDIO_D1, SDIO_D2, SDIO_D3) // go to 4 bit wide mode if pins are defined
|
||||||
retry_Cnt = retryCnt;
|
retry_Cnt = retryCnt;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
|
hal.watchdog_refresh();
|
||||||
if (!HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B)) break; // some cards are only 1 bit wide so a pass here is not required
|
if (!HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B)) break; // some cards are only 1 bit wide so a pass here is not required
|
||||||
if (!--retry_Cnt) break;
|
if (!--retry_Cnt) break;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ bool SDIO_Init() {
|
||||||
SD_LowLevel_Init();
|
SD_LowLevel_Init();
|
||||||
retry_Cnt = retryCnt;
|
retry_Cnt = retryCnt;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
|
hal.watchdog_refresh();
|
||||||
status = (bool) HAL_SD_Init(&hsd);
|
status = (bool) HAL_SD_Init(&hsd);
|
||||||
if (!status) break;
|
if (!status) break;
|
||||||
if (!--retry_Cnt) return false; // return failing status if retries are exhausted
|
if (!--retry_Cnt) return false; // return failing status if retries are exhausted
|
||||||
|
@ -243,7 +243,7 @@ bool SDIO_Init() {
|
||||||
static bool SDIO_ReadWriteBlock_DMA(uint32_t block, const uint8_t *src, uint8_t *dst) {
|
static bool SDIO_ReadWriteBlock_DMA(uint32_t block, const uint8_t *src, uint8_t *dst) {
|
||||||
if (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER) return false;
|
if (HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER) return false;
|
||||||
|
|
||||||
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
|
hal.watchdog_refresh();
|
||||||
|
|
||||||
HAL_StatusTypeDef ret;
|
HAL_StatusTypeDef ret;
|
||||||
if (src) {
|
if (src) {
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../platforms.h"
|
|
||||||
|
|
||||||
#ifdef HAL_STM32
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfigPre.h"
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#include "watchdog.h"
|
|
||||||
#include <IWatchdog.h>
|
|
||||||
|
|
||||||
void watchdog_init() {
|
|
||||||
#if DISABLED(DISABLE_WATCHDOG_INIT)
|
|
||||||
IWatchdog.begin(WDT_TIMEOUT_US);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_watchdog_refresh() {
|
|
||||||
IWatchdog.reload();
|
|
||||||
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
|
|
||||||
TOGGLE(LED_PIN); // heartbeat indicator
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // USE_WATCHDOG
|
|
||||||
#endif // HAL_STM32
|
|
|
@ -1,25 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
void watchdog_init();
|
|
||||||
void HAL_watchdog_refresh();
|
|
|
@ -113,6 +113,47 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
// Watchdog Timer
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
#include <libmaple/iwdg.h>
|
||||||
|
|
||||||
|
void watchdogSetup() {
|
||||||
|
// do whatever. don't remove this function.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The watchdog clock is 40Khz. So for a 4s or 8s interval use a /256 preescaler and 625 or 1250 reload value (counts down to 0).
|
||||||
|
*/
|
||||||
|
#define STM32F1_WD_RELOAD TERN(WATCHDOG_DURATION_8S, 1250, 625) // 4 or 8 second timeout
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize the independent hardware watchdog.
|
||||||
|
*
|
||||||
|
* @return No return
|
||||||
|
*
|
||||||
|
* @details The watchdog clock is 40Khz. So for a 4s or 8s interval use a /256 preescaler and 625 or 1250 reload value (counts down to 0).
|
||||||
|
*/
|
||||||
|
void MarlinHAL::watchdog_init() {
|
||||||
|
#if DISABLED(DISABLE_WATCHDOG_INIT)
|
||||||
|
iwdg_init(IWDG_PRE_256, STM32F1_WD_RELOAD);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset watchdog. MUST be called every 4 or 8 seconds after the
|
||||||
|
// first watchdog_init or the STM32F1 will reset.
|
||||||
|
void MarlinHAL::watchdog_refresh() {
|
||||||
|
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
|
||||||
|
TOGGLE(LED_PIN); // heartbeat indicator
|
||||||
|
#endif
|
||||||
|
iwdg_feed();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // USE_WATCHDOG
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// ADC
|
// ADC
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
|
@ -34,7 +34,6 @@
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
|
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <util/atomic.h>
|
#include <util/atomic.h>
|
||||||
|
@ -247,6 +246,10 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
static void init(); // Called early in setup()
|
static void init(); // Called early in setup()
|
||||||
static void init_board() {} // Called less early in setup()
|
static void init_board() {} // Called less early in setup()
|
||||||
static void reboot(); // Restart the firmware from 0x0
|
static void reboot(); // Restart the firmware from 0x0
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#if ENABLED(POSTMORTEM_DEBUGGING)
|
#if ENABLED(POSTMORTEM_DEBUGGING)
|
||||||
|
|
||||||
#include "../shared/MinSerial.h"
|
#include "../shared/MinSerial.h"
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#include <libmaple/usart.h>
|
#include <libmaple/usart.h>
|
||||||
#include <libmaple/rcc.h>
|
#include <libmaple/rcc.h>
|
||||||
|
@ -82,7 +81,7 @@ static void TX(char c) {
|
||||||
#if WITHIN(SERIAL_PORT, 1, 6)
|
#if WITHIN(SERIAL_PORT, 1, 6)
|
||||||
struct usart_dev* dev = MYSERIAL1.c_dev();
|
struct usart_dev* dev = MYSERIAL1.c_dev();
|
||||||
while (!(dev->regs->SR & USART_SR_TXE)) {
|
while (!(dev->regs->SR & USART_SR_TXE)) {
|
||||||
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
|
hal.watchdog_refresh();
|
||||||
sw_barrier();
|
sw_barrier();
|
||||||
}
|
}
|
||||||
dev->regs->DR = c;
|
dev->regs->DR = c;
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __STM32F1__
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
#include <libmaple/iwdg.h>
|
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The watchdog clock is 40Khz. So for a 4s or 8s interval use a /256 preescaler and 625 or 1250 reload value (counts down to 0).
|
|
||||||
*/
|
|
||||||
#define STM32F1_WD_RELOAD TERN(WATCHDOG_DURATION_8S, 1250, 625) // 4 or 8 second timeout
|
|
||||||
|
|
||||||
void HAL_watchdog_refresh() {
|
|
||||||
#if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
|
|
||||||
TOGGLE(LED_PIN); // heartbeat indicator
|
|
||||||
#endif
|
|
||||||
iwdg_feed();
|
|
||||||
}
|
|
||||||
|
|
||||||
void watchdogSetup() {
|
|
||||||
// do whatever. don't remove this function.
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialized the independent hardware watchdog.
|
|
||||||
*
|
|
||||||
* @return No return
|
|
||||||
*
|
|
||||||
* @details The watchdog clock is 40Khz. So for a 4s or 8s interval use a /256 preescaler and 625 or 1250 reload value (counts down to 0).
|
|
||||||
*/
|
|
||||||
void watchdog_init() {
|
|
||||||
#if DISABLED(DISABLE_WATCHDOG_INIT)
|
|
||||||
iwdg_init(IWDG_PRE_256, STM32F1_WD_RELOAD);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // USE_WATCHDOG
|
|
||||||
#endif // __STM32F1__
|
|
|
@ -1,35 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HAL for stm32duino.com based on Libmaple and compatible (STM32F1)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <libmaple/iwdg.h>
|
|
||||||
|
|
||||||
// Initialize watchdog with a 4 or 8 second countdown time
|
|
||||||
void watchdog_init();
|
|
||||||
|
|
||||||
// Reset watchdog. MUST be called every 4 or 8 seconds after the
|
|
||||||
// first watchdog_init or the STM32F1 will reset.
|
|
||||||
void HAL_watchdog_refresh();
|
|
|
@ -62,6 +62,28 @@ uint8_t MarlinHAL::get_reset_source() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
// Watchdog Timer
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
#define WDT_TIMEOUT_MS TERN(WATCHDOG_DURATION_8S, 8000, 4000) // 4 or 8 second timeout
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_init() {
|
||||||
|
WDOG_TOVALH = 0;
|
||||||
|
WDOG_TOVALL = WDT_TIMEOUT_MS;
|
||||||
|
WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_refresh() {
|
||||||
|
// Watchdog refresh sequence
|
||||||
|
WDOG_REFRESH = 0xA602;
|
||||||
|
WDOG_REFRESH = 0xB480;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// ADC
|
// ADC
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
|
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -135,6 +134,10 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
static void init() {} // Called early in setup()
|
static void init() {} // Called early in setup()
|
||||||
static void init_board() {} // Called less early in setup()
|
static void init_board() {} // Called less early in setup()
|
||||||
static void reboot(); // Restart the firmware from 0x0
|
static void reboot(); // Restart the firmware from 0x0
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifdef __MK20DX256__
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#define WDT_TIMEOUT_MS TERN(WATCHDOG_DURATION_8S, 8000, 4000) // 4 or 8 second timeout
|
|
||||||
|
|
||||||
void watchdog_init() {
|
|
||||||
WDOG_TOVALH = 0;
|
|
||||||
WDOG_TOVALL = WDT_TIMEOUT_MS;
|
|
||||||
WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // USE_WATCHDOG
|
|
||||||
|
|
||||||
#endif // __MK20DX256__
|
|
|
@ -1,34 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "HAL.h"
|
|
||||||
|
|
||||||
// Arduino Due core now has watchdog support
|
|
||||||
|
|
||||||
void watchdog_init();
|
|
||||||
|
|
||||||
inline void HAL_watchdog_refresh() {
|
|
||||||
// Watchdog refresh sequence
|
|
||||||
WDOG_REFRESH = 0xA602;
|
|
||||||
WDOG_REFRESH = 0xB480;
|
|
||||||
}
|
|
|
@ -61,6 +61,28 @@ uint8_t MarlinHAL::get_reset_source() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
// Watchdog Timer
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
#define WDT_TIMEOUT_MS TERN(WATCHDOG_DURATION_8S, 8000, 4000) // 4 or 8 second timeout
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_init() {
|
||||||
|
WDOG_TOVALH = 0;
|
||||||
|
WDOG_TOVALL = WDT_TIMEOUT_MS;
|
||||||
|
WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_refresh() {
|
||||||
|
// Watchdog refresh sequence
|
||||||
|
WDOG_REFRESH = 0xA602;
|
||||||
|
WDOG_REFRESH = 0xB480;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// ADC
|
// ADC
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
|
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <util/atomic.h>
|
#include <util/atomic.h>
|
||||||
|
@ -140,6 +139,10 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
static void init() {} // Called early in setup()
|
static void init() {} // Called early in setup()
|
||||||
static void init_board() {} // Called less early in setup()
|
static void init_board() {} // Called less early in setup()
|
||||||
static void reboot(); // Restart the firmware from 0x0
|
static void reboot(); // Restart the firmware from 0x0
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#define WDT_TIMEOUT_MS TERN(WATCHDOG_DURATION_8S, 8000, 4000) // 4 or 8 second timeout
|
|
||||||
|
|
||||||
void watchdog_init() {
|
|
||||||
WDOG_TOVALH = 0;
|
|
||||||
WDOG_TOVALL = WDT_TIMEOUT_MS;
|
|
||||||
WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // USE_WATCHDOG
|
|
||||||
|
|
||||||
#endif // __MK64FX512__ || __MK66FX1M0__
|
|
|
@ -1,30 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
void watchdog_init();
|
|
||||||
|
|
||||||
inline void HAL_watchdog_refresh() {
|
|
||||||
// Watchdog refresh sequence
|
|
||||||
WDOG_REFRESH = 0xA602;
|
|
||||||
WDOG_REFRESH = 0xB480;
|
|
||||||
}
|
|
|
@ -78,6 +78,31 @@ void MarlinHAL::clear_reset_source() {
|
||||||
SRC_SRSR = reset_source;
|
SRC_SRSR = reset_source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------
|
||||||
|
// Watchdog Timer
|
||||||
|
// ------------------------
|
||||||
|
|
||||||
|
#if ENABLED(USE_WATCHDOG)
|
||||||
|
|
||||||
|
#define WDT_TIMEOUT TERN(WATCHDOG_DURATION_8S, 8, 4) // 4 or 8 second timeout
|
||||||
|
|
||||||
|
constexpr uint8_t timeoutval = (WDT_TIMEOUT - 0.5f) / 0.5f;
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_init() {
|
||||||
|
CCM_CCGR3 |= CCM_CCGR3_WDOG1(3); // enable WDOG1 clocks
|
||||||
|
WDOG1_WMCR = 0; // disable power down PDE
|
||||||
|
WDOG1_WCR |= WDOG_WCR_SRS | WDOG_WCR_WT(timeoutval);
|
||||||
|
WDOG1_WCR |= WDOG_WCR_WDE | WDOG_WCR_WDT | WDOG_WCR_SRE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MarlinHAL::watchdog_refresh() {
|
||||||
|
// Watchdog refresh sequence
|
||||||
|
WDOG1_WSR = 0x5555;
|
||||||
|
WDOG1_WSR = 0xAAAA;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
// ADC
|
// ADC
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
#include "../shared/HAL_SPI.h"
|
#include "../shared/HAL_SPI.h"
|
||||||
|
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <util/atomic.h>
|
#include <util/atomic.h>
|
||||||
|
@ -162,6 +161,10 @@ public:
|
||||||
// Earliest possible init, before setup()
|
// Earliest possible init, before setup()
|
||||||
MarlinHAL() {}
|
MarlinHAL() {}
|
||||||
|
|
||||||
|
// Watchdog
|
||||||
|
static void watchdog_init() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
static void watchdog_refresh() IF_DISABLED(USE_WATCHDOG, {});
|
||||||
|
|
||||||
static void init() {} // Called early in setup()
|
static void init() {} // Called early in setup()
|
||||||
static void init_board() {} // Called less early in setup()
|
static void init_board() {} // Called less early in setup()
|
||||||
static void reboot(); // Restart the firmware from 0x0
|
static void reboot(); // Restart the firmware from 0x0
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifdef __IMXRT1062__
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HAL Watchdog for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
|
||||||
|
|
||||||
#include "watchdog.h"
|
|
||||||
|
|
||||||
#define WDT_TIMEOUT TERN(WATCHDOG_DURATION_8S, 8, 4) // 4 or 8 second timeout
|
|
||||||
|
|
||||||
constexpr uint8_t timeoutval = (WDT_TIMEOUT - 0.5f) / 0.5f;
|
|
||||||
|
|
||||||
void watchdog_init() {
|
|
||||||
CCM_CCGR3 |= CCM_CCGR3_WDOG1(3); // enable WDOG1 clocks
|
|
||||||
WDOG1_WMCR = 0; // disable power down PDE
|
|
||||||
WDOG1_WCR |= WDOG_WCR_SRS | WDOG_WCR_WT(timeoutval);
|
|
||||||
WDOG1_WCR |= WDOG_WCR_WDE | WDOG_WCR_WDT | WDOG_WCR_SRE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HAL_watchdog_refresh() {
|
|
||||||
// Watchdog refresh sequence
|
|
||||||
WDOG1_WSR = 0x5555;
|
|
||||||
WDOG1_WSR = 0xAAAA;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // USE_WATCHDOG
|
|
||||||
#endif // __IMXRT1062__
|
|
|
@ -1,30 +0,0 @@
|
||||||
/**
|
|
||||||
* Marlin 3D Printer Firmware
|
|
||||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
||||||
*
|
|
||||||
* Based on Sprinter and grbl.
|
|
||||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HAL Watchdog for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
|
|
||||||
*/
|
|
||||||
|
|
||||||
void watchdog_init();
|
|
||||||
|
|
||||||
void HAL_watchdog_refresh();
|
|
|
@ -221,7 +221,7 @@ bool resume_from_fault() {
|
||||||
// So we'll just need to refresh the watchdog for a while and then stop for the system to reboot
|
// So we'll just need to refresh the watchdog for a while and then stop for the system to reboot
|
||||||
uint32_t last = start;
|
uint32_t last = start;
|
||||||
while (PENDING(last, end)) {
|
while (PENDING(last, end)) {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
while (millis() == last) { /* nada */ }
|
while (millis() == last) { /* nada */ }
|
||||||
last = millis();
|
last = millis();
|
||||||
MinSerial::TX('.');
|
MinSerial::TX('.');
|
||||||
|
|
|
@ -931,18 +931,18 @@ void minkill(const bool steppers_off/*=false*/) {
|
||||||
|
|
||||||
// Wait for both KILL and ENC to be released
|
// Wait for both KILL and ENC to be released
|
||||||
while (TERN0(HAS_KILL, kill_state()) || TERN0(SOFT_RESET_ON_KILL, ui.button_pressed()))
|
while (TERN0(HAS_KILL, kill_state()) || TERN0(SOFT_RESET_ON_KILL, ui.button_pressed()))
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
|
|
||||||
// Wait for either KILL or ENC to be pressed again
|
// Wait for either KILL or ENC to be pressed again
|
||||||
while (TERN1(HAS_KILL, !kill_state()) && TERN1(SOFT_RESET_ON_KILL, !ui.button_pressed()))
|
while (TERN1(HAS_KILL, !kill_state()) && TERN1(SOFT_RESET_ON_KILL, !ui.button_pressed()))
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
|
|
||||||
// Reboot the board
|
// Reboot the board
|
||||||
hal.reboot();
|
hal.reboot();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
for (;;) watchdog_refresh(); // Wait for RESET button or power-cycle
|
for (;;) hal.watchdog_refresh(); // Wait for RESET button or power-cycle
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1549,7 +1549,7 @@ void setup() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(USE_WATCHDOG)
|
#if ENABLED(USE_WATCHDOG)
|
||||||
SETUP_RUN(watchdog_init()); // Reinit watchdog after hal.get_reset_source call
|
SETUP_RUN(hal.watchdog_init()); // Reinit watchdog after hal.get_reset_source call
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
|
#if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
|
||||||
|
|
|
@ -69,7 +69,7 @@ inline void toggle_pins() {
|
||||||
SERIAL_EOL();
|
SERIAL_EOL();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
report_pin_state_extended(pin, ignore_protection, true, F("Pulsing "));
|
report_pin_state_extended(pin, ignore_protection, true, F("Pulsing "));
|
||||||
#ifdef __STM32F1__
|
#ifdef __STM32F1__
|
||||||
const auto prior_mode = _GET_MODE(i);
|
const auto prior_mode = _GET_MODE(i);
|
||||||
|
@ -98,10 +98,10 @@ inline void toggle_pins() {
|
||||||
{
|
{
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
for (int16_t j = 0; j < repeat; j++) {
|
for (int16_t j = 0; j < repeat; j++) {
|
||||||
watchdog_refresh(); extDigitalWrite(pin, 0); safe_delay(wait);
|
hal.watchdog_refresh(); extDigitalWrite(pin, 0); safe_delay(wait);
|
||||||
watchdog_refresh(); extDigitalWrite(pin, 1); safe_delay(wait);
|
hal.watchdog_refresh(); extDigitalWrite(pin, 1); safe_delay(wait);
|
||||||
watchdog_refresh(); extDigitalWrite(pin, 0); safe_delay(wait);
|
hal.watchdog_refresh(); extDigitalWrite(pin, 0); safe_delay(wait);
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef __STM32F1__
|
#ifdef __STM32F1__
|
||||||
|
|
|
@ -309,7 +309,6 @@ void GcodeSuite::M917() {
|
||||||
}
|
}
|
||||||
DEBUG_ECHOLNPGM(".");
|
DEBUG_ECHOLNPGM(".");
|
||||||
reset_stepper_timeout(); // keep steppers powered
|
reset_stepper_timeout(); // keep steppers powered
|
||||||
watchdog_refresh();
|
|
||||||
safe_delay(5000);
|
safe_delay(5000);
|
||||||
status_composite_temp = 0;
|
status_composite_temp = 0;
|
||||||
for (j = 0; j < driver_count; j++) {
|
for (j = 0; j < driver_count; j++) {
|
||||||
|
|
|
@ -214,7 +214,7 @@ void GcodeSuite::D(const int16_t dcode) {
|
||||||
|
|
||||||
c = 1024 * 4;
|
c = 1024 * 4;
|
||||||
while (c--) {
|
while (c--) {
|
||||||
TERN_(USE_WATCHDOG, watchdog_refresh());
|
hal.watchdog_refresh();
|
||||||
card.write(buf, COUNT(buf));
|
card.write(buf, COUNT(buf));
|
||||||
}
|
}
|
||||||
SERIAL_ECHOLNPGM(" done");
|
SERIAL_ECHOLNPGM(" done");
|
||||||
|
@ -231,7 +231,7 @@ void GcodeSuite::D(const int16_t dcode) {
|
||||||
__attribute__((aligned(sizeof(size_t)))) uint8_t buf[512];
|
__attribute__((aligned(sizeof(size_t)))) uint8_t buf[512];
|
||||||
uint16_t c = 1024 * 4;
|
uint16_t c = 1024 * 4;
|
||||||
while (c--) {
|
while (c--) {
|
||||||
TERN_(USE_WATCHDOG, watchdog_refresh());
|
hal.watchdog_refresh();
|
||||||
card.read(buf, COUNT(buf));
|
card.read(buf, COUNT(buf));
|
||||||
bool error = false;
|
bool error = false;
|
||||||
for (uint16_t i = 0; i < COUNT(buf); i++) {
|
for (uint16_t i = 0; i < COUNT(buf); i++) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ void MeshViewerClass::DrawMesh(bed_mesh_t zval, const uint8_t sizex, const uint8
|
||||||
LOOP_S_L_N(x, 1, sizex - 1) DrawMeshVLine(x);
|
LOOP_S_L_N(x, 1, sizex - 1) DrawMeshVLine(x);
|
||||||
LOOP_S_L_N(y, 1, sizey - 1) DrawMeshHLine(y);
|
LOOP_S_L_N(y, 1, sizey - 1) DrawMeshHLine(y);
|
||||||
LOOP_L_N(y, sizey) {
|
LOOP_L_N(y, sizey) {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
LOOP_L_N(x, sizex) {
|
LOOP_L_N(x, sizex) {
|
||||||
uint16_t color = DWINUI::RainbowInt(zmesh[x][y], _MIN(-5, minz), _MAX(5, maxz));
|
uint16_t color = DWINUI::RainbowInt(zmesh[x][y], _MIN(-5, minz), _MAX(5, maxz));
|
||||||
uint8_t radius = rm(zmesh[x][y]);
|
uint8_t radius = rm(zmesh[x][y]);
|
||||||
|
|
|
@ -402,7 +402,7 @@ void lv_gcode_file_read(uint8_t *data_buf) {
|
||||||
char temp_test[200];
|
char temp_test[200];
|
||||||
volatile uint16_t *p_index;
|
volatile uint16_t *p_index;
|
||||||
|
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
memset(public_buf, 0, 200);
|
memset(public_buf, 0, 200);
|
||||||
|
|
||||||
while (card.isFileOpen()) {
|
while (card.isFileOpen()) {
|
||||||
|
|
|
@ -104,7 +104,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
||||||
sync_plan_position();
|
sync_plan_position();
|
||||||
// Raise Z as if it was homed
|
// Raise Z as if it was homed
|
||||||
do_z_clearance(Z_POST_CLEARANCE);
|
do_z_clearance(Z_POST_CLEARANCE);
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
draw_return_ui();
|
draw_return_ui();
|
||||||
return;
|
return;
|
||||||
case ID_M_RETURN:
|
case ID_M_RETURN:
|
||||||
|
@ -117,7 +117,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
||||||
#else // Otherwise do a Z clearance move like after Homing
|
#else // Otherwise do a Z clearance move like after Homing
|
||||||
do_z_clearance(Z_POST_CLEARANCE);
|
do_z_clearance(Z_POST_CLEARANCE);
|
||||||
#endif
|
#endif
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
draw_return_ui();
|
draw_return_ui();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,12 +267,12 @@ void spiFlashErase_PIC() {
|
||||||
W25QXX.init(SPI_QUARTER_SPEED);
|
W25QXX.init(SPI_QUARTER_SPEED);
|
||||||
// erase 0x001000 -64K
|
// erase 0x001000 -64K
|
||||||
for (pic_sectorcnt = 0; pic_sectorcnt < (64 - 4) / 4; pic_sectorcnt++) {
|
for (pic_sectorcnt = 0; pic_sectorcnt < (64 - 4) / 4; pic_sectorcnt++) {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
W25QXX.SPI_FLASH_SectorErase(PICINFOADDR + pic_sectorcnt * 4 * 1024);
|
W25QXX.SPI_FLASH_SectorErase(PICINFOADDR + pic_sectorcnt * 4 * 1024);
|
||||||
}
|
}
|
||||||
// erase 64K -- 6M
|
// erase 64K -- 6M
|
||||||
for (pic_sectorcnt = 0; pic_sectorcnt < (PIC_SIZE_xM * 1024 / 64 - 1); pic_sectorcnt++) {
|
for (pic_sectorcnt = 0; pic_sectorcnt < (PIC_SIZE_xM * 1024 / 64 - 1); pic_sectorcnt++) {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
W25QXX.SPI_FLASH_BlockErase((pic_sectorcnt + 1) * 64 * 1024);
|
W25QXX.SPI_FLASH_BlockErase((pic_sectorcnt + 1) * 64 * 1024);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@ void spiFlashErase_PIC() {
|
||||||
volatile uint32_t Font_sectorcnt = 0;
|
volatile uint32_t Font_sectorcnt = 0;
|
||||||
W25QXX.init(SPI_QUARTER_SPEED);
|
W25QXX.init(SPI_QUARTER_SPEED);
|
||||||
for (Font_sectorcnt = 0; Font_sectorcnt < 32 - 1; Font_sectorcnt++) {
|
for (Font_sectorcnt = 0; Font_sectorcnt < 32 - 1; Font_sectorcnt++) {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
W25QXX.SPI_FLASH_BlockErase(FONTINFOADDR + Font_sectorcnt * 64 * 1024);
|
W25QXX.SPI_FLASH_BlockErase(FONTINFOADDR + Font_sectorcnt * 64 * 1024);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -414,7 +414,7 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
disp_assets_update_progress(fn);
|
disp_assets_update_progress(fn);
|
||||||
|
|
||||||
W25QXX.init(SPI_QUARTER_SPEED);
|
W25QXX.init(SPI_QUARTER_SPEED);
|
||||||
|
@ -427,21 +427,21 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
|
||||||
totalSizeLoaded += pfileSize;
|
totalSizeLoaded += pfileSize;
|
||||||
if (assetType == ASSET_TYPE_LOGO) {
|
if (assetType == ASSET_TYPE_LOGO) {
|
||||||
do {
|
do {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
|
pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
|
||||||
Pic_Logo_Write((uint8_t*)fn, public_buf, pbr);
|
Pic_Logo_Write((uint8_t*)fn, public_buf, pbr);
|
||||||
} while (pbr >= BMP_WRITE_BUF_LEN);
|
} while (pbr >= BMP_WRITE_BUF_LEN);
|
||||||
}
|
}
|
||||||
else if (assetType == ASSET_TYPE_TITLE_LOGO) {
|
else if (assetType == ASSET_TYPE_TITLE_LOGO) {
|
||||||
do {
|
do {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
|
pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
|
||||||
Pic_TitleLogo_Write((uint8_t*)fn, public_buf, pbr);
|
Pic_TitleLogo_Write((uint8_t*)fn, public_buf, pbr);
|
||||||
} while (pbr >= BMP_WRITE_BUF_LEN);
|
} while (pbr >= BMP_WRITE_BUF_LEN);
|
||||||
}
|
}
|
||||||
else if (assetType == ASSET_TYPE_G_PREVIEW) {
|
else if (assetType == ASSET_TYPE_G_PREVIEW) {
|
||||||
do {
|
do {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
|
pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
|
||||||
default_view_Write(public_buf, pbr);
|
default_view_Write(public_buf, pbr);
|
||||||
} while (pbr >= BMP_WRITE_BUF_LEN);
|
} while (pbr >= BMP_WRITE_BUF_LEN);
|
||||||
|
@ -451,7 +451,7 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
|
||||||
SPIFlash.beginWrite(Pic_Write_Addr);
|
SPIFlash.beginWrite(Pic_Write_Addr);
|
||||||
#if HAS_SPI_FLASH_COMPRESSION
|
#if HAS_SPI_FLASH_COMPRESSION
|
||||||
do {
|
do {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
pbr = file.read(public_buf, SPI_FLASH_PageSize);
|
pbr = file.read(public_buf, SPI_FLASH_PageSize);
|
||||||
TERN_(MARLIN_DEV_MODE, totalSizes += pbr);
|
TERN_(MARLIN_DEV_MODE, totalSizes += pbr);
|
||||||
SPIFlash.writeData(public_buf, SPI_FLASH_PageSize);
|
SPIFlash.writeData(public_buf, SPI_FLASH_PageSize);
|
||||||
|
@ -472,7 +472,7 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
|
||||||
else if (assetType == ASSET_TYPE_FONT) {
|
else if (assetType == ASSET_TYPE_FONT) {
|
||||||
Pic_Write_Addr = UNIGBK_FLASH_ADDR;
|
Pic_Write_Addr = UNIGBK_FLASH_ADDR;
|
||||||
do {
|
do {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
|
pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
|
||||||
W25QXX.SPI_FLASH_BufferWrite(public_buf, Pic_Write_Addr, pbr);
|
W25QXX.SPI_FLASH_BufferWrite(public_buf, Pic_Write_Addr, pbr);
|
||||||
Pic_Write_Addr += pbr;
|
Pic_Write_Addr += pbr;
|
||||||
|
@ -493,11 +493,11 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
|
||||||
|
|
||||||
disp_assets_update();
|
disp_assets_update();
|
||||||
disp_assets_update_progress(F("Erasing pics..."));
|
disp_assets_update_progress(F("Erasing pics..."));
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
spiFlashErase_PIC();
|
spiFlashErase_PIC();
|
||||||
#if HAS_SPI_FLASH_FONT
|
#if HAS_SPI_FLASH_FONT
|
||||||
disp_assets_update_progress(F("Erasing fonts..."));
|
disp_assets_update_progress(F("Erasing fonts..."));
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
spiFlashErase_FONT();
|
spiFlashErase_FONT();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -125,13 +125,13 @@ void tft_lvgl_init() {
|
||||||
ui_cfg_init();
|
ui_cfg_init();
|
||||||
disp_language_init();
|
disp_language_init();
|
||||||
|
|
||||||
watchdog_refresh(); // LVGL init takes time
|
hal.watchdog_refresh(); // LVGL init takes time
|
||||||
|
|
||||||
// Init TFT first!
|
// Init TFT first!
|
||||||
SPI_TFT.spi_init(SPI_FULL_SPEED);
|
SPI_TFT.spi_init(SPI_FULL_SPEED);
|
||||||
SPI_TFT.LCD_init();
|
SPI_TFT.LCD_init();
|
||||||
|
|
||||||
watchdog_refresh(); // LVGL init takes time
|
hal.watchdog_refresh(); // LVGL init takes time
|
||||||
|
|
||||||
#if ENABLED(USB_FLASH_DRIVE_SUPPORT)
|
#if ENABLED(USB_FLASH_DRIVE_SUPPORT)
|
||||||
uint16_t usb_flash_loop = 1000;
|
uint16_t usb_flash_loop = 1000;
|
||||||
|
@ -142,21 +142,21 @@ void tft_lvgl_init() {
|
||||||
#endif
|
#endif
|
||||||
do {
|
do {
|
||||||
card.media_driver_usbFlash.idle();
|
card.media_driver_usbFlash.idle();
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
delay(2);
|
delay(2);
|
||||||
} while (!card.media_driver_usbFlash.isInserted() && usb_flash_loop--);
|
} while (!card.media_driver_usbFlash.isInserted() && usb_flash_loop--);
|
||||||
card.mount();
|
card.mount();
|
||||||
#elif HAS_LOGO_IN_FLASH
|
#elif HAS_LOGO_IN_FLASH
|
||||||
delay(1000);
|
delay(1000);
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
delay(1000);
|
delay(1000);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
watchdog_refresh(); // LVGL init takes time
|
hal.watchdog_refresh(); // LVGL init takes time
|
||||||
|
|
||||||
#if ENABLED(SDSUPPORT)
|
#if ENABLED(SDSUPPORT)
|
||||||
UpdateAssets();
|
UpdateAssets();
|
||||||
watchdog_refresh(); // LVGL init takes time
|
hal.watchdog_refresh(); // LVGL init takes time
|
||||||
TERN_(MKS_TEST, mks_test_get());
|
TERN_(MKS_TEST, mks_test_get());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ uint32_t getWifiTickDiff(int32_t lastTick, int32_t curTick) {
|
||||||
void wifi_delay(int n) {
|
void wifi_delay(int n) {
|
||||||
const uint32_t start = getWifiTick();
|
const uint32_t start = getWifiTick();
|
||||||
while (getWifiTickDiff(start, getWifiTick()) < (uint32_t)n)
|
while (getWifiTickDiff(start, getWifiTick()) < (uint32_t)n)
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wifi_reset() {
|
void wifi_reset() {
|
||||||
|
@ -1882,7 +1882,7 @@ void wifi_rcv_handle() {
|
||||||
void wifi_looping() {
|
void wifi_looping() {
|
||||||
do {
|
do {
|
||||||
wifi_rcv_handle();
|
wifi_rcv_handle();
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
} while (wifi_link_state == WIFI_TRANS_FILE);
|
} while (wifi_link_state == WIFI_TRANS_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1897,7 +1897,7 @@ void mks_esp_wifi_init() {
|
||||||
|
|
||||||
esp_state = TRANSFER_IDLE;
|
esp_state = TRANSFER_IDLE;
|
||||||
esp_port_begin(1);
|
esp_port_begin(1);
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
wifi_reset();
|
wifi_reset();
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -1950,14 +1950,14 @@ void mks_esp_wifi_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void mks_wifi_firmware_update() {
|
void mks_wifi_firmware_update() {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
card.openFileRead((char *)ESP_FIRMWARE_FILE);
|
card.openFileRead((char *)ESP_FIRMWARE_FILE);
|
||||||
|
|
||||||
if (card.isFileOpen()) {
|
if (card.isFileOpen()) {
|
||||||
card.closefile();
|
card.closefile();
|
||||||
|
|
||||||
wifi_delay(2000);
|
wifi_delay(2000);
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
if (usartFifoAvailable((SZ_USART_FIFO *)&WifiRxFifo) < 20) return;
|
if (usartFifoAvailable((SZ_USART_FIFO *)&WifiRxFifo) < 20) return;
|
||||||
|
|
||||||
clear_cur_ui();
|
clear_cur_ui();
|
||||||
|
@ -1965,7 +1965,7 @@ void mks_wifi_firmware_update() {
|
||||||
lv_draw_dialog(DIALOG_TYPE_UPDATE_ESP_FIRMWARE);
|
lv_draw_dialog(DIALOG_TYPE_UPDATE_ESP_FIRMWARE);
|
||||||
|
|
||||||
lv_task_handler();
|
lv_task_handler();
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
|
|
||||||
if (wifi_upload(0) >= 0) {
|
if (wifi_upload(0) >= 0) {
|
||||||
card.removeFile((char *)ESP_FIRMWARE_FILE_RENAME);
|
card.removeFile((char *)ESP_FIRMWARE_FILE_RENAME);
|
||||||
|
|
|
@ -265,7 +265,7 @@ EspUploadResult readPacket(uint8_t op, uint32_t *valp, size_t *bodyLen, uint32_t
|
||||||
EspUploadResult stat;
|
EspUploadResult stat;
|
||||||
|
|
||||||
//IWDG_ReloadCounter();
|
//IWDG_ReloadCounter();
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
|
|
||||||
if (getWifiTickDiff(startTime, getWifiTick()) > msTimeout)
|
if (getWifiTickDiff(startTime, getWifiTick()) > msTimeout)
|
||||||
return timeout;
|
return timeout;
|
||||||
|
@ -445,7 +445,7 @@ EspUploadResult Sync(uint16_t timeout) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
size_t bodyLen;
|
size_t bodyLen;
|
||||||
EspUploadResult rc = readPacket(ESP_SYNC, 0, &bodyLen, defaultTimeout);
|
EspUploadResult rc = readPacket(ESP_SYNC, 0, &bodyLen, defaultTimeout);
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
if (rc != success || bodyLen != 2) break;
|
if (rc != success || bodyLen != 2) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -673,7 +673,7 @@ int32_t wifi_upload(int type) {
|
||||||
|
|
||||||
while (esp_upload.state != upload_idle) {
|
while (esp_upload.state != upload_idle) {
|
||||||
upload_spin();
|
upload_spin();
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResetWiFiForUpload(1);
|
ResetWiFiForUpload(1);
|
||||||
|
|
|
@ -1226,10 +1226,10 @@ inline void loud_kill(FSTR_P const lcd_msg, const heater_id_t heater_id) {
|
||||||
thermalManager.disable_all_heaters();
|
thermalManager.disable_all_heaters();
|
||||||
#if HAS_BEEPER
|
#if HAS_BEEPER
|
||||||
for (uint8_t i = 20; i--;) {
|
for (uint8_t i = 20; i--;) {
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
buzzer.click(25);
|
buzzer.click(25);
|
||||||
delay(80);
|
delay(80);
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
}
|
}
|
||||||
buzzer.on();
|
buzzer.on();
|
||||||
#endif
|
#endif
|
||||||
|
@ -1274,7 +1274,7 @@ void Temperature::_temp_error(const heater_id_t heater_id, FSTR_P const serial_m
|
||||||
}
|
}
|
||||||
|
|
||||||
disable_all_heaters(); // always disable (even for bogus temp)
|
disable_all_heaters(); // always disable (even for bogus temp)
|
||||||
watchdog_refresh();
|
hal.watchdog_refresh();
|
||||||
|
|
||||||
#if BOGUS_TEMPERATURE_GRACE_PERIOD
|
#if BOGUS_TEMPERATURE_GRACE_PERIOD
|
||||||
const millis_t ms = millis();
|
const millis_t ms = millis();
|
||||||
|
@ -1638,7 +1638,7 @@ void Temperature::min_temp_error(const heater_id_t heater_id) {
|
||||||
* - Update the heated bed PID output value
|
* - Update the heated bed PID output value
|
||||||
*/
|
*/
|
||||||
void Temperature::manage_heater() {
|
void Temperature::manage_heater() {
|
||||||
if (marlin_state == MF_INITIALIZING) return watchdog_refresh(); // If Marlin isn't started, at least reset the watchdog!
|
if (marlin_state == MF_INITIALIZING) return hal.watchdog_refresh(); // If Marlin isn't started, at least reset the watchdog!
|
||||||
|
|
||||||
static bool no_reentry = false; // Prevent recursion
|
static bool no_reentry = false; // Prevent recursion
|
||||||
if (no_reentry) return;
|
if (no_reentry) return;
|
||||||
|
@ -2387,7 +2387,7 @@ void Temperature::manage_heater() {
|
||||||
*/
|
*/
|
||||||
void Temperature::updateTemperaturesFromRawValues() {
|
void Temperature::updateTemperaturesFromRawValues() {
|
||||||
|
|
||||||
watchdog_refresh(); // Reset because raw_temps_ready was set by the interrupt
|
hal.watchdog_refresh(); // Reset because raw_temps_ready was set by the interrupt
|
||||||
|
|
||||||
TERN_(TEMP_SENSOR_0_IS_MAX_TC, temp_hotend[0].setraw(READ_MAX_TC(0)));
|
TERN_(TEMP_SENSOR_0_IS_MAX_TC, temp_hotend[0].setraw(READ_MAX_TC(0)));
|
||||||
TERN_(TEMP_SENSOR_1_IS_MAX_TC, temp_hotend[1].setraw(READ_MAX_TC(1)));
|
TERN_(TEMP_SENSOR_1_IS_MAX_TC, temp_hotend[1].setraw(READ_MAX_TC(1)));
|
||||||
|
|
|
@ -249,7 +249,7 @@ bool DiskIODriver_SPI_SD::init(const uint8_t sckRateID, const pin_t chipSelectPi
|
||||||
const millis_t init_timeout = millis() + SD_INIT_TIMEOUT;
|
const millis_t init_timeout = millis() + SD_INIT_TIMEOUT;
|
||||||
uint32_t arg;
|
uint32_t arg;
|
||||||
|
|
||||||
watchdog_refresh(); // In case init takes too long
|
hal.watchdog_refresh(); // In case init takes too long
|
||||||
|
|
||||||
// Set pin modes
|
// Set pin modes
|
||||||
#if ENABLED(ZONESTAR_12864OLED)
|
#if ENABLED(ZONESTAR_12864OLED)
|
||||||
|
@ -270,7 +270,7 @@ bool DiskIODriver_SPI_SD::init(const uint8_t sckRateID, const pin_t chipSelectPi
|
||||||
// Must supply min of 74 clock cycles with CS high.
|
// Must supply min of 74 clock cycles with CS high.
|
||||||
LOOP_L_N(i, 10) spiSend(0xFF);
|
LOOP_L_N(i, 10) spiSend(0xFF);
|
||||||
|
|
||||||
watchdog_refresh(); // In case init takes too long
|
hal.watchdog_refresh(); // In case init takes too long
|
||||||
|
|
||||||
// Command to go idle in SPI mode
|
// Command to go idle in SPI mode
|
||||||
while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
|
while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
|
||||||
|
@ -284,7 +284,7 @@ bool DiskIODriver_SPI_SD::init(const uint8_t sckRateID, const pin_t chipSelectPi
|
||||||
crcSupported = (cardCommand(CMD59, 1) == R1_IDLE_STATE);
|
crcSupported = (cardCommand(CMD59, 1) == R1_IDLE_STATE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
watchdog_refresh(); // In case init takes too long
|
hal.watchdog_refresh(); // In case init takes too long
|
||||||
|
|
||||||
// check SD version
|
// check SD version
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -306,7 +306,7 @@ bool DiskIODriver_SPI_SD::init(const uint8_t sckRateID, const pin_t chipSelectPi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watchdog_refresh(); // In case init takes too long
|
hal.watchdog_refresh(); // In case init takes too long
|
||||||
|
|
||||||
// Initialize card and send host supports SDHC if SD2
|
// Initialize card and send host supports SDHC if SD2
|
||||||
arg = type() == SD_CARD_TYPE_SD2 ? 0x40000000 : 0;
|
arg = type() == SD_CARD_TYPE_SD2 ? 0x40000000 : 0;
|
||||||
|
|
Loading…
Reference in a new issue