/* Re-enable JTAG debugging */
JTAG_ENABLE();
- /* Check if the device's BOOTRST fuse is set */
- if (boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS) & FUSE_BOOTRST)
- {
- /* If the reset source was not an external reset or the key is correct, clear it and jump to the application */
- if (!(MCUSR & (1 << EXTRF)) || (MagicBootKey == MAGIC_BOOT_KEY))
- JumpToApplication = true;
-
- /* Clear reset source */
- MCUSR &= ~(1 << EXTRF);
- }
- else
+ #else
+ {
+ /* If the reset source was the bootloader and the key is correct, clear it and jump to the application;
+ * this can happen in the HWBE fuse is set, and the HBE pin is low during the watchdog reset */
+ if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY))
+ JumpToApplication = true;
+
+ /* Clear reset source */
+ MCUSR &= ~(1 << WDRF);
+ }
#endif
- /* If the reset source was the bootloader and the key is correct, clear it and jump to the application */
- if ((MCUSR & (1 << WDRF)) && (MagicBootKey == MAGIC_BOOT_KEY))
- JumpToApplication |= true;
+ /* Don't run the user application if the reset vector is blank (no app loaded) */
+ bool ApplicationValid = (pgm_read_word_near(0) != 0xFFFF);
/* If a request has been made to jump to the user application, honor it */
- if (JumpToApplication)
+ if (JumpToApplication && ApplicationValid)
{
/* Turn off the watchdog */
- MCUSR &= ~(1<<WDRF);
- wdt_disable();
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
/* Clear the boot key and jump to the user application */
MagicBootKey = 0;
{
/* Shut down the USB and other board hardware drivers */
USB_Disable();
- LEDs_Disable();
+ //LEDs_Disable();
+ DDRB = 0;
+ PORTB = 0;
+ DDRD = 0;
+ PORTD = 0;
-
+
/* Disable Bootloader active LED toggle timer */
TIMSK1 = 0;
TCCR1B = 0;
#include "Config/AppConfig.h"
#include <LUFA/Drivers/USB/USB.h>
- #include <LUFA/Drivers/Board/LEDs.h>
+ //#include <LUFA/Drivers/Board/LEDs.h>
+ #include <LUFA/Platform/Platform.h>
+
+ /* Preprocessor Checks: */
+ #if !defined(__OPTIMIZE_SIZE__)
+ #error This bootloader requires that it be optimized for size, not speed, to fit into the target device. Change optimization settings and try again.
+ #endif
/* Macros: */
/** Major bootloader version number. */
<toolchain-config name="avrgcc.compiler.optimization.OtherFlags" value="-fdata-sections" toolchain="avrgcc"/>\r
<toolchain-config name="avrgcc.compiler.optimization.PrepareFunctionsForGarbageCollection" value="True" toolchain="avrgcc"/>\r
<toolchain-config name="avrgcc.compiler.warnings.AllWarnings" value="True" toolchain="avrgcc"/>\r
- <toolchain-config name="avrgcc.compiler.miscellaneous.OtherFlags" value="-std=gnu99 -fno-strict-aliasing" toolchain="avrgcc"/>\r
+ <toolchain-config name="avrgcc.compiler.miscellaneous.OtherFlags" value="-mrelax -std=gnu99 -fno-strict-aliasing -fno-jump-tables" toolchain="avrgcc"/>\r
<toolchain-config name="avrgcc.linker.optimization.GarbageCollectUnusedSections" value="True" toolchain="avrgcc"/>\r
<toolchain-config name="avrgcc.linker.optimization.RelaxBranches" value="True" toolchain="avrgcc"/>\r
- <toolchain-config name="avrgcc.linker.miscellaneous.LinkerFlags" value="-Wl,--relax" toolchain="avrgcc"/>\r
</module>\r
</select-by-device>\r
\r