aboutsummaryrefslogtreecommitdiffstats
path: root/Bootloaders
diff options
context:
space:
mode:
Diffstat (limited to 'Bootloaders')
-rw-r--r--Bootloaders/CDC/BootloaderCDC.c48
-rw-r--r--Bootloaders/CDC/BootloaderCDC.h5
-rw-r--r--Bootloaders/CDC/BootloaderCDC.txt6
-rw-r--r--Bootloaders/CDC/Config/AppConfig.h50
-rw-r--r--Bootloaders/CDC/Config/LUFAConfig.h93
-rw-r--r--Bootloaders/CDC/Descriptors.c10
-rw-r--r--Bootloaders/CDC/Descriptors.h12
-rw-r--r--Bootloaders/CDC/makefile21
-rw-r--r--Bootloaders/DFU/BootloaderDFU.c24
-rw-r--r--Bootloaders/DFU/BootloaderDFU.h5
-rw-r--r--Bootloaders/DFU/BootloaderDFU.txt6
-rw-r--r--Bootloaders/DFU/Descriptors.c2
-rw-r--r--Bootloaders/DFU/makefile2
-rw-r--r--Bootloaders/HID/BootloaderHID.c30
-rw-r--r--Bootloaders/HID/BootloaderHID.h5
-rw-r--r--Bootloaders/HID/BootloaderHID.txt8
-rw-r--r--Bootloaders/HID/Descriptors.c4
-rw-r--r--Bootloaders/HID/Descriptors.h4
-rw-r--r--Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c4
-rw-r--r--Bootloaders/HID/makefile2
20 files changed, 274 insertions, 67 deletions
diff --git a/Bootloaders/CDC/BootloaderCDC.c b/Bootloaders/CDC/BootloaderCDC.c
index e9ea8ae35..211b054e3 100644
--- a/Bootloaders/CDC/BootloaderCDC.c
+++ b/Bootloaders/CDC/BootloaderCDC.c
@@ -56,6 +56,28 @@ static uint32_t CurrAddress;
*/
static bool RunBootloader = true;
+/** Magic lock for forced application start. If the HWBE fuse is programmed and BOOTRST is unprogrammed, the bootloader
+ * will start if the /HWB line of the AVR is held low and the system is reset. However, if the /HWB line is still held
+ * low when the application attempts to start via a watchdog reset, the bootloader will re-start. If set to the value
+ * \ref MAGIC_BOOT_KEY the special init function \ref Application_Jump_Check() will force the application to start.
+ */
+uint32_t MagicBootKey ATTR_NO_INIT;
+
+
+/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application
+ * start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid,
+ * this will force the user application to start via a software jump.
+ */
+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))
+ {
+ MagicBootKey = 0;
+ // cppcheck-suppress constStatement
+ ((void (*)(void))0x0000)();
+ }
+}
/** 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
@@ -80,6 +102,9 @@ int main(void)
/* Disconnect from the host - USB interface will be reset later along with the AVR */
USB_Detach();
+
+ /* Unlock the forced application start mode of the bootloader if it is restarted */
+ MagicBootKey = MAGIC_BOOT_KEY;
/* Enable the watchdog and force a timeout to reset the AVR */
wdt_enable(WDTO_250MS);
@@ -122,17 +147,12 @@ ISR(TIMER1_OVF_vect, ISR_BLOCK)
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Setup CDC Notification, Rx and Tx Endpoints */
- Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,
- ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,
- ENDPOINT_BANK_SINGLE);
+ Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT,
+ CDC_NOTIFICATION_EPSIZE, 1);
- Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK,
- ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,
- ENDPOINT_BANK_SINGLE);
+ Endpoint_ConfigureEndpoint(CDC_TX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
- Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK,
- ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,
- ENDPOINT_BANK_SINGLE);
+ Endpoint_ConfigureEndpoint(CDC_RX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
}
/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to
@@ -303,7 +323,7 @@ static void ReadWriteMemoryBlock(const uint8_t Command)
static uint8_t FetchNextCommandByte(void)
{
/* Select the OUT endpoint so that the next data byte can be read */
- Endpoint_SelectEndpoint(CDC_RX_EPNUM);
+ Endpoint_SelectEndpoint(CDC_RX_EPADDR);
/* If OUT endpoint empty, clear it and wait for the next packet from the host */
while (!(Endpoint_IsReadWriteAllowed()))
@@ -329,7 +349,7 @@ static uint8_t FetchNextCommandByte(void)
static void WriteNextResponseByte(const uint8_t Response)
{
/* Select the IN endpoint so that the next data byte can be written */
- Endpoint_SelectEndpoint(CDC_TX_EPNUM);
+ Endpoint_SelectEndpoint(CDC_TX_EPADDR);
/* If IN endpoint full, clear it and wait until ready for the next packet to the host */
if (!(Endpoint_IsReadWriteAllowed()))
@@ -353,7 +373,7 @@ static void WriteNextResponseByte(const uint8_t Response)
static void CDC_Task(void)
{
/* Select the OUT endpoint */
- Endpoint_SelectEndpoint(CDC_RX_EPNUM);
+ Endpoint_SelectEndpoint(CDC_RX_EPADDR);
/* Check if endpoint has a command in it sent from the host */
if (!(Endpoint_IsOUTReceived()))
@@ -549,7 +569,7 @@ static void CDC_Task(void)
}
/* Select the IN endpoint */
- Endpoint_SelectEndpoint(CDC_TX_EPNUM);
+ Endpoint_SelectEndpoint(CDC_TX_EPADDR);
/* Remember if the endpoint is completely full before clearing it */
bool IsEndpointFull = !(Endpoint_IsReadWriteAllowed());
@@ -577,7 +597,7 @@ static void CDC_Task(void)
}
/* Select the OUT endpoint */
- Endpoint_SelectEndpoint(CDC_RX_EPNUM);
+ Endpoint_SelectEndpoint(CDC_RX_EPADDR);
/* Acknowledge the command from the host */
Endpoint_ClearOUT();
diff --git a/Bootloaders/CDC/BootloaderCDC.h b/Bootloaders/CDC/BootloaderCDC.h
index 4b9e7d6d8..257e884e6 100644
--- a/Bootloaders/CDC/BootloaderCDC.h
+++ b/Bootloaders/CDC/BootloaderCDC.h
@@ -67,6 +67,9 @@
/** Eight character bootloader firmware identifier reported to the host when requested */
#define SOFTWARE_IDENTIFIER "LUFACDC"
+ /** Magic bootloader key to unlock forced application start mode. */
+ #define MAGIC_BOOT_KEY 0xDC42CACA
+
/* Type Defines: */
/** Type define for a non-returning pointer to the start of the loaded application in flash memory. */
typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;
@@ -75,6 +78,8 @@
static void CDC_Task(void);
static void SetupHardware(void);
+ void Application_Jump_Check(void) ATTR_INIT_SECTION(3);
+
void EVENT_USB_Device_ConfigurationChanged(void);
#if defined(INCLUDE_FROM_BOOTLOADERCDC_C) || defined(__DOXYGEN__)
diff --git a/Bootloaders/CDC/BootloaderCDC.txt b/Bootloaders/CDC/BootloaderCDC.txt
index d6ab94516..618b95d25 100644
--- a/Bootloaders/CDC/BootloaderCDC.txt
+++ b/Bootloaders/CDC/BootloaderCDC.txt
@@ -47,9 +47,9 @@
* This bootloader enumerates to the host as a CDC Class device (virtual serial port), allowing for AVR109
* protocol compatible programming software to load firmware onto the AVR.
*
- * Out of the box this bootloader builds for the USB1287, and will fit into 4KB of bootloader space. If
- * you wish to enlarge this space and/or change the AVR model, you will need to edit the BOOT_START and MCU
- * values in the accompanying makefile.
+ * Out of the box this bootloader builds for the AT90USB1287 with an 8KB bootloader section size, and will fit
+ * into 4KB of bootloader space. If you wish to alter this size and/or change the AVR model, you will need to
+ * edit the MCU, FLASH_SIZE_KB and BOOT_SECTION_SIZE_KB values in the accompanying makefile.
*
* When the bootloader is running, the board's LED(s) will flash at regular intervals to distinguish the
* bootloader from the normal user application.
diff --git a/Bootloaders/CDC/Config/AppConfig.h b/Bootloaders/CDC/Config/AppConfig.h
new file mode 100644
index 000000000..ae3e50e1d
--- /dev/null
+++ b/Bootloaders/CDC/Config/AppConfig.h
@@ -0,0 +1,50 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief LUFA Library Configuration Header File
+ *
+ * This is a header file which is be used to configure LUFA's
+ * compile time options, as an alternative to the compile time
+ * constants supplied through a makefile.
+ *
+ * For information on what each token does, refer to the LUFA
+ * manual section "Summary of Compile Tokens".
+ */
+
+#ifndef _APP_CONFIG_H_
+#define _APP_CONFIG_H_
+
+ #define NO_BLOCK_SUPPORT
+ #define NO_EEPROM_BYTE_SUPPORT
+ #define NO_FLASH_BYTE_SUPPORT
+ #define NO_LOCK_BYTE_WRITE_SUPPORT
+
+#endif \ No newline at end of file
diff --git a/Bootloaders/CDC/Config/LUFAConfig.h b/Bootloaders/CDC/Config/LUFAConfig.h
new file mode 100644
index 000000000..c5a01c2fa
--- /dev/null
+++ b/Bootloaders/CDC/Config/LUFAConfig.h
@@ -0,0 +1,93 @@
+/*
+ LUFA Library
+ Copyright (C) Dean Camera, 2012.
+
+ dean [at] fourwalledcubicle [dot] com
+ www.lufa-lib.org
+*/
+
+/*
+ Copyright 2012 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
+ without fee, provided that the above copyright notice appear in
+ all copies and that both that the copyright notice and this
+ permission notice and warranty disclaimer appear in supporting
+ documentation, and that the name of the author not be used in
+ advertising or publicity pertaining to distribution of the
+ software without specific, written prior permission.
+
+ The author disclaim all warranties with regard to this
+ software, including all implied warranties of merchantability
+ and fitness. In no event shall the author be liable for any
+ special, indirect or consequential damages or any damages
+ whatsoever resulting from loss of use, data or profits, whether
+ in an action of contract, negligence or other tortious action,
+ arising out of or in connection with the use or performance of
+ this software.
+*/
+
+/** \file
+ * \brief LUFA Library Configuration Header File
+ *
+ * This is a header file which is be used to configure LUFA's
+ * compile time options, as an alternative to the compile time
+ * constants supplied through a makefile.
+ *
+ * For information on what each token does, refer to the LUFA
+ * manual section "Summary of Compile Tokens".
+ */
+
+#ifndef _LUFA_CONFIG_H_
+#define _LUFA_CONFIG_H_
+
+ #if (ARCH == ARCH_AVR8)
+
+ /* Non-USB Related Configuration Tokens: */
+// #define DISABLE_TERMINAL_CODES
+
+ /* USB Class Driver Related Tokens: */
+// #define HID_HOST_BOOT_PROTOCOL_ONLY
+// #define HID_STATETABLE_STACK_DEPTH {Insert Value Here}
+// #define HID_USAGE_STACK_DEPTH {Insert Value Here}
+// #define HID_MAX_COLLECTIONS {Insert Value Here}
+// #define HID_MAX_REPORTITEMS {Insert Value Here}
+// #define HID_MAX_REPORT_IDS {Insert Value Here}
+// #define NO_CLASS_DRIVER_AUTOFLUSH
+
+ /* General USB Driver Related Tokens: */
+ #define ORDERED_EP_CONFIG
+ #define USE_STATIC_OPTIONS (USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)
+ #define USB_DEVICE_ONLY
+// #define USB_HOST_ONLY
+// #define USB_STREAM_TIMEOUT_MS {Insert Value Here}
+// #define NO_LIMITED_CONTROLLER_CONNECT
+ #define NO_SOF_EVENTS
+
+ /* USB Device Mode Driver Related Tokens: */
+ #define USE_RAM_DESCRIPTORS
+// #define USE_FLASH_DESCRIPTORS
+// #define USE_EEPROM_DESCRIPTORS
+ #define NO_INTERNAL_SERIAL
+ #define FIXED_CONTROL_ENDPOINT_SIZE 8
+ #define DEVICE_STATE_AS_GPIOR 0
+ #define FIXED_NUM_CONFIGURATIONS 1
+// #define CONTROL_ONLY_DEVICE
+// #define INTERRUPT_CONTROL_ENDPOINT
+ #define NO_DEVICE_REMOTE_WAKEUP
+ #define NO_DEVICE_SELF_POWER
+
+ /* USB Host Mode Driver Related Tokens: */
+// #define HOST_STATE_AS_GPIOR {Insert Value Here}
+// #define USB_HOST_TIMEOUT_MS {Insert Value Here}
+// #define HOST_DEVICE_SETTLE_DELAY_MS {Insert Value Here}
+// #define NO_AUTO_VBUS_MANAGEMENT
+// #define INVERTED_VBUS_ENABLE_LINE
+
+ #else
+
+ #error Unsupported architecture for this LUFA configuration file.
+
+ #endif
+#endif
diff --git a/Bootloaders/CDC/Descriptors.c b/Bootloaders/CDC/Descriptors.c
index 4bf3eced5..9c892f835 100644
--- a/Bootloaders/CDC/Descriptors.c
+++ b/Bootloaders/CDC/Descriptors.c
@@ -131,7 +131,7 @@ const USB_Descriptor_Configuration_t ConfigurationDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM),
+ .EndpointAddress = CDC_NOTIFICATION_EPADDR,
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_NOTIFICATION_EPSIZE,
.PollingIntervalMS = 0xFF
@@ -157,20 +157,20 @@ const USB_Descriptor_Configuration_t ConfigurationDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_OUT | CDC_RX_EPNUM),
+ .EndpointAddress = CDC_RX_EPADDR,
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_TXRX_EPSIZE,
- .PollingIntervalMS = 0x01
+ .PollingIntervalMS = 0x05
},
.CDC_DataInEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_IN | CDC_TX_EPNUM),
+ .EndpointAddress = CDC_TX_EPADDR,
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_TXRX_EPSIZE,
- .PollingIntervalMS = 0x01
+ .PollingIntervalMS = 0x05
}
};
diff --git a/Bootloaders/CDC/Descriptors.h b/Bootloaders/CDC/Descriptors.h
index e5ef64102..0010fc69b 100644
--- a/Bootloaders/CDC/Descriptors.h
+++ b/Bootloaders/CDC/Descriptors.h
@@ -92,14 +92,14 @@
#error The selected AVR part is not currently supported by this bootloader.
#endif
- /** Endpoint number for the CDC control interface event notification endpoint. */
- #define CDC_NOTIFICATION_EPNUM 2
+ /** Endpoint address for the CDC control interface event notification endpoint. */
+ #define CDC_NOTIFICATION_EPADDR (ENDPOINT_DIR_IN | 2)
- /** Endpoint number for the CDC data interface TX (data IN) endpoint. */
- #define CDC_TX_EPNUM 3
+ /** Endpoint address for the CDC data interface TX (data IN) endpoint. */
+ #define CDC_TX_EPADDR (ENDPOINT_DIR_IN | 3)
- /** Endpoint number for the CDC data interface RX (data OUT) endpoint. */
- #define CDC_RX_EPNUM 4
+ /** Endpoint address for the CDC data interface RX (data OUT) endpoint. */
+ #define CDC_RX_EPADDR (ENDPOINT_DIR_OUT | 4)
/** Size of the CDC data interface TX and RX data endpoint banks, in bytes. */
#define CDC_TXRX_EPSIZE 16
diff --git a/Bootloaders/CDC/makefile b/Bootloaders/CDC/makefile
index 066fb8884..b449ff0c6 100644
--- a/Bootloaders/CDC/makefile
+++ b/Bootloaders/CDC/makefile
@@ -95,7 +95,7 @@ F_USB = $(F_CPU)
# Note that the bootloader size and start address given in AVRStudio is in words and not
# bytes, and so will need to be doubled to obtain the byte address needed by AVR-GCC.
FLASH_SIZE_KB = 128
-BOOT_SECTION_SIZE_KB = 4
+BOOT_SECTION_SIZE_KB = 8
# Formulas used to calculate the starting address of the Bootloader section, and the User Application
@@ -124,22 +124,7 @@ LUFA_PATH = ../..
# LUFA library compile-time options and predefined tokens
-LUFA_OPTS = -D USB_DEVICE_ONLY
-LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
-LUFA_OPTS += -D ORDERED_EP_CONFIG
-LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
-LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
-LUFA_OPTS += -D USE_RAM_DESCRIPTORS
-LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
-LUFA_OPTS += -D NO_INTERNAL_SERIAL
-LUFA_OPTS += -D NO_DEVICE_SELF_POWER
-LUFA_OPTS += -D NO_DEVICE_REMOTE_WAKEUP
-LUFA_OPTS += -D NO_SOF_EVENTS
-
-#LUFA_OPTS += -D NO_BLOCK_SUPPORT
-#LUFA_OPTS += -D NO_EEPROM_BYTE_SUPPORT
-#LUFA_OPTS += -D NO_FLASH_BYTE_SUPPORT
-#LUFA_OPTS += -D NO_LOCK_BYTE_WRITE_SUPPORT
+LUFA_OPTS = -D USE_LUFA_CONFIG_HEADER
# Create the LUFA source path variables by including the LUFA root makefile
@@ -184,7 +169,7 @@ DEBUG = dwarf-2
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
-EXTRAINCDIRS = $(LUFA_PATH)/
+EXTRAINCDIRS = $(LUFA_PATH)/ Config/
# Compiler flag to set the C Standard level.
diff --git a/Bootloaders/DFU/BootloaderDFU.c b/Bootloaders/DFU/BootloaderDFU.c
index 3ce2a6285..233e145ae 100644
--- a/Bootloaders/DFU/BootloaderDFU.c
+++ b/Bootloaders/DFU/BootloaderDFU.c
@@ -92,6 +92,27 @@ static uint16_t StartAddr = 0x0000;
*/
static uint16_t EndAddr = 0x0000;
+/** Magic lock for forced application start. If the HWBE fuse is programmed and BOOTRST is unprogrammed, the bootloader
+ * will start if the /HWB line of the AVR is held low and the system is reset. However, if the /HWB line is still held
+ * low when the application attempts to start via a watchdog reset, the bootloader will re-start. If set to the value
+ * \ref MAGIC_BOOT_KEY the special init function \ref Application_Jump_Check() will force the application to start.
+ */
+uint32_t MagicBootKey ATTR_NO_INIT;
+
+
+/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application
+ * start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid,
+ * this will force the user application to start via a software jump.
+ */
+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))
+ {
+ MagicBootKey = 0;
+ AppStartPtr();
+ }
+}
/** 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
@@ -695,6 +716,9 @@ static void ProcessWriteCommand(void)
{
if (SentCommand.Data[1] == 0x00) // Start via watchdog
{
+ /* Unlock the forced application start mode of the bootloader if it is restarted */
+ MagicBootKey = MAGIC_BOOT_KEY;
+
/* Start the watchdog to reset the AVR once the communications are finalized */
wdt_enable(WDTO_250MS);
}
diff --git a/Bootloaders/DFU/BootloaderDFU.h b/Bootloaders/DFU/BootloaderDFU.h
index a80775348..46b70c0e9 100644
--- a/Bootloaders/DFU/BootloaderDFU.h
+++ b/Bootloaders/DFU/BootloaderDFU.h
@@ -66,6 +66,9 @@
/** Minor bootloader version number. */
#define BOOTLOADER_VERSION_REV 0
+
+ /** Magic bootloader key to unlock forced application start mode. */
+ #define MAGIC_BOOT_KEY 0xDC42CACA
/** Complete bootloader version number expressed as a packed byte, constructed from the
* two individual bootloader version macros.
@@ -206,6 +209,8 @@
static void ProcessWriteCommand(void);
static void ProcessReadCommand(void);
#endif
+
+ void Application_Jump_Check(void) ATTR_INIT_SECTION(3);
#endif
diff --git a/Bootloaders/DFU/BootloaderDFU.txt b/Bootloaders/DFU/BootloaderDFU.txt
index d0811b2aa..2c9eaf1de 100644
--- a/Bootloaders/DFU/BootloaderDFU.txt
+++ b/Bootloaders/DFU/BootloaderDFU.txt
@@ -47,9 +47,9 @@
* This bootloader enumerates to the host as a DFU Class device, allowing for DFU-compatible programming
* software to load firmware onto the AVR.
*
- * Out of the box this bootloader builds for the USB1287, and should fit into 4KB of bootloader space. If
- * you wish to enlarge this space and/or change the AVR model, you will need to edit the BOOT_START and MCU
- * values in the accompanying makefile.
+ * Out of the box this bootloader builds for the AT90USB1287 with an 8KB bootloader section size, and will fit
+ * into 4KB of bootloader space. If you wish to alter this size and/or change the AVR model, you will need to
+ * edit the MCU, FLASH_SIZE_KB and BOOT_SECTION_SIZE_KB values in the accompanying makefile.
*
* When the bootloader is running, the board's LED(s) will flash at regular intervals to distinguish the
* bootloader from the normal user application.
diff --git a/Bootloaders/DFU/Descriptors.c b/Bootloaders/DFU/Descriptors.c
index d55159060..ff33b6b64 100644
--- a/Bootloaders/DFU/Descriptors.c
+++ b/Bootloaders/DFU/Descriptors.c
@@ -111,7 +111,7 @@ const USB_Descriptor_Configuration_t ConfigurationDescriptor =
.DetachTimeout = 0x0000,
.TransferSize = 0x0C00,
- .DFUSpecification = VERSION_BCD(01.01)
+ .DFUSpecification = VERSION_BCD(01.10)
}
};
diff --git a/Bootloaders/DFU/makefile b/Bootloaders/DFU/makefile
index 608564ebe..f78ceb270 100644
--- a/Bootloaders/DFU/makefile
+++ b/Bootloaders/DFU/makefile
@@ -95,7 +95,7 @@ F_USB = $(F_CPU)
# Note that the bootloader size and start address given in AVRStudio is in words and not
# bytes, and so will need to be doubled to obtain the byte address needed by AVR-GCC.
FLASH_SIZE_KB = 128
-BOOT_SECTION_SIZE_KB = 4
+BOOT_SECTION_SIZE_KB = 8
# Formulas used to calculate the starting address of the Bootloader section, and the User Application
diff --git a/Bootloaders/HID/BootloaderHID.c b/Bootloaders/HID/BootloaderHID.c
index 928000f8b..acc351a30 100644
--- a/Bootloaders/HID/BootloaderHID.c
+++ b/Bootloaders/HID/BootloaderHID.c
@@ -41,6 +41,29 @@
*/
static bool RunBootloader = true;
+/** Magic lock for forced application start. If the HWBE fuse is programmed and BOOTRST is unprogrammed, the bootloader
+ * will start if the /HWB line of the AVR is held low and the system is reset. However, if the /HWB line is still held
+ * low when the application attempts to start via a watchdog reset, the bootloader will re-start. If set to the value
+ * \ref MAGIC_BOOT_KEY the special init function \ref Application_Jump_Check() will force the application to start.
+ */
+uint32_t MagicBootKey ATTR_NO_INIT;
+
+
+/** Special startup routine to check if the bootloader was started via a watchdog reset, and if the magic application
+ * start key has been loaded into \ref MagicBootKey. If the bootloader started via the watchdog and the key is valid,
+ * this will force the user application to start via a software jump.
+ */
+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))
+ {
+ MagicBootKey = 0;
+ // cppcheck-suppress constStatement
+ ((void (*)(void))0x0000)();
+ }
+}
+
/** 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.
*/
@@ -58,6 +81,9 @@ int main(void)
/* Disconnect from the host - USB interface will be reset later along with the AVR */
USB_Detach();
+ /* Unlock the forced application start mode of the bootloader if it is restarted */
+ MagicBootKey = MAGIC_BOOT_KEY;
+
/* Enable the watchdog and force a timeout to reset the AVR */
wdt_enable(WDTO_250MS);
@@ -85,9 +111,7 @@ static void SetupHardware(void)
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Setup HID Report Endpoint */
- Endpoint_ConfigureEndpoint(HID_IN_EPNUM, EP_TYPE_INTERRUPT,
- ENDPOINT_DIR_IN, HID_IN_EPSIZE,
- ENDPOINT_BANK_SINGLE);
+ Endpoint_ConfigureEndpoint(HID_IN_EPADDR, EP_TYPE_INTERRUPT, HID_IN_EPSIZE, 1);
}
/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to
diff --git a/Bootloaders/HID/BootloaderHID.h b/Bootloaders/HID/BootloaderHID.h
index ab5752d3c..af2812a7d 100644
--- a/Bootloaders/HID/BootloaderHID.h
+++ b/Bootloaders/HID/BootloaderHID.h
@@ -52,9 +52,14 @@
/** Bootloader special address to start the user application */
#define COMMAND_STARTAPPLICATION 0xFFFF
+ /** Magic bootloader key to unlock forced application start mode. */
+ #define MAGIC_BOOT_KEY 0xDC42CACA
+
/* Function Prototypes: */
static void SetupHardware(void);
+ void Application_Jump_Check(void) ATTR_INIT_SECTION(3);
+
void EVENT_USB_Device_ConfigurationChanged(void);
void EVENT_USB_Device_UnhandledControlRequest(void);
diff --git a/Bootloaders/HID/BootloaderHID.txt b/Bootloaders/HID/BootloaderHID.txt
index a774ab485..f6c084d65 100644
--- a/Bootloaders/HID/BootloaderHID.txt
+++ b/Bootloaders/HID/BootloaderHID.txt
@@ -51,10 +51,10 @@
* from PJRC (used with permission). This bootloader is deliberatley non-compatible with the properietary PJRC
* HalfKay bootloader GUI; only the command line interface software accompanying this bootloader will work with it.
*
- * Out of the box this bootloader builds for the USB1287, and will fit into 2KB of bootloader space for the
- * Series 2 USB AVRs (ATMEGAxxU2, AT90USBxx2) or 4KB of bootloader space for all other models. If you wish to
- * enlarge this space and/or change the AVR model, you will need to edit the BOOT_START and MCU values in the
- * accompanying makefile.
+ * Out of the box this bootloader builds for the AT90USB1287 with an 8KB bootloader section size, and will fit
+ * into 2KB of bootloader space for the Series 2 USB AVRs (ATMEGAxxU2, AT90USBxx2) or 4KB of bootloader space for
+ * all other models. If you wish to alter this size and/or change the AVR model, you will need to edit the MCU,
+ * FLASH_SIZE_KB and BOOT_SECTION_SIZE_KB values in the accompanying makefile.
*
* \section Sec_Installation Driver Installation
*
diff --git a/Bootloaders/HID/Descriptors.c b/Bootloaders/HID/Descriptors.c
index 5d4271e0c..c1ea8e30e 100644
--- a/Bootloaders/HID/Descriptors.c
+++ b/Bootloaders/HID/Descriptors.c
@@ -137,10 +137,10 @@ const USB_Descriptor_Configuration_t ConfigurationDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
- .EndpointAddress = (ENDPOINT_DIR_IN | HID_IN_EPNUM),
+ .EndpointAddress = HID_IN_EPADDR,
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = HID_IN_EPSIZE,
- .PollingIntervalMS = 0x01
+ .PollingIntervalMS = 0x05
},
};
diff --git a/Bootloaders/HID/Descriptors.h b/Bootloaders/HID/Descriptors.h
index 41c4ee402..ad216038a 100644
--- a/Bootloaders/HID/Descriptors.h
+++ b/Bootloaders/HID/Descriptors.h
@@ -55,8 +55,8 @@
} USB_Descriptor_Configuration_t;
/* Macros: */
- /** Endpoint number of the HID data IN endpoint. */
- #define HID_IN_EPNUM 1
+ /** Endpoint address of the HID data IN endpoint. */
+ #define HID_IN_EPADDR (ENDPOINT_DIR_IN | 1)
/** Size in bytes of the HID reporting IN endpoint. */
#define HID_IN_EPSIZE 64
diff --git a/Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c b/Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c
index 6063e1981..c86b0da9c 100644
--- a/Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c
+++ b/Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c
@@ -970,13 +970,9 @@ void parse_options(int argc, char **argv)
} else if (strncmp(arg, "-mmcu=", 6) == 0) {
arg += 6;
- uint8_t valid_prefix = 0;
-
if (strncmp(arg, "at90usb", 7) == 0) {
- valid_prefix = 1;
arg += 7;
} else if (strncmp(arg, "atmega", 6) == 0) {
- valid_prefix = 1;
arg += 6;
} else {
die("Unknown MCU type\n");
diff --git a/Bootloaders/HID/makefile b/Bootloaders/HID/makefile
index efbb6a645..bfefbf695 100644
--- a/Bootloaders/HID/makefile
+++ b/Bootloaders/HID/makefile
@@ -95,7 +95,7 @@ F_USB = $(F_CPU)
# Note that the bootloader size and start address given in AVRStudio is in words and not
# bytes, and so will need to be doubled to obtain the byte address needed by AVR-GCC.
FLASH_SIZE_KB = 128
-BOOT_SECTION_SIZE_KB = 4
+BOOT_SECTION_SIZE_KB = 8
# Formulas used to calculate the starting address of the Bootloader section. These formulas