From 49f7fb00fd7578fe5ecd78d60165fc2570aec1e2 Mon Sep 17 00:00:00 2001 From: Zach Eveland Date: Wed, 11 Apr 2012 23:19:05 -0400 Subject: fixed logic bug in Caterina that could stop the bootloader from entering self-programming mode --- bootloaders/caterina/Caterina.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'bootloaders/caterina/Caterina.c') diff --git a/bootloaders/caterina/Caterina.c b/bootloaders/caterina/Caterina.c index 0cb9590..abcba2b 100755 --- a/bootloaders/caterina/Caterina.c +++ b/bootloaders/caterina/Caterina.c @@ -66,7 +66,7 @@ uint16_t RxLEDPulse = 0; // time remaining for Rx LED pulse uint16_t Timeout = 0; uint16_t bootKey = 0x7777; -volatile uint16_t *const bootKeyPtr = (volatile uint16_t *)0x0A00; +volatile uint16_t *const bootKeyPtr = (volatile uint16_t *)0x0800; void StartSketch(void) { @@ -106,25 +106,29 @@ void LEDPulse(void) } /** Main program entry point. This routine configures the hardware required by the bootloader, then continuously - * runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start - * the loaded application code. + * runs the bootloader processing routine until it times out or is instructed to exit. */ int main(void) { - /* Watchdog may be configured with a 15 ms period so must disable it before doing anything else */ - wdt_disable(); - - /* Check the reason for the reset and act accordingly */ + /* Save the value of the boot key memory before it is overwritten */ + uint16_t bootKeyPtrVal = *bootKeyPtr; + *bootKeyPtr = 0; + + /* Check the reason for the reset so we can act accordingly */ uint8_t mcusr_state = MCUSR; // store the initial state of the Status register MCUSR = 0; // clear all reset flags - // After a power-on reset skip the bootloader and jump straight to sketch - // if one exists. - if (mcusr_state & (1<