diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2012-05-10 19:24:58 +0000 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2012-05-10 19:24:58 +0000 |
commit | 359fbfe14d00ab378f85a36664820ea9ba538c3f (patch) | |
tree | 0929d5663a3be4dc078dda0aba5ba798ebb627ab /Bootloaders/HID | |
parent | e8570c4a37e41117e3fd1e989e0b41f1e9608f3c (diff) | |
download | lufa-359fbfe14d00ab378f85a36664820ea9ba538c3f.tar.gz lufa-359fbfe14d00ab378f85a36664820ea9ba538c3f.tar.bz2 lufa-359fbfe14d00ab378f85a36664820ea9ba538c3f.zip |
Add branch for the conversion of demos to use standard C header files for configuration, rather than makefile defined macros.
Diffstat (limited to 'Bootloaders/HID')
-rw-r--r-- | Bootloaders/HID/BootloaderHID.c | 30 | ||||
-rw-r--r-- | Bootloaders/HID/BootloaderHID.h | 5 | ||||
-rw-r--r-- | Bootloaders/HID/BootloaderHID.txt | 8 | ||||
-rw-r--r-- | Bootloaders/HID/Descriptors.c | 4 | ||||
-rw-r--r-- | Bootloaders/HID/Descriptors.h | 4 | ||||
-rw-r--r-- | Bootloaders/HID/HostLoaderApp/hid_bootloader_cli.c | 4 | ||||
-rw-r--r-- | Bootloaders/HID/makefile | 2 |
7 files changed, 41 insertions, 16 deletions
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 |