From d489c92a1bc541d19df66f79501a91ba3f29764b Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Fri, 16 Apr 2021 09:56:43 +0800 Subject: [PATCH] Nuvoton: Fix hal_watchdog_kick() with WDT stopped According to HAL spec, hal_watchdog_kick() shall do nothing when WDT is stopped. --- targets/TARGET_NUVOTON/TARGET_M451/watchdog_api.c | 5 +++++ targets/TARGET_NUVOTON/TARGET_M480/watchdog_api.c | 5 +++++ targets/TARGET_NUVOTON/TARGET_NANO100/watchdog_api.c | 5 +++++ targets/TARGET_NUVOTON/TARGET_NUC472/watchdog_api.c | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/targets/TARGET_NUVOTON/TARGET_M451/watchdog_api.c b/targets/TARGET_NUVOTON/TARGET_M451/watchdog_api.c index 7fdb5775ba0..5b8d459d87c 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/watchdog_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/watchdog_api.c @@ -125,6 +125,11 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config) void hal_watchdog_kick(void) { + /* If a watchdog is not running, this function does nothing */ + if (!(WDT->CTL & WDT_CTL_WDTEN_Msk)) { + return; + } + wdt_timeout_rmn_clk = NU_MS2WDTCLK(wdt_timeout_reload_ms); watchdog_setup_cascade_timeout(); } diff --git a/targets/TARGET_NUVOTON/TARGET_M480/watchdog_api.c b/targets/TARGET_NUVOTON/TARGET_M480/watchdog_api.c index 985174ac785..18e160da3e8 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/watchdog_api.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/watchdog_api.c @@ -126,6 +126,11 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config) void hal_watchdog_kick(void) { + /* If a watchdog is not running, this function does nothing */ + if (!(WDT->CTL & WDT_CTL_WDTEN_Msk)) { + return; + } + wdt_timeout_rmn_clk = NU_MS2WDTCLK(wdt_timeout_reload_ms); watchdog_setup_cascade_timeout(); } diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/watchdog_api.c b/targets/TARGET_NUVOTON/TARGET_NANO100/watchdog_api.c index 3c92a5a4570..502f59bf3cb 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/watchdog_api.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/watchdog_api.c @@ -123,6 +123,11 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config) void hal_watchdog_kick(void) { + /* If a watchdog is not running, this function does nothing */ + if (!(WDT->CTL & WDT_CTL_WTE_Msk)) { + return; + } + wdt_timeout_rmn_clk = NU_MS2WDTCLK(wdt_timeout_reload_ms); watchdog_setup_cascade_timeout(); } diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/watchdog_api.c b/targets/TARGET_NUVOTON/TARGET_NUC472/watchdog_api.c index 94c65a0c67a..d760721363c 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/watchdog_api.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/watchdog_api.c @@ -124,6 +124,11 @@ watchdog_status_t hal_watchdog_init(const watchdog_config_t *config) void hal_watchdog_kick(void) { + /* If a watchdog is not running, this function does nothing */ + if (!(WDT->CTL & WDT_CTL_WDTEN_Msk)) { + return; + } + wdt_timeout_rmn_clk = NU_MS2WDTCLK(wdt_timeout_reload_ms); watchdog_setup_cascade_timeout(); }