zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.77k stars 6.57k forks source link

sam0: watchdog: Times out twice as fast as expected #25283

Closed KubaFYI closed 4 years ago

KubaFYI commented 4 years ago

The watchdog times out at twice the speed expected on a samd21-based Adafruit Feather M0.

In order to reproduce the problem I used the watchdog sample code modified to let the watchdog time out 30 times (so that I could time the behaviour accurately against a wall clock). Setting a timeout window of 1000ms has the whole thing complete in about 16sec, 2000ms times out in about 32sec etc.

I initially thought this might be because of an incorrectly setup/routed clock, but from what I could read in gclks_init() of soc_samd2x.c all seems alright at least in writing.

It might be worth someone else try to reproduce it with their hardware because I don't have other samd21-based boards lying around.

carlescufi commented 4 years ago

@pabigot and @nandojve could you please try to reproduce?

pabigot commented 4 years ago

I can't duplicate this on atsamd21_xpro. From what I can tell the timer operates correctly within the limits of the SAM D21 WDT.

Allowed intervals are 8 ms * 2^k for k in [0, 12), i.e. 8 ms, 16 ms, 32 ms, ..., 8 s, 16 s. Ignoring windowed mode, the configured period is rounded up to the smallest duration not less than the requested duration. The warning interrupt (when enabled) fires at half this duration.

So at 2000 ms max the warning interrupt will fire at 1 s, and in the sample will clear the watchdog, so the board will reset 2 s later at 3 s after boot. I've confirmed this relationship for several delays.

I don't see anything obvious about the adafruit_feather_m0_basic_proto that suggests a misconfiguration of clocks. I don't have that board to test directly.

Now: reading the description of your modification more carefully: If what you've done is set it up so the warning callback is invoked 30 times, then what you see is correct. At a 1000 ms timeout you're feeding the watchdog 30 times at a 500 ms interval (15 s), then getting a timeout 1000 ms after the last feed (16 s).

Does that explain it?

pabigot commented 4 years ago

@KubaFYI Could you verify that the analysis above and the observed behavior is correct?

nzmichaelh commented 4 years ago

The analysis LGTM

carlescufi commented 4 years ago

Closing due to inactivity, Please reopen if it's still an issue.