-
Notifications
You must be signed in to change notification settings - Fork 13.3k
FAQ Section Updated about Watchdog resets #2533
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
Open
pasko-zh
wants to merge
5
commits into
esp8266:master
Choose a base branch
from
pasko-zh:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,103 @@ You will see this issue only if serial upload was not followed by a physical res | |
|
||
Ref. [#1017](https://github.com/esp8266/Arduino/issues/1017), [#1107](https://github.com/esp8266/Arduino/issues/1107), [#1782](https://github.com/esp8266/Arduino/issues/1782) | ||
|
||
|
||
### I'm getting these Watchdog Resets "wdt reset"�How can I avoid them? | ||
The esp8266 is equipped with two watchdog timers: A software watchdog and a hardware watchdog. If you don't understand why microcontrollers need a watchdog (timer), you may first read [here](http://www.embedded.com/electronics-blogs/beginner-s-corner/4023849/Introduction-to-Watchdog-Timers). | ||
|
||
When your sketch is running�either in the `setup` or during the `loop`�you have to make sure to feed the watchdog periodically. Otherwise "it will bite" and the watchdog reset will stop your sketch. The basic operation is illustrated in the following picture: | ||
 | ||
|
||
|
||
**How does the esp8266 Arduino Core feed the watchdog(s)?** | ||
From the perspective of your Arduino sketch, the basic feeding is implicit: Everytime an iteration of your main loop starts again, i.e. it hits the `loop` statement, (1) takes place and both watchdogs are fed. Esp8266 Arduino libraries, especially core libraries like for instance the `ESP8266WiFi` library take care of feeding the watchdogs, too. Thus, normally you don't have to feed them explicitly. | ||
|
||
**When and why should I feed the watchdog(s) explicitly?** | ||
The software watchdog bites exactly every 3.2 seconds, the hardware watchdog every 7�8 seconds. If your sketch contains code which could exceed running for 3.2 seconds you must feed the watchdogs. I.e. you have to feed them explicitly by calling | ||
|
||
- `yield()` | ||
or | ||
- `delay(...)` | ||
|
||
Note that calling `delayMicroseconds(...)` does **not** feed the watchdogs! | ||
|
||
**Can I disable the watchdogs?** | ||
You can disable the software watchdog but you **cannot** disable the hardware watchdog. Furthermore, you **cannot** change the intervals of the watchdogs timers. | ||
|
||
The following code snippet shows you how to disable the software watchdog and how to feed the hardware watchdog periodically. | ||
```c | ||
extern "C" { | ||
#include "user_interface.h" | ||
} | ||
int j = 0; | ||
unsigned long a, b; | ||
|
||
void setup() { | ||
delay(1000); // This feeds both watchdogs | ||
Serial.begin(115200); | ||
Serial.println("Setup..."); | ||
} | ||
// This function keeps the cpu busy for 1 second by doing stupid NOPs | ||
void ICACHE_RAM_ATTR busy_1second() { | ||
unsigned int i, iterations; | ||
if (F_CPU == 160000000) { | ||
iterations = 13333332; | ||
} | ||
else { | ||
iterations = 6666666; | ||
} | ||
|
||
for (i = 0; i < iterations; i++) { | ||
asm( | ||
"NOP;" | ||
"NOP;" | ||
"NOP;" | ||
"NOP;" | ||
"NOP;" | ||
"NOP;" | ||
"NOP;" | ||
); | ||
} | ||
} | ||
void loop() { | ||
Serial.println("Getting busy in 3 seconds..."); | ||
delay(3000); | ||
Serial.println("now!"); | ||
system_soft_wdt_stop(); // Disable Software watchdog | ||
system_soft_wdt_feed(); // Feed Hardware Watchdog | ||
for (j = 1; j < 20; j++) { | ||
a = micros(); | ||
busy_1second(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be replaced with a more intuitive |
||
b = micros(); | ||
Serial.println(b - a); | ||
// Feed Hardware Watchdog every 6 seconds | ||
if (j % 6 == 0) { | ||
system_soft_wdt_feed(); | ||
Serial.println("HW Dog fed! Miam miam :-o "); | ||
} | ||
} | ||
system_soft_wdt_feed(); | ||
system_soft_wdt_restart(); | ||
} | ||
``` | ||
And it will give you the following output: | ||
``` | ||
Getting busy in 3 seconds... | ||
now! | ||
1000002 | ||
1000007 | ||
1000001 | ||
1000000 | ||
1000000 | ||
1000000 | ||
HW Dog fed! Miam miam :-o | ||
1000001 | ||
1000007 | ||
1000000 | ||
1000001 | ||
1000001 | ||
1000000 | ||
HW Dog fed! Miam miam :-o | ||
1000000 | ||
... | ||
``` |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pasko-zh, I think my comment was not to the point. Sorry, and let me be more specific. I would rephrase:
to:
Otherwise "it will bite" and the watchdog will reset your sketch.
or:
Otherwise "it will bite" and the watchdog will restart your module.
I think that "stop sketch" may confuse people, while "restart" or "reset" better explains what the watchdog does if not fed.
Thank you again for contributing to FAQ 👍
Krzysztof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okey... I will change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went for "restart" your sketch, which explains it better than stop your sketch