From ffa84d1224958f37902d0dac091c55617d7873d6 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 3 Jun 2024 12:36:21 +0200 Subject: [PATCH 1/2] Watchdog: OTA, Remove mbed_watchdog_trigger_reset Hack to trigger board reset --- src/ota/implementation/OTANanoRP2040.cpp | 2 -- src/utility/watchdog/Watchdog.cpp | 15 --------------- src/utility/watchdog/Watchdog.h | 4 ---- 3 files changed, 21 deletions(-) diff --git a/src/ota/implementation/OTANanoRP2040.cpp b/src/ota/implementation/OTANanoRP2040.cpp index 5b1266f6..7dad7baf 100644 --- a/src/ota/implementation/OTANanoRP2040.cpp +++ b/src/ota/implementation/OTANanoRP2040.cpp @@ -83,8 +83,6 @@ OTACloudProcessInterface::State NANO_RP2040OTACloudProcess::flashOTA() { } OTACloudProcessInterface::State NANO_RP2040OTACloudProcess::reboot() { - mbed_watchdog_trigger_reset(); - /* If watchdog is enabled we should not reach this point */ NVIC_SystemReset(); return Resume; // This won't ever be reached diff --git a/src/utility/watchdog/Watchdog.cpp b/src/utility/watchdog/Watchdog.cpp index 942b569f..19034026 100644 --- a/src/utility/watchdog/Watchdog.cpp +++ b/src/utility/watchdog/Watchdog.cpp @@ -131,21 +131,6 @@ static void mbed_watchdog_enable_network_feed(NetworkAdapter ni) #endif } } - -void mbed_watchdog_trigger_reset() -{ - watchdog_config_t cfg; - cfg.timeout_ms = 1; - - if (hal_watchdog_init(&cfg) == WATCHDOG_STATUS_OK) { - is_watchdog_enabled = true; - while(1){} - } - else { - DEBUG_WARNING("%s: watchdog could not be reconfigured", __FUNCTION__); - } - -} #endif /* ARDUINO_ARCH_MBED */ #if defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_MBED) diff --git a/src/utility/watchdog/Watchdog.h b/src/utility/watchdog/Watchdog.h index 3bfd3545..2ba43a87 100644 --- a/src/utility/watchdog/Watchdog.h +++ b/src/utility/watchdog/Watchdog.h @@ -34,8 +34,4 @@ void watchdog_reset(); void watchdog_enable_network_feed(NetworkAdapter ni); #endif /* (ARDUINO_ARCH_SAMD) || (ARDUINO_ARCH_MBED) */ -#ifdef ARDUINO_ARCH_MBED -void mbed_watchdog_trigger_reset(); -#endif /* ARDUINO_ARCH_MBED */ - #endif /* ARDUINO_AIOTC_UTILITY_WATCHDOG_H_ */ From 03b69d3f9f8bcbb84839dcde7bca796a9c33eb62 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 2 May 2024 17:11:52 +0200 Subject: [PATCH 2/2] Watchdog: use mbed API to enable and trigger watchdog --- src/utility/watchdog/Watchdog.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/utility/watchdog/Watchdog.cpp b/src/utility/watchdog/Watchdog.cpp index 19034026..d4723406 100644 --- a/src/utility/watchdog/Watchdog.cpp +++ b/src/utility/watchdog/Watchdog.cpp @@ -33,7 +33,7 @@ #endif /* ARDUINO_ARCH_SAMD */ #ifdef ARDUINO_ARCH_MBED -# include +# include # define PORTENTA_H7_WATCHDOG_MAX_TIMEOUT_ms (32760) # define NANO_RP2040_WATCHDOG_MAX_TIMEOUT_ms (8389) # define EDGE_CONTROL_WATCHDOG_MAX_TIMEOUT_ms (65536) @@ -42,7 +42,7 @@ /****************************************************************************** * GLOBAL VARIABLES ******************************************************************************/ -#if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_MBED) +#if defined(ARDUINO_ARCH_SAMD) static bool is_watchdog_enabled = false; #endif @@ -96,18 +96,15 @@ static void mbed_watchdog_enable() # error "You need to define the maximum possible timeout for this architecture." #endif - if (hal_watchdog_init(&cfg) == WATCHDOG_STATUS_OK) { - is_watchdog_enabled = true; - } - else { + if (!mbed::Watchdog::get_instance().start(cfg.timeout_ms)) { DEBUG_WARNING("%s: watchdog could not be enabled", __FUNCTION__); } } static void mbed_watchdog_reset() { - if (is_watchdog_enabled) { - hal_watchdog_kick(); + if (mbed::Watchdog::get_instance().is_running()) { + mbed::Watchdog::get_instance().kick(); } }