This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 8e51220447a937140a8c17084903a80f6f0c3c00 Author: Tiago Medicci Serrano <[email protected]> AuthorDate: Tue May 26 13:26:37 2026 +0200 xtensa/esp32: Re-apply WDT prescaler and timeout at start. Same issue as ESP32-S3/S2: with BOARD_LATE_INITIALIZE, the constructor function enable_timer_group0_for_calibration() resets Timer Group 0 registers after board_late_initialize() has configured the MWDT0 prescaler, causing the watchdog to fire at an incorrect rate. Re-apply the prescaler, timeout, and feed the WDT counter in esp32_wdt_start() just before enabling the timer. Signed-off-by: Tiago Medicci Serrano <[email protected]> --- arch/xtensa/src/esp32/esp32_wdt_lowerhalf.c | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/xtensa/src/esp32/esp32_wdt_lowerhalf.c b/arch/xtensa/src/esp32/esp32_wdt_lowerhalf.c index 77ed09dcf5f..d071341c0d2 100644 --- a/arch/xtensa/src/esp32/esp32_wdt_lowerhalf.c +++ b/arch/xtensa/src/esp32/esp32_wdt_lowerhalf.c @@ -193,6 +193,36 @@ static int esp32_wdt_start(struct watchdog_lowerhalf_s *lower) ESP32_WDT_UNLOCK(priv->wdt); + /* Re-apply the prescaler for MWDT in case the Timer Group + * registers were reset after initialization (e.g. by a + * constructor function that resets the peripheral). + */ + + if (priv->peripheral == TIMER) + { + ESP32_WDT_PRE(priv->wdt, PRE_VALUE); + } + + /* Re-apply the timeout value */ + + if (priv->timeout > 0) + { + if (priv->peripheral == TIMER) + { + ESP32_WDT_STO(priv->wdt, + priv->timeout * MS_CYCLES_TIMER, STAGE_0); + } + else + { + uint16_t rtc_cycles = ESP32_RWDT_CLK(priv->wdt); + if (rtc_cycles > 0) + { + ESP32_WDT_STO(priv->wdt, + priv->timeout * rtc_cycles, STAGE_0); + } + } + } + /* No User Handler */ if (priv->handler == NULL) @@ -226,6 +256,8 @@ static int esp32_wdt_start(struct watchdog_lowerhalf_s *lower) ESP32_WDT_ENABLEINT(priv->wdt); } + ESP32_WDT_FEED(priv->wdt); + flags = spin_lock_irqsave(&priv->lock); priv->lastreset = clock_systime_ticks(); ESP32_WDT_START(priv->wdt);
