HAL support for 8s watchdog
This commit is contained in:
		@@ -36,7 +36,7 @@ void watchdogSetup() {
 | 
			
		||||
  #if ENABLED(USE_WATCHDOG)
 | 
			
		||||
 | 
			
		||||
    // 4 seconds timeout
 | 
			
		||||
    uint32_t timeout = 4000;
 | 
			
		||||
    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
 | 
			
		||||
 
 | 
			
		||||
@@ -25,6 +25,8 @@
 | 
			
		||||
 | 
			
		||||
#if ENABLED(USE_WATCHDOG)
 | 
			
		||||
 | 
			
		||||
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
 | 
			
		||||
 | 
			
		||||
#include "watchdog.h"
 | 
			
		||||
 | 
			
		||||
void watchdogSetup() {
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,8 @@
 | 
			
		||||
 | 
			
		||||
#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() {}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,5 @@
 | 
			
		||||
 */
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#define WDT_TIMEOUT   4000000 // 4 second timeout
 | 
			
		||||
 | 
			
		||||
void watchdog_init();
 | 
			
		||||
void HAL_watchdog_refresh();
 | 
			
		||||
 
 | 
			
		||||
@@ -28,6 +28,8 @@
 | 
			
		||||
#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.
 | 
			
		||||
@@ -52,7 +54,7 @@ void watchdog_init() {
 | 
			
		||||
  #else
 | 
			
		||||
    WDT_Init(WDT_CLKSRC_IRC, WDT_MODE_RESET);
 | 
			
		||||
  #endif
 | 
			
		||||
  WDT_Start(WDT_TIMEOUT);
 | 
			
		||||
  WDT_Start(WDT_TIMEOUT_US);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HAL_watchdog_refresh() {
 | 
			
		||||
 
 | 
			
		||||
@@ -21,8 +21,6 @@
 | 
			
		||||
 */
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#define WDT_TIMEOUT   4000000 // 4 second timeout
 | 
			
		||||
 | 
			
		||||
void watchdog_init();
 | 
			
		||||
void HAL_watchdog_refresh();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -24,28 +24,30 @@
 | 
			
		||||
 | 
			
		||||
#if ENABLED(USE_WATCHDOG)
 | 
			
		||||
 | 
			
		||||
  #include "watchdog.h"
 | 
			
		||||
#include "watchdog.h"
 | 
			
		||||
 | 
			
		||||
  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.
 | 
			
		||||
#define WDT_TIMEOUT_REG TERN(WATCHDOG_DURATION_8S, WDT_CONFIG_PER_CYC8192, WDT_CONFIG_PER_CYC4096) // 4 or 8 second timeout
 | 
			
		||||
 | 
			
		||||
    // 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)
 | 
			
		||||
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.
 | 
			
		||||
 | 
			
		||||
    WDT->CTRLA.bit.ENABLE = false;              // Disable watchdog for config
 | 
			
		||||
    SYNC(WDT->SYNCBUSY.bit.ENABLE);
 | 
			
		||||
  // 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->INTENCLR.reg = WDT_INTENCLR_EW;        // Disable early warning interrupt
 | 
			
		||||
    WDT->CONFIG.reg = WDT_CONFIG_PER_CYC4096;   // Set at least 4s period for chip reset
 | 
			
		||||
  WDT->CTRLA.bit.ENABLE = false;              // Disable watchdog for config
 | 
			
		||||
  SYNC(WDT->SYNCBUSY.bit.ENABLE);
 | 
			
		||||
 | 
			
		||||
    HAL_watchdog_refresh();
 | 
			
		||||
  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
 | 
			
		||||
 | 
			
		||||
    WDT->CTRLA.reg = WDT_CTRLA_ENABLE;          // Start watchdog now in normal mode
 | 
			
		||||
    SYNC(WDT->SYNCBUSY.bit.ENABLE);
 | 
			
		||||
  }
 | 
			
		||||
  HAL_watchdog_refresh();
 | 
			
		||||
 | 
			
		||||
  WDT->CTRLA.reg = WDT_CTRLA_ENABLE;          // Start watchdog now in normal mode
 | 
			
		||||
  SYNC(WDT->SYNCBUSY.bit.ENABLE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // USE_WATCHDOG
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -25,23 +25,26 @@
 | 
			
		||||
 | 
			
		||||
#if ENABLED(USE_WATCHDOG)
 | 
			
		||||
 | 
			
		||||
  #include "../../inc/MarlinConfig.h"
 | 
			
		||||
#define WDT_TIMEOUT_US TERN(WATCHDOG_DURATION_8S, 8000000, 4000000) // 4 or 8 second timeout
 | 
			
		||||
 | 
			
		||||
  #include "watchdog.h"
 | 
			
		||||
  #include <IWatchdog.h>
 | 
			
		||||
#include "../../inc/MarlinConfig.h"
 | 
			
		||||
 | 
			
		||||
  void watchdog_init() {
 | 
			
		||||
    #if DISABLED(DISABLE_WATCHDOG_INIT)
 | 
			
		||||
      IWatchdog.begin(4000000); // 4 sec timeout
 | 
			
		||||
    #endif
 | 
			
		||||
  }
 | 
			
		||||
#include "watchdog.h"
 | 
			
		||||
#include <IWatchdog.h>
 | 
			
		||||
 | 
			
		||||
  void HAL_watchdog_refresh() {
 | 
			
		||||
    IWatchdog.reload();
 | 
			
		||||
    #if DISABLED(PINS_DEBUGGING) && PIN_EXISTS(LED)
 | 
			
		||||
      TOGGLE(LED_PIN);  // heartbeat indicator
 | 
			
		||||
    #endif
 | 
			
		||||
  }
 | 
			
		||||
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 // ARDUINO_ARCH_STM32 && !STM32GENERIC
 | 
			
		||||
 
 | 
			
		||||
@@ -33,6 +33,13 @@
 | 
			
		||||
#include <libmaple/iwdg.h>
 | 
			
		||||
#include "watchdog.h"
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *  The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and
 | 
			
		||||
 *  625 reload value (counts down to 0)
 | 
			
		||||
 *  use 1250 for 8 seconds
 | 
			
		||||
 */
 | 
			
		||||
#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
 | 
			
		||||
 
 | 
			
		||||
@@ -27,13 +27,6 @@
 | 
			
		||||
 | 
			
		||||
#include <libmaple/iwdg.h>
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *  The watchdog clock is 40Khz. We need a 4 seconds interval, so use a /256 preescaler and
 | 
			
		||||
 *  625 reload value (counts down to 0)
 | 
			
		||||
 *  use 1250 for 8 seconds
 | 
			
		||||
 */
 | 
			
		||||
#define STM32F1_WD_RELOAD 625
 | 
			
		||||
 | 
			
		||||
// Arduino STM32F1 core now has watchdog support
 | 
			
		||||
 | 
			
		||||
// Initialize watchdog with a 4 second countdown time
 | 
			
		||||
 
 | 
			
		||||
@@ -25,31 +25,33 @@
 | 
			
		||||
 | 
			
		||||
#if ENABLED(USE_WATCHDOG)
 | 
			
		||||
 | 
			
		||||
  #include "watchdog.h"
 | 
			
		||||
#include "watchdog.h"
 | 
			
		||||
 | 
			
		||||
  IWDG_HandleTypeDef hiwdg;
 | 
			
		||||
#define WDT_TIMEOUT_COUNT TERN(WATCHDOG_DURATION_8S, 8192, 4096) // 4 or 8 second timeout
 | 
			
		||||
 | 
			
		||||
  void watchdog_init() {
 | 
			
		||||
    hiwdg.Instance = IWDG;
 | 
			
		||||
    hiwdg.Init.Prescaler = IWDG_PRESCALER_32; //32kHz LSI clock and 32x prescalar = 1024Hz IWDG clock
 | 
			
		||||
    hiwdg.Init.Reload = 4095;           //4095 counts = 4 seconds at 1024Hz
 | 
			
		||||
    if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
 | 
			
		||||
      //Error_Handler();
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      #if PIN_EXISTS(LED) && DISABLED(PINS_DEBUGGING)
 | 
			
		||||
        TOGGLE(LED_PIN);  // heartbeat indicator
 | 
			
		||||
      #endif
 | 
			
		||||
    }
 | 
			
		||||
IWDG_HandleTypeDef hiwdg;
 | 
			
		||||
 | 
			
		||||
void watchdog_init() {
 | 
			
		||||
  hiwdg.Instance = IWDG;
 | 
			
		||||
  hiwdg.Init.Prescaler = IWDG_PRESCALER_32; // 32kHz LSI clock and 32x prescalar = 1024Hz IWDG clock
 | 
			
		||||
  hiwdg.Init.Reload = WDT_TIMEOUT_COUNT - 1;
 | 
			
		||||
  if (HAL_IWDG_Init(&hiwdg) != HAL_OK) {
 | 
			
		||||
    //Error_Handler();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void HAL_watchdog_refresh() {
 | 
			
		||||
    /* Refresh IWDG: reload counter */
 | 
			
		||||
    if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
 | 
			
		||||
      /* Refresh Error */
 | 
			
		||||
      //Error_Handler();
 | 
			
		||||
    }
 | 
			
		||||
  else {
 | 
			
		||||
    #if PIN_EXISTS(LED) && DISABLED(PINS_DEBUGGING)
 | 
			
		||||
      TOGGLE(LED_PIN);  // heartbeat indicator
 | 
			
		||||
    #endif
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HAL_watchdog_refresh() {
 | 
			
		||||
  /* Refresh IWDG: reload counter */
 | 
			
		||||
  if (HAL_IWDG_Refresh(&hiwdg) != HAL_OK) {
 | 
			
		||||
    /* Refresh Error */
 | 
			
		||||
    //Error_Handler();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif // USE_WATCHDOG
 | 
			
		||||
#endif // STM32GENERIC && (STM32F4 || STM32F7)
 | 
			
		||||
 
 | 
			
		||||
@@ -27,9 +27,11 @@
 | 
			
		||||
 | 
			
		||||
#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 = 4000;
 | 
			
		||||
  WDOG_TOVALL = WDT_TIMEOUT_MS;
 | 
			
		||||
  WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -27,9 +27,11 @@
 | 
			
		||||
 | 
			
		||||
#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 = 4000;
 | 
			
		||||
  WDOG_TOVALL = WDT_TIMEOUT_MS;
 | 
			
		||||
  WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -19,31 +19,27 @@
 | 
			
		||||
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
#ifdef __IMXRT1062__
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * HAL Watchdog for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifdef __IMXRT1062__
 | 
			
		||||
 | 
			
		||||
#include "../../inc/MarlinConfig.h"
 | 
			
		||||
 | 
			
		||||
#if ENABLED(USE_WATCHDOG)
 | 
			
		||||
 | 
			
		||||
#include "watchdog.h"
 | 
			
		||||
 | 
			
		||||
// 4 seconds timeout
 | 
			
		||||
#define WDTO 4 //seconds
 | 
			
		||||
#define WDT_TIMEOUT TERN(WATCHDOG_DURATION_8S, 8, 4) // 4 or 8 second timeout
 | 
			
		||||
 | 
			
		||||
uint8_t timeoutval = (WDTO - 0.5f) / 0.5f;
 | 
			
		||||
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() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user