From 12da5bbd9e7a2fbd6a5728f58b526b5348eeb467 Mon Sep 17 00:00:00 2001 From: weycen76 <22557692+weycen76@users.noreply.github.com> Date: Fri, 30 Apr 2021 20:33:47 +0800 Subject: [PATCH] stm32:iwdg: reset counter after changing period. Fix the bug that the iwdg counter is not refreshed after the configurationis complete, if this counter is not refreshed after the configuration is completed, the first iwdg counting period will be as long as 26 seconds. Fixes: https://github.com/libopencm3/libopencm3/pull/1333 Reviewed-by: Karl Palsson --- lib/stm32/common/iwdg_common_all.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/stm32/common/iwdg_common_all.c b/lib/stm32/common/iwdg_common_all.c index 44b3b9b3..84268ef9 100644 --- a/lib/stm32/common/iwdg_common_all.c +++ b/lib/stm32/common/iwdg_common_all.c @@ -108,6 +108,9 @@ void iwdg_set_period_ms(uint32_t period) while (iwdg_reload_busy()); IWDG_KR = IWDG_KR_UNLOCK; IWDG_RLR = count & COUNT_MASK; + + /* Refresh counter after configuration is complete */ + iwdg_reset(); } /*---------------------------------------------------------------------------*/