-
-
Notifications
You must be signed in to change notification settings - Fork 19.5k
Add Watchdog timer reset in kill() #3077
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
Add Watchdog timer reset in kill() #3077
Conversation
Add watchdog reset in the kill loop to simplify recovering.
Does this do what we want in all cases? From what I can see the watchdog timer is set up to have the board reset if Some interesting things keep coming up about resetting an Arduino with Watchdog enabled. This of course:
And… from this forum post at AVR Freaks we have:
The current procedure at startup for setting the Watchdog Timer is as follows: // Initialize watchdog with a 4 sec interrupt time
void watchdog_init() {
#if ENABLED(WATCHDOG_RESET_MANUAL)
// We enable the watchdog timer, but only for the interrupt.
// Take care, as this requires the correct order of operation, with interrupts disabled. See the datasheet of any AVR chip for details.
wdt_reset();
_WD_CONTROL_REG = _BV(_WD_CHANGE_BIT) | _BV(WDE);
_WD_CONTROL_REG = _BV(WDIE) | WDTO_4S;
#else
wdt_enable(WDTO_4S);
#endif
} If this is equivalent to the above discussion, then all is well. I think the main concern is that the watchdog reset apparatus might not always be started, and that this condition should be avoided. Marlin avoids it by doing watchdog reset pretty frequently, and on every reset. I haven't heard any complaints where resetting a board caused endless resets, but it's something to watch out for. |
@thinkyhead The watchdog is ought to catch unexpected endless loops in the code. The kill() loop is not unexpected. I suggest to make a simple test. Lets wait for some days. The day where Octoprint users will begin to complain about having to run down 3 stairs, to power cycle their machines, is not far. |
@Blue-Marlin Customarily when users have different needs we will make such options configurable through #define MANUAL_RESET_ON_KILL // Enable this option to require a manual reset on kill() |
This was exactly my suggestion on #3045 when this reset thing came to discussion. |
I'm seriously considering including this change even though it redefines the default behavior. I personally would prefer that if my printer locks up, it should stay locked up and not reboot on its own. Your points made in #3085 are compelling, especially surrounding the response of hosts and the In Configuration.h: a sub-option with //#define AUTO_RESET_ON_KILL // Enable this option to automatically reset the board on kill() In SanityCheck.h:: #if ENABLED(USE_WATCHDOG) && ENABLED(AUTO_RESET_ON_KILL) && ENABLED(AUTOSTART)
#error AUTO_RESET_ON_KILL combined with AUTOSTART considered risky. Comment this line if you only use AUTOSTART for harmless things.
#endif And finally in Marlin_main.cpp… #if ENABLED(USE_WATCHDOG) && DISABLED(AUTO_RESET_ON_KILL)
watchdog_reset();
#endif Another thought occurs to me, which is of course "Why would anyone use |
After reviewing the code I see that, yes, in fact, the whole point of Hopefully few users will have to deal with these things in the first place, but it's good to look at them once in a while. Indication of a failure state is always helpful. A hung machine that isn't responsive has to be prodded to determine the failed state. I would prefer to give some clear indication, if only toggling the configured LED pin as a visual alarm. (Audio alarms have been discussed and are considered … too alarming.) If it's immediately apparent by a flashing light that the machine has gone down then users can respond by resetting right away instead of trying the controller knob. Hosts assume that a machine is hung if it stops responding long enough. They can also look for the Marlin startup message and by that assume that a machine has been reset. But these have not been formalized. We have received requests from makers of host software to send more messages out about Marlin's states ("busy", "awaiting input", etc.). So, even in the "precarious" position of a machine that has gone into the |
Sounds sane your suggestion but I would still prefer to ship with The issue is not Marlin to go into a panic mode and need reset, the issue is when the watchdog kicks in people are obliged to power cycle the printer and for some people this may mean remove the plug from mains and plug it back again.. As it is today without When When The issue is when the user manually soft-resets the board. The Arduino bootloader is expected to disable the watchdog which it is not.. which means that after 4S of booting Marlin will go again into This bugfix will still lockup Marlin on the |
This cannot be counted upon, even according to Arduino's own documentation.
As I described above, during program initialization (in
I'm not seeing how this PR "disables" the watchdog. It just signals watchdog to stay alive with |
Add Watchdog timer reset in kill()
Merged this as basically an obvious bug-fix. Expected behavior for |
@jbrazio I guess language is the key for our initial misunderstanding. I don't think it needs an additional configuration option. The behaviour of kill() with activated watchdog is, with this change, the same as if the watchdog would not be activated. The advantage of the watchdog, to catch unexpected endless loops, is untouched. Have an other look at the kill() function. We explicitly disable software interrupts but the pure hardware watchdog timer interrupt (without WATCHDOG_RESET_MANUAL) still works! |
You're correct, |
Add watchdog reset in the kill loop to simplify recovering with Arduino Mega based boards..
Fix for #3076