Description
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.