Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch to prevent Reboot loop when using watchdog #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ermtl
Copy link

@ermtl ermtl commented Nov 25, 2018

When resetting with the watchdog on AVR micros, the watchdog remains enabled after the reset, but with a very short 15ms timeout.
With the default bootloader, that creates a situation where the arduino constantly resets itself until physically powered off.

Here is a description of the problem:
https://github.com/arduino/Arduino/issues/4492
https://arduino.stackexchange.com/questions/2922/watchdog-timer-stuck-in-restart-loop-green-led-flashing/45281#45281

The patch adds the ability to use the ISR to perform a "soft" reset that will disable the watchdog before resetting. It solves the issue without having to reflash the bootloader with WATCHDOG_MODS
The patch behaves as expected when using the sleep function (even when exiting sleep by another interrupt).

Changes are in utility/WatchdogAVR.cpp and utility/WatchdogAVR.h

Since this is a AVR only problem, nothing is changed for other architectures.

To enable the soft reset, use a negative number in the Watchdog.enable function.
Watchdog.enable(4000); // This uses the hard reset but will hang in a boot loop on some boards (depending on the bootloader)
Watchdog.enable(-4000); // This will never hang and uses the soft reset
(adding an optional softReset parameter to Watchdog.enable could be a cleaner way to do it)

The BasicUsage.ino example can be modified as shown to prevent endless reset on arduinos with a bootloader that does not disable the watchdog.

When resetting with the watchdog on AVR micros, the watchdog remains enabled after the reset, but with a very short 15ms timeout.
With the default bootloader, that creates a situation where the arduino constantly resets itself until physically powered off.
The patch adds the ability to use the ISR to perform a "soft" reset that will disable the watchdog before resetting.
The patch behaves as expected when using the sleep function.
Since this is a AVR only problem, nothing is changed for other architectures.
To enable the soft reset, use a negative number in the Watchdog.enable function.
Watchdog.enable(4000); // This uses the hard reset but might hang on some boards (depending on the bootloader)
Watchdog.enable(-4000); // This will never hang and uses the soft reset
Corrects a bug if sleep was exited by another interrupt (the sleep timer interrupt would later reset the AVR when it times out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant