Tags:
view all tags
%DASHBOARD{ section="dashboard_start" }% %DASHBOARD{ section="banner" image="%PUBURLPATH%/Cosmac/ForthSTM32WB/nucleo-header.jpg" title="Watchdog" titlestyle="color:#F00000;" }% %DASHBOARD{ section="box_start" title="Intro" width="485" height="280"}% For serious real time systems you need a [[https://en.wikipedia.org/wiki/Watchdog_timer][watchdog]] to detect and recover from malfunctions e.g. deadlocks. STM32 MCUs have two of them: independent watchdog (IWDG) and window watchdog (WWDG). I prefer the WWDG because it has a time window (as the name implies) and an interrupt just before the watchdog is going to bite. Window means that the feeding time has to be in a time window (interval), to feed to early is harmful too. The early wakeup interrupt can be used to bring the system into a save state or log something before the CPU is going into reset. There is a thread only for kicking (regularly feed) the watchdog. This thread has the second lowest priority (just higher than the idle thread), if any task does not want to give up control, the watchdog thread does not get any more CPU time and cannot feed the watchdog and the watchdog will bite after the timeout. %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" title="Contents" width="460" height="280"}% %TOC% %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="600" }% ---+ How to use <verbatim> watchdog ( -- ) Activate watchdog watchdog? ( -- flag ) Has the WATCHDOG bitten? watchdog# ( -- u ) How many times has the watchdog bitten since cold startup? watchdog@ ( -- addr ) Address where the atchdog bit </verbatim> If a thread takes longer than about 500 ms the watchdog will bite and a reset occurs. As long the thread waits for an event e.g. file operation, keyboard (the thread is blocked), nothing happens. <pre> <b>: forever begin again ; [RET]</b> ok. <b>watchdog? .[RET]</b> 0 ok. <b>watchdog[RET]</b> ok. <b>forever[RET]</b> BOOM Mecrisp-Stellaris RA 2.5.4 by Matthias Koch. Mecrisp-Cube 1.4.4 for STM32WB55, 63/128 KiB RAM/FLASH dictionary (C) 2021 peter@spyr.ch * Firmware Package STM32Cube FW_WB V1.11.0, USB-CDC, BLE Stack 5.0 (C) 2021 STMicroelectronics * CMSIS-RTOS V2 FreeRTOS wrapper, FreeRTOS Kernel V10.3.1 (C) 2020 Amazon.com * FatFs for internal flash and microSD - Generic FAT fs module R0.12c (C) 2017 ChaN * tiny vi - part of BusyBox (C) 2000, 2001 Sterling Huxley <b>watchdog? .[RET]</b> -1 ok. <b>watchdog# .[RET]</b> 1 ok. </pre> Do not activate the watchdog in debugging mode. <verbatim> watchdog? [IF] .( Watchdog has bitten at ) watchdog@ hex. .( , # bites: ) watchdog# . cr [THEN] </verbatim> %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="box_start" width="992" height="500" }% ---+ Implementation For !STM32WB55: <verbatim> WWDG clock (Hz) = PCLK1 / (4096 * Prescaler) PCLK1 is 32 MHz, Prescaler is 64, clock = 32 MHz / (4096 * 64) = 122 Hz WWDG timeout (mS) = 1000 * (T[5;0] + 1) / WWDG clock (Hz) timeout = 1000 * 64 / 122 = 524 ms window = 1000 * 48 / 122 = 393 ms </verbatim> I choose 450 ms period to feed the watchdog. RTC registers are used for accounting the watchdog bites. Those registers are not affected by the reset. For implementation details see: * https://github.com/spyren/Mecrisp-Cube/blob/master/peripherals/watchdog.c * https://github.com/spyren/Mecrisp-Cube/blob/master/peripherals/watchdog.h * https://github.com/spyren/Mecrisp-Cube/blob/master/Core/Src/wwdg.c * https://github.com/spyren/Mecrisp-Cube/blob/master/peripherals/clock.h %DASHBOARD{ section="box_end" }% %DASHBOARD{ section="dashboard_end" }% -- %USERSIG{PeterSchmid - 2021-12-25}% <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />This work by <a xmlns:cc="http://creativecommons.org/ns#" href="http://spyr.ch" property="cc:attributionName" rel="cc:attributionURL">Peter Schmid</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.
Edit
|
Attach
|
Watch
|
P
rint version
|
H
istory
:
r5
<
r4
<
r3
<
r2
<
r1
|
B
acklinks
|
V
iew topic
|
Raw edit
|
More topic actions...
Topic revision: r4 - 2021-12-30
-
PeterSchmid
Home
Site map
Cosmac web
MRR web
MecrispCube web
SuperRandonnee web
TWiki web
Ursula web
Velo web
MecrispCube Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Edit
Attach
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback