Infinite reset with leonardo using watchdog timer

Hey all,

Hit a weird snag today. I'm using the avrisp mk2 to program the Leonardo so I don't have the boot loader installed.

Everything is fine up until I implement the watchdog timer. I use wdt enable and disable at setup and it works fine too during normal operation.

Then I simulate a lock up and the unit reboots as predicted. Next thing I know, the MCU goes in to infinite reset. Not cool. The tx/RX LEDs are flashing wildly. I put the led13 to low on setup so I was able to see it was triggering every ~~16 ms. Suspicious.

Anyone have experience with this? I believe I missed something the arduino libs are doing at boot up.

Sorry for the lack of code as I'm writing this on a bus. It will come tomorrow when I get back to the lab. Maybe I will get lucky and someone knows off hand what I possibly missed.

Edit. Forgot to mention pin 0 & 1 are usually pulled high on init. I have them sensing and not for serial. Doesn't matter.
Edit2. I re-installed the bootloader and the sketch worked fine with the soft reset and watchdog timer. Very interesting. Still have the annoying problem with Windows locking the port. Still not solved without the bootloader.

Code snippet

#include <avr/wdt.h>

void setup(){
wdt_disable();
pinMode(13,OUTPUT);
digitalWrite(13,LOW);

digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);

Serial.begin(9600);
Serial.println("Alive");
}

void loop(){

if(Serial.available()){
char var = Serial.read();
if ( var == 'r'){
Serial.println("reboot");
digitalWrite(13,HIGH);
delay(5000);
cli();
wdt_enable(WDTO_15MS);
}
}
}

Looks like it was solved with the following snippet from avr's libc documentation avr-libc: <avr/wdt.h>: Watchdog timer handling.

#include <stdint.h>
#include <avr/wdt.h>

uint8_t mcusr_mirror attribute ((section (".noinit")));

void get_mcusr(void)
attribute((naked))
attribute((section(".init3")));
void get_mcusr(void)
{
mcusr_mirror = MCUSR;
MCUSR = 0;
wdt_disable();
}