Patch to prevent Reboot loop when using watchdog#16
Open
ermtl wants to merge 2 commits into
Open
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).
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.