Jumping to bootloader and got stuck...

Status
Not open for further replies.
Hi All,

I used the simple code below with Teensy 2.0 for jumping to boot loader but it's not returning to user code. Seems it stuck at the boot loader and waiting for a firmware update?
What else is needed to make it continue from boot loader back to user code?

Thanks in advance,
Tako

#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <PS2Keyboard.h>

const int ledPin = 11;
const int DataPin = 8;
const int IRQpin = 5;

PS2Keyboard keyboard;

void setup() {
pinMode(ledPin, OUTPUT);
delay(1000);
}

void bootloader_jump(void) {
cli();
// disable watchdog, if enabled
// disable all peripherals
UDCON = 1;
USBCON = (1<<FRZCLK); // disable USB
UCSR1B = 0;
_delay_ms(5);
EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0;
DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0;
PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
asm volatile("jmp 0x7E00");
}

void loop() {
// digitalWrite(ledPin, HIGH); // set the LED on
// delay(500); // wait for a second

delay(10000);
bootloader_jump();
//_restart_Teensyduino_();

// digitalWrite(ledPin, LOW); // set the LED off
// delay(1000); // wait for a second

}
 
I just want to ask: What is your purpose in jumping to the bootloader? (Ie., what are you trying to achieve?)

To the best of my understanding the Teensy the code above is ran on will wait for some (fairly specific) communication from the PC it is connected to before it will "continue from boot loader back to user code".
 
on the AVR you can disable interrupts and do a JMP 0 or the C equivalent.
Or set/enable the watchdog.

Neither will do a hardware reset where all the registers are what they would be after a power up. Only way I know of to do that (other than cycling power) is to wire an I/O bit to the reset pin and assert it when needed. I can't recall seeing that used - normally it's one of the two, above.
 
Answering my own question,

I was able to perform a simulation of physical disconnect of the usb using the code below:

Serial.begin(9600);
Serial.end();

Thanks all for the info and help.

Cheers,
 
Status
Not open for further replies.
Back
Top