PDA

View Full Version : Bootloader and Watchdog Timer



rbhollabaugh
01-06-2013, 08:08 PM
So I just tried using watchdog code I've used on 328s w/o bootloader and it works fine. So I tried similar code on the teensy++2.0. And now it seems the bootloader is out to lunch. Can not upload a new program.

The code I used:
#include <avr/wdt.h>

int ledPin = 6;

void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(200);
wdt_enable(WDTO_2S);
}

void loop() {
wdt_reset();
}

When I commented out the reset is when it hosed the bootloader. So the chip tried to reset from the WDT and the bootloader seems to be fried. What to do? Can I reload the bootloader? I have not seen it on the website anywhere?:(

PaulStoffregen
01-06-2013, 08:56 PM
This page has a progress for recovering.

http://www.pjrc.com/teensy/troubleshoot.html

The main trick is to hold the pushbutton before plugging in the USB cable, and release it only after the cable is fully mated. Make sure the Teensy Loader auto mode is off. It should detect the board. Then you can load another program and write it.

rbhollabaugh
01-06-2013, 10:31 PM
Paul,

Yes! that fixed it. So I guess the moral of the story is that I can't use WDT?

Thanks,
Rich

Prism
03-10-2019, 10:17 PM
Paul,

Yes! that fixed it. So I guess the moral of the story is that I can't use WDT?

Thanks,
Rich

I'm having a similar problem with a Teensy 2.0. Enabling the Watchdog Timer with
wdt_enable(WDTO_2S); causes the bootloader to start acting funny and I need to disconnect the cable and plug it again to recover.

Is there any verdict here? Does this mean we shouldn't use the Watchdog Timer with Teensy 2.0?

LDideas
07-19-2019, 01:31 PM
Hi All,

I realize this thread is quite old, but I haven't found any answers to this question, and thought this might be some helpful knowledge to share. Using the setup code in <avr/wdt.h>, I was not able to successfully get my Teensy 2.0 to reboot via WDT. My theory here is that the way the ATMEGA32U4 resets after the watchdog is tripped, is not compatible with how the Teensy 2.0 is setup? (Someone correct me if I'm wrong here). Anyhow, what I ended up doing was setting up the WDT so that it calls an interrupt, as opposed to performing an automatic reset, and then invoking the function _restart_Teensyduino_(); . So far this seems to be working for me. Here is how I've set up the code, which is essentially a modification of the WDT_Prescaler_Change() function example in the ATMEGA32U4 datasheet.




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

//WDT Interrupt which will soft reset the board
ISR(WDT_vect)
{
_restart_Teensyduino_();
}

void WDT_Prescaler_Change(void) {

// make sure wdt flag in mcusr isn't set...
MCUSR = MCUSR | (0xFF & (0 << WDRF));

//disable interrupts
cli();
/* Start timed sequence */
WDTCSR |= (1 << WDCE) | (1 << WDE);
/* Set new prescaler (time-out) value = 256kcycles (~2.0s) (Refer to table on pg61 to choose your timeout value) */
WDTCSR = (1 << WDIE) | (1 << WDP2) | (1 << WDP1) | (1 << WDP0);

//enable interrupts
sei();

}

void setup(){
//INITIALIZE WATCHDOG TIMER
wdt_reset();
WDT_Prescaler_Change();

}

void loop(){
wdt_reset();
}




I think this should be enough code to help get the WDT up and running. Cheers.