This commit is contained in:
andreika-git 2023-11-29 13:59:38 +02:00 committed by rusefillc
parent 63d6154085
commit 74b2ff6468
4 changed files with 31 additions and 8 deletions

View File

@ -149,7 +149,7 @@ void writeToFlashNow() {
// there's no wdgStop() for STM32, so we cannot disable it.
// we just set a long timeout of 5 secs to wait until flash is done.
startWatchdog(5000);
startWatchdog(WATCHDOG_FLASH_TIMEOUT_MS);
#if EFI_STORAGE_MFS == TRUE
mfs_error_t err;

View File

@ -3,6 +3,7 @@
#include "rusefi_types.h"
#include "port_mpu_util.h"
#include "mpu_watchdog.h"
#ifdef __cplusplus
@ -15,11 +16,6 @@ void jump_to_openblt();
void causeHardFault();
bool allowFlashWhileRunning();
// 300 ms is our default timeout (we use 'int' for compatibility with addConsoleActionI())
void startWatchdog(int timeoutMs = 300);
void setWatchdogResetPeriod(int resetMs);
void tryResetWatchdog();
bool ramReadProbe(volatile const char *read_address);
#if defined(STM32F4)
bool isStm32F42x();

View File

@ -0,0 +1,28 @@
/**
* @file mpu_watchdog.h
* @brief Hardware Independent Watchdog (IWDG) high-level API
*
* @date Nov 28, 2023
* @author Andrey Belomutskiy, (c) 2012-2023
* @author andreika <prometheus.pcb@gmail.com>
*/
#pragma once
// 100 ms is our empiric choice based on 2 * SLOW_CALLBACK_PERIOD_MS
#define WATCHDOG_RESET_MS (2 * SLOW_CALLBACK_PERIOD_MS)
// 300 ms is our default timeout
#define WATCHDOG_TIMEOUT_MS (3 * WATCHDOG_RESET_MS)
// 5 secs should be enough to wait until
#define WATCHDOG_FLASH_TIMEOUT_MS 5000
// we use 'int' for compatibility with addConsoleActionI()
// can be called multiple times to change the timeout
void startWatchdog(int timeoutMs = WATCHDOG_TIMEOUT_MS);
// Can be called for debug reasons to test the watchdog
void setWatchdogResetPeriod(int resetMs);
// A reset is done only if enough time has passed since the last reset.
void tryResetWatchdog();

View File

@ -137,8 +137,7 @@ void baseMCUInit(void) {
BOR_Set(BOR_Level_1); // one step above default value
// 100 ms is our empiric choice based on 2 * SLOW_CALLBACK_PERIOD_MS
setWatchdogResetPeriod(100);
setWatchdogResetPeriod(WATCHDOG_RESET_MS);
startWatchdog();
}