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 239d108ed7ec44c2a76e22e746ab65aef0ce9888 Author: Tiago Medicci Serrano <[email protected]> AuthorDate: Tue May 26 13:25:42 2026 +0200 xtensa/esp32s2: Re-apply WDT prescaler and timeout at start. Same issue as ESP32-S3: 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 wdt_lh_start() just before enabling the timer. Signed-off-by: Tiago Medicci Serrano <[email protected]> --- arch/xtensa/src/esp32s2/esp32s2_wdt_lowerhalf.c | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/arch/xtensa/src/esp32s2/esp32s2_wdt_lowerhalf.c b/arch/xtensa/src/esp32s2/esp32s2_wdt_lowerhalf.c index 27d94f2536e..495f3d44b0b 100644 --- a/arch/xtensa/src/esp32s2/esp32s2_wdt_lowerhalf.c +++ b/arch/xtensa/src/esp32s2/esp32s2_wdt_lowerhalf.c @@ -236,6 +236,33 @@ static int wdt_lh_start(struct watchdog_lowerhalf_s *lower) ESP32S2_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) + { + ESP32S2_MWDT_PRE(priv->wdt, MWDT_CLK_PRESCALER_VALUE); + } + + /* Re-apply the timeout value */ + + if (priv->timeout > 0) + { + if (priv->peripheral == TIMER) + { + ESP32S2_WDT_STO(priv->wdt, MWDT_TIMEOUT_MS(priv->timeout), + ESP32S2_WDT_STAGE0); + } + else if (priv->peripheral == RTC) + { + uint16_t rtc_cycles = ESP32S2_RWDT_CLK(priv->wdt); + ESP32S2_WDT_STO(priv->wdt, priv->timeout * rtc_cycles, + ESP32S2_WDT_STAGE0); + } + } + /* No User Handler */ if (priv->handler == NULL) @@ -271,6 +298,8 @@ static int wdt_lh_start(struct watchdog_lowerhalf_s *lower) ESP32S2_WDT_ENABLEINT(priv->wdt); } + ESP32S2_WDT_FEED(priv->wdt); + flags = enter_critical_section(); priv->lastreset = clock_systime_ticks(); ESP32S2_WDT_START(priv->wdt);
