Minor documentation improvements.
[pub/USBasp.git] / Bootloaders / HID / BootloaderHID.c
index 04fd0df..fa1dd58 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2016.
+     Copyright (C) Dean Camera, 2017.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2016  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2017  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
@@ -58,6 +58,11 @@ void Application_Jump_Check(void)
        /* 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))
        {
        /* 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))
        {
+               /* Turn off the watchdog */
+               MCUSR &= ~(1 << WDRF);
+               wdt_disable();
+
+               /* Clear the boot key and jump to the user application */
                MagicBootKey = 0;
 
                // cppcheck-suppress constStatement
                MagicBootKey = 0;
 
                // cppcheck-suppress constStatement
@@ -98,6 +103,9 @@ static void SetupHardware(void)
        MCUSR &= ~(1 << WDRF);
        wdt_disable();
 
        MCUSR &= ~(1 << WDRF);
        wdt_disable();
 
+       /* Disable clock division */
+       clock_prescale_set(clock_div_1);
+
        /* Relocate the interrupt vector table to the bootloader section */
        MCUCR = (1 << IVCE);
        MCUCR = (1 << IVSEL);
        /* Relocate the interrupt vector table to the bootloader section */
        MCUCR = (1 << IVCE);
        MCUCR = (1 << IVSEL);
@@ -153,7 +161,7 @@ void EVENT_USB_Device_ControlRequest(void)
                        {
                                RunBootloader = false;
                        }
                        {
                                RunBootloader = false;
                        }
-                       else
+                       else if (PageAddress < BOOT_START_ADDR)
                        {
                                /* Erase the given FLASH page, ready to be programmed */
                                boot_page_erase(PageAddress);
                        {
                                /* Erase the given FLASH page, ready to be programmed */
                                boot_page_erase(PageAddress);