From 3a768ba746fdb98990233bc83cdf33df682fd114 Mon Sep 17 00:00:00 2001 From: Ben McCrea Date: Fri, 13 Oct 2023 12:12:33 -0700 Subject: [PATCH] kernel/os: Fix issue that causes WDOG reset reason to be lost In the default irq handler, hal_watchdog_tickle() was called before doing a core dump but on Dialog da1469x this causes the reset reason to be lost, and reboot log was recording the reset reason as HAL_RESET_SOFT instead of HAL_RESET_WDOG. The issue is fixed by calling hal_watchdog_disable() instead of hal_watchdog_tickle() before doing a core dump. This PR also adds hal_watchdog_disable() to the HAL API for all MCUs (for now it is implemented only for Dialog da1469x and CMAC). --- hw/hal/include/hal/hal_watchdog.h | 5 +++++ hw/mcu/ambiq/apollo2/src/hal_watchdog.c | 6 ++++++ hw/mcu/ambiq/apollo3/src/hal_watchdog.c | 6 ++++++ hw/mcu/arc/snps/src/hal_watchdog.c | 5 +++++ hw/mcu/dialog/cmac/src/hal_watchdog.c | 7 +++++++ hw/mcu/dialog/da1469x/src/hal_watchdog.c | 6 ++++++ hw/mcu/microchip/pic32mx470f512h/src/hal_watchdog.c | 6 ++++++ hw/mcu/microchip/pic32mz/src/hal_watchdog.c | 6 ++++++ hw/mcu/mips/danube/src/hal_watchdog.c | 5 +++++ hw/mcu/native/src/hal_watchdog.c | 5 +++++ hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c | 6 ++++++ hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c | 6 ++++++ hw/mcu/nordic/nrf5340/src/hal_watchdog.c | 6 ++++++ hw/mcu/nordic/nrf5340_net/src/hal_watchdog.c | 5 +++++ hw/mcu/nordic/nrf91xx/src/hal_watchdog.c | 6 ++++++ hw/mcu/nxp/kinetis/src/hal_watchdog.c | 5 +++++ hw/mcu/nxp/mkw41z/src/hal_watchdog.c | 6 ++++++ hw/mcu/sifive/fe310/src/hal_watchdog.c | 6 ++++++ hw/mcu/stm/stm32_common/src/hal_watchdog.c | 6 ++++++ kernel/os/src/arch/cortex_m33/os_fault.c | 2 +- 20 files changed, 110 insertions(+), 1 deletion(-) diff --git a/hw/hal/include/hal/hal_watchdog.h b/hw/hal/include/hal/hal_watchdog.h index 8c946f1b6f..ce9047a2f7 100644 --- a/hw/hal/include/hal/hal_watchdog.h +++ b/hw/hal/include/hal/hal_watchdog.h @@ -51,6 +51,11 @@ int hal_watchdog_init(uint32_t expire_msecs); */ void hal_watchdog_enable(void); +/** + * Stops the watchdog. + */ +void hal_watchdog_disable(void); + /** * Tickles the watchdog. This needs to be done periodically, before * the value configured in :c:func:`hal_watchdog_init()` expires. diff --git a/hw/mcu/ambiq/apollo2/src/hal_watchdog.c b/hw/mcu/ambiq/apollo2/src/hal_watchdog.c index c4d57b3339..f5a0ef10c6 100644 --- a/hw/mcu/ambiq/apollo2/src/hal_watchdog.c +++ b/hw/mcu/ambiq/apollo2/src/hal_watchdog.c @@ -34,6 +34,12 @@ hal_watchdog_enable(void) /* XXX: Unimplemented. */ } +void +hal_watchdog_disable(void) +{ + /* XXX: Unimplemented. */ +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/ambiq/apollo3/src/hal_watchdog.c b/hw/mcu/ambiq/apollo3/src/hal_watchdog.c index c4d57b3339..f5a0ef10c6 100644 --- a/hw/mcu/ambiq/apollo3/src/hal_watchdog.c +++ b/hw/mcu/ambiq/apollo3/src/hal_watchdog.c @@ -34,6 +34,12 @@ hal_watchdog_enable(void) /* XXX: Unimplemented. */ } +void +hal_watchdog_disable(void) +{ + /* XXX: Unimplemented. */ +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/arc/snps/src/hal_watchdog.c b/hw/mcu/arc/snps/src/hal_watchdog.c index 930fc22eb1..eccca7798c 100644 --- a/hw/mcu/arc/snps/src/hal_watchdog.c +++ b/hw/mcu/arc/snps/src/hal_watchdog.c @@ -32,6 +32,11 @@ hal_watchdog_enable(void) { } +void +hal_watchdog_disable(void) +{ +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/dialog/cmac/src/hal_watchdog.c b/hw/mcu/dialog/cmac/src/hal_watchdog.c index cd3a7d3eef..5ce45de550 100644 --- a/hw/mcu/dialog/cmac/src/hal_watchdog.c +++ b/hw/mcu/dialog/cmac/src/hal_watchdog.c @@ -34,6 +34,13 @@ hal_watchdog_enable(void) hal_watchdog_tickle(); } +void +hal_watchdog_disable(void) +{ + GPREG->SET_FREEZE_REG |= GPREG_SET_FREEZE_REG_FRZ_CMAC_WDOG_Msk; + return; +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/dialog/da1469x/src/hal_watchdog.c b/hw/mcu/dialog/da1469x/src/hal_watchdog.c index d7e1df88a7..364e7c6b44 100644 --- a/hw/mcu/dialog/da1469x/src/hal_watchdog.c +++ b/hw/mcu/dialog/da1469x/src/hal_watchdog.c @@ -54,6 +54,12 @@ hal_watchdog_enable(void) GPREG->RESET_FREEZE_REG |= GPREG_RESET_FREEZE_REG_FRZ_SYS_WDOG_Msk; } +void +hal_watchdog_disable(void) +{ + GPREG->SET_FREEZE_REG |= GPREG_SET_FREEZE_REG_FRZ_SYS_WDOG_Msk; +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/microchip/pic32mx470f512h/src/hal_watchdog.c b/hw/mcu/microchip/pic32mx470f512h/src/hal_watchdog.c index b43344fb12..fdcf873c65 100644 --- a/hw/mcu/microchip/pic32mx470f512h/src/hal_watchdog.c +++ b/hw/mcu/microchip/pic32mx470f512h/src/hal_watchdog.c @@ -39,6 +39,12 @@ hal_watchdog_enable(void) WDTCONSET = _WDTCON_ON_MASK; } +void +hal_watchdog_disable(void) +{ + return; +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/microchip/pic32mz/src/hal_watchdog.c b/hw/mcu/microchip/pic32mz/src/hal_watchdog.c index ab875df8a8..0316dd269f 100644 --- a/hw/mcu/microchip/pic32mz/src/hal_watchdog.c +++ b/hw/mcu/microchip/pic32mz/src/hal_watchdog.c @@ -39,6 +39,12 @@ hal_watchdog_enable(void) WDTCONSET = _WDTCON_ON_MASK; } +void +hal_watchdog_disable(void) +{ + return; +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/mips/danube/src/hal_watchdog.c b/hw/mcu/mips/danube/src/hal_watchdog.c index 392b967ccc..ed9fb401b4 100644 --- a/hw/mcu/mips/danube/src/hal_watchdog.c +++ b/hw/mcu/mips/danube/src/hal_watchdog.c @@ -32,6 +32,11 @@ hal_watchdog_enable(void) { } +void +hal_watchdog_disable(void) +{ +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/native/src/hal_watchdog.c b/hw/mcu/native/src/hal_watchdog.c index 81a1bb70b6..77b12a2324 100644 --- a/hw/mcu/native/src/hal_watchdog.c +++ b/hw/mcu/native/src/hal_watchdog.c @@ -30,6 +30,11 @@ hal_watchdog_enable(void) { } +void +hal_watchdog_disable(void) +{ +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c b/hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c index d677792833..6700a2c8e4 100644 --- a/hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c +++ b/hw/mcu/nordic/nrf51xxx/src/hal_watchdog.c @@ -66,6 +66,12 @@ hal_watchdog_enable(void) NRF_WDT->TASKS_START = 1; } +void +hal_watchdog_disable(void) +{ + return; +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c b/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c index cfbaff6363..9d230a3ced 100644 --- a/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c +++ b/hw/mcu/nordic/nrf52xxx/src/hal_watchdog.c @@ -69,6 +69,12 @@ hal_watchdog_enable(void) NRF_WDT->TASKS_START = 1; } +void +hal_watchdog_disable(void) +{ + return; +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/nordic/nrf5340/src/hal_watchdog.c b/hw/mcu/nordic/nrf5340/src/hal_watchdog.c index 19a26b99c2..ad81dc6d55 100644 --- a/hw/mcu/nordic/nrf5340/src/hal_watchdog.c +++ b/hw/mcu/nordic/nrf5340/src/hal_watchdog.c @@ -71,6 +71,12 @@ hal_watchdog_enable(void) NRF_WDT0->TASKS_START = 1; } +void +hal_watchdog_disable(void) +{ + return; +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/nordic/nrf5340_net/src/hal_watchdog.c b/hw/mcu/nordic/nrf5340_net/src/hal_watchdog.c index 9c9af98896..b0d79601e7 100644 --- a/hw/mcu/nordic/nrf5340_net/src/hal_watchdog.c +++ b/hw/mcu/nordic/nrf5340_net/src/hal_watchdog.c @@ -70,6 +70,11 @@ hal_watchdog_enable(void) NRF_WDT_NS->TASKS_START = 1; } +void +hal_watchdog_disable(void) +{ +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/nordic/nrf91xx/src/hal_watchdog.c b/hw/mcu/nordic/nrf91xx/src/hal_watchdog.c index ff0a74547d..83f3169b67 100644 --- a/hw/mcu/nordic/nrf91xx/src/hal_watchdog.c +++ b/hw/mcu/nordic/nrf91xx/src/hal_watchdog.c @@ -70,6 +70,12 @@ hal_watchdog_enable(void) NRF_WDT->TASKS_START = 1; } +void +hal_watchdog_disable(void) +{ + return; +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/nxp/kinetis/src/hal_watchdog.c b/hw/mcu/nxp/kinetis/src/hal_watchdog.c index 9d755e7160..85dfd13c36 100644 --- a/hw/mcu/nxp/kinetis/src/hal_watchdog.c +++ b/hw/mcu/nxp/kinetis/src/hal_watchdog.c @@ -65,6 +65,11 @@ void hal_watchdog_enable(void) #endif } +void hal_watchdog_disable(void) +{ + return; +} + void hal_watchdog_tickle(void) { #ifndef WATCHDOG_STUB diff --git a/hw/mcu/nxp/mkw41z/src/hal_watchdog.c b/hw/mcu/nxp/mkw41z/src/hal_watchdog.c index afda40e988..eccbacd2ac 100644 --- a/hw/mcu/nxp/mkw41z/src/hal_watchdog.c +++ b/hw/mcu/nxp/mkw41z/src/hal_watchdog.c @@ -33,6 +33,12 @@ hal_watchdog_enable(void) return; } +void +hal_watchdog_disable(void) +{ + return; +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/sifive/fe310/src/hal_watchdog.c b/hw/mcu/sifive/fe310/src/hal_watchdog.c index 9e4ef057c4..3229cb7584 100644 --- a/hw/mcu/sifive/fe310/src/hal_watchdog.c +++ b/hw/mcu/sifive/fe310/src/hal_watchdog.c @@ -97,6 +97,12 @@ hal_watchdog_enable(void) #endif } +void +hal_watchdog_disable(void) +{ + return; +} + void hal_watchdog_tickle(void) { diff --git a/hw/mcu/stm/stm32_common/src/hal_watchdog.c b/hw/mcu/stm/stm32_common/src/hal_watchdog.c index 12159404a1..80e6070f69 100644 --- a/hw/mcu/stm/stm32_common/src/hal_watchdog.c +++ b/hw/mcu/stm/stm32_common/src/hal_watchdog.c @@ -60,6 +60,12 @@ hal_watchdog_enable(void) HAL_IWDG_Init(&g_wdt_cfg); } +void +hal_watchdog_disable(void) +{ + return; +} + void hal_watchdog_tickle(void) { diff --git a/kernel/os/src/arch/cortex_m33/os_fault.c b/kernel/os/src/arch/cortex_m33/os_fault.c index 4aa0376ca0..8b99b19542 100644 --- a/kernel/os/src/arch/cortex_m33/os_fault.c +++ b/kernel/os/src/arch/cortex_m33/os_fault.c @@ -244,7 +244,7 @@ os_default_irq(struct trap_frame *tf) #endif #if MYNEWT_VAL(OS_COREDUMP) - hal_watchdog_tickle(); + hal_watchdog_disable(); #if MYNEWT_VAL(OS_COREDUMP_CB) os_coredump_cb(tf); #else