From a7632df7f47a7489984f3741c4c49f0aae118a24 Mon Sep 17 00:00:00 2001 From: fenugrec Date: Thu, 17 Apr 2025 22:16:06 -0400 Subject: [PATCH] iwdg: START and UNLOCK values before polling Busy With code that uses IWDG and these operations: - user code initializes iwdg - user code jumps to USB-DFU - USB host triggers a USB exit (e.g. after reflashing, or even just a dummy dfu-util Reset/Exit command) - user code will hang in iwdg_prescaler_busy() called from iwdg_set_period_ms() --- lib/stm32/common/iwdg_common_all.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/stm32/common/iwdg_common_all.c b/lib/stm32/common/iwdg_common_all.c index b1b00f70..cbb831b7 100644 --- a/lib/stm32/common/iwdg_common_all.c +++ b/lib/stm32/common/iwdg_common_all.c @@ -102,11 +102,11 @@ void iwdg_set_period_ms(uint32_t period) prescale = PRESCALER_MAX; } - while (iwdg_prescaler_busy()); + IWDG_KR = IWDG_KR_START; IWDG_KR = IWDG_KR_UNLOCK; + while (iwdg_prescaler_busy()); IWDG_PR = prescale; while (iwdg_reload_busy()); - IWDG_KR = IWDG_KR_UNLOCK; IWDG_RLR = count & COUNT_MASK; /* Refresh counter after configuration is complete */