mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
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 <tiago.medicci@espressif.com>
This commit is contained in:
parent
96d71ea565
commit
239d108ed7
1 changed files with 29 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue