diff options
author | Zach Eveland <zeveland@blacklabel-development.com> | 2012-01-21 16:51:55 -0500 |
---|---|---|
committer | Zach Eveland <zeveland@blacklabel-development.com> | 2012-01-21 16:51:55 -0500 |
commit | 014466a7880e1424aaeedd66c269ea1197624535 (patch) | |
tree | 17dbc5eeda758870bdcbb8f94913294309fdd805 /bootloaders/caterina_LUFA/Caterina.c | |
parent | 0d8f865d9b783a74ea8238bb77a7bde239617d5e (diff) |
move interrupt vector table to application section before jumping to it after upload finished.
Diffstat (limited to 'bootloaders/caterina_LUFA/Caterina.c')
-rwxr-xr-x | bootloaders/caterina_LUFA/Caterina.c | 28 |
1 files changed, 20 insertions, 8 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<<WDRF) && (pgm_read_word(0) != 0xFFFF)) {
- StartSketch(); // if the reset was caused by WDT and if a sketch is already present then run the sketch instead of the bootloader
- }
+// 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<<WDRF) && (pgm_read_word(0) != 0xFFFF)) {
+// StartSketch(); // if the reset was caused by WDT and if a sketch is already present then run the sketch instead of the bootloader
+// }
/* Setup hardware required for the bootloader */
SetupHardware();
@@ -101,9 +111,11 @@ int main(void) USB_Detach();
/* Enable the watchdog and force a timeout to reset the AVR */
- wdt_enable(WDTO_250MS);
+// wdt_enable(WDTO_250MS);
- for (;;);
+// for (;;);
+
+ StartSketch();
}
/** Configures all hardware required for the bootloader. */
|