Skip to content

Using watchdog timer on Leonardo / 32u4 breaks bootloader uploads #6077

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

Closed
JediJeremy opened this issue Mar 15, 2017 · 1 comment
Closed

Comments

@JediJeremy
Copy link

This took me a while to figure out, and I'm still not 100% sure of the cause, but this is the gist. The following program will "brick" a leonardo / 32u4 so that you can't program it anymore without physical access to the reset button. (which is a MAJOR problem for any finished embedded project)

// external libraries
#include <avr/wdt.h>

void setup() {
Serial.begin(57600);
wdt_enable(WDTO_1S);
}

void loop() {
wdt_reset();
}

Looking into it, it turns out the USB programming process uses the watchdog timer to "reboot" the controller after seeing the 1200-baud serial open/close signal. It seems that if your main program loop is calling wdt_reset(), the reboot into the bootloader never occurs, and uploads fail.

I mostly use 32u4 based Arduinos (Leonardo, pro micros, etc) and in a recent project I wanted to make it extra-reliable because it's controlling 200 watts of power, and you don't want that going haywire. But I apparently can't use the WDT. I get the choice of an unsafe toy, or a reliable brick.

Meanwhile, you've got all those articles extolling the virtues of the watchdog timer, and not ONCE do you mention that it screws with USB uploads to the 32u4. Did you never test it? It's a pretty essential embedded feature. The forums are full of people with this problem. One person tracked it back into the catarina bootloader.

Frankly, this is the kind of amateur-hour crap I've come to expect from Arduino. The Leonardo is a lovely piece of hardware, but you haven't bothered to put the time in to support the platform beyond the trivial. This issue has already cost me days of time and uncertainty, and I'm going to have to spend the rest of the day disassembling prototype hardware to get access again, now that I understand what's been bricking them.

@facchinm
Copy link
Member

See #6055 and #6064 for possible solutions. The easy upload procedure is intended for tinkerers and hackers, not for production environments. In fact, if you have important equipment attached to the board you should never update it in-place since the bootloader can mess up with the pins state.

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

No branches or pull requests

2 participants