Skip to content

Commit

Permalink
Never initialize peripheries when going to application. If peripherie…
Browse files Browse the repository at this point in the history
…s were initialized, use watchdog reset before going to application.

Remove duplicate call of wdt_disable() in SetupHardware() and remove unnecessary peripheries disabling in StartSketch();
  • Loading branch information
mkbel committed Jul 3, 2018
1 parent 321ae6e commit 3b0a60a
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions Caterina.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,10 @@ void StartSketch(void)
{
cli();

/* Undo TIMER1 setup and clear the count before running the sketch */
TIMSK1 = 0;
TCCR1B = 0;
TCNT1H = 0; // 16-bit write to TCNT1 requires high byte be written first
TCNT1L = 0;

/* Relocate the interrupt vector table to the application section */
MCUCR = (1 << IVCE);
MCUCR = 0;

L_LED_OFF();

/* jump to beginning of application space */
__asm__ volatile("jmp 0x0000");
}
Expand Down Expand Up @@ -184,16 +176,17 @@ int main(void)
/* Disconnect from the host - USB interface will be reset later along with the AVR */
USB_Detach();

/* Jump to beginning of application space to run the sketch - do not reset */
StartSketch();
/* Watchdog reset to start the application. */

wdt_enable(WDTO_120MS);
while(1);
}

/** Configures all hardware required for the bootloader. */
void SetupHardware(void)
{
/* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF);
wdt_disable();

/* Disable clock division */
clock_prescale_set(clock_div_1);
Expand Down

0 comments on commit 3b0a60a

Please sign in to comment.