From 014466a7880e1424aaeedd66c269ea1197624535 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Sat, 21 Jan 2012 16:51:55 -0500 Subject: move interrupt vector table to application section before jumping to it after upload finished. --- bootloaders/caterina_LUFA/Caterina.c | 28 ++- bootloaders/caterina_LUFA/Caterina.hex | 443 ++++++++++++++++----------------- 2 files changed, 240 insertions(+), 231 deletions(-) diff --git a/bootloaders/caterina_LUFA/Caterina.c b/bootloaders/caterina_LUFA/Caterina.c index 8bd7403..9e1dbbc 100755 --- a/bootloaders/caterina_LUFA/Caterina.c +++ b/bootloaders/caterina_LUFA/Caterina.c @@ -58,6 +58,16 @@ static bool RunBootloader = true; void StartSketch() { + /* Relocate the interrupt vector table to the application section */ +// MCUCR = (1 << IVCE); // these two lines are for moving interrupts to bootloader, not application +// MCUCR = (1 << IVSEL); + __asm__ volatile ( + "ldi r16, 0x01\n" + "out 0x35, r16\n" + "ldi r16, 0x00\n" + "out 0x35, r16\n" + ::); + UDCON = 1; // Detach USB UDIEN = 0; __asm__ volatile ( // Reset vector to run firmware @@ -73,12 +83,12 @@ void StartSketch() */ int main(void) { - uint8_t MCUSR_state = MCUSR; // store the reason for the reset - MCUSR &= ~(1 << WDRF); // must clear the watchdog reset flag before disabling and reenabling WDT - wdt_disable(); - if (MCUSR_state & (1<