Make CDC class bootloader hard-reset the AVR when exited instead of a soft-reset...
authorDean Camera <dean@fourwalledcubicle.com>
Thu, 6 May 2010 07:27:13 +0000 (07:27 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Thu, 6 May 2010 07:27:13 +0000 (07:27 +0000)
Fix the TeensyHID bootloader for the larger USB AVR devices, since Paul uses a different (undocumented) addressing scheme on these devices.

Bootloaders/CDC/BootloaderCDC.c
Bootloaders/CDC/BootloaderCDC.h
Bootloaders/TeensyHID/Descriptors.h
Bootloaders/TeensyHID/TeensyHID.c
Bootloaders/TeensyHID/TeensyHID.txt
Bootloaders/TeensyHID/makefile
LUFA/ManPages/ChangeLog.txt

index 83fd0ee..9f78786 100644 (file)
@@ -54,8 +54,8 @@ CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600,
 uint32_t CurrAddress;\r
 \r
 /** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run\r
- *  via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application\r
- *  jumped to via an indirect jump to location 0x0000.\r
+ *  via a watchdog reset. When cleared the bootloader will exit, starting the watchdog and entering an infinite\r
+ *  loop until the AVR restarts and the application runs.\r
  */\r
 bool RunBootloader = true;\r
 \r
@@ -78,12 +78,13 @@ int main(void)
                USB_USBTask();\r
        }\r
        \r
-       /* Reset all configured hardware to their default states for the user app */\r
-       ResetHardware();\r
+       /* Disconnect from the host - USB interface will be reset later along with the AVR */\r
+       USB_Detach();\r
 \r
-       /* Start the user application */\r
-       AppPtr_t AppStartPtr = (AppPtr_t)0x0000;\r
-       AppStartPtr();  \r
+       /* Enable the watchdog and force a timeout to reset the AVR */\r
+       wdt_enable(WDTO_250MS);\r
+\r
+       for (;;);\r
 }\r
 \r
 /** Configures all hardware required for the bootloader. */\r
@@ -104,20 +105,6 @@ void SetupHardware(void)
        USB_Init();\r
 }\r
 \r
-/** Resets all configured hardware required for the bootloader back to their original states. */\r
-void ResetHardware(void)\r
-{\r
-       /* Shut down the USB subsystem */\r
-       USB_ShutDown();\r
-       \r
-       /* Relocate the interrupt vector table back to the application section */\r
-       MCUCR = (1 << IVCE);\r
-       MCUCR = 0;\r
-\r
-       /* Re-enable RWW section */\r
-       boot_rww_enable();\r
-}\r
-\r
 /** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready\r
  *  to relay data to and from the attached USB host.\r
  */\r
index 22b5743..8142211 100644 (file)
        /* Function Prototypes: */\r
                void CDC_Task(void);\r
                void SetupHardware(void);\r
-               void ResetHardware(void);\r
 \r
                void EVENT_USB_Device_ConfigurationChanged(void);\r
                void EVENT_USB_Device_UnhandledControlRequest(void);\r
index 37a2b64..f72dec2 100644 (file)
@@ -93,7 +93,7 @@
                /** Vendor usage page for the Teensy 2.0 board */\r
                #define TEENSY_USAGEPAGE_20       0x1B\r
                \r
-               /** Vendor usage page for the Teensy++ 1.0 board */\r
+               /** Vendor usage page for the Teensy++ 2.0 board */\r
                #define TEENSY_USAGEPAGE_20PP     0x1C\r
                \r
                #if defined(USB_SERIES_2_AVR)\r
index b93be6d..ff28927 100644 (file)
@@ -105,18 +105,24 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                        /* Wait until the command has been sent by the host */\r
                        while (!(Endpoint_IsOUTReceived()));\r
                \r
-                       /* Read in the write destination address */\r
-                       uint16_t PageAddress = Endpoint_Read_Word_LE();\r
+                       /* Read in the write destination index */\r
+                       uint16_t PageIndex = Endpoint_Read_Word_LE();\r
                        \r
                        /* Check if the command is a program page command, or a start application command */\r
-                       if (PageAddress == TEENSY_STARTAPPLICATION)\r
+                       if (PageIndex == TEENSY_STARTAPPLICATION)\r
                        {\r
                                RunBootloader = false;\r
                        }\r
                        else\r
                        {\r
+                               #if (SPM_PAGESIZE == 128)\r
+                               uint16_t PageByteAddress = PageIndex;\r
+                               #else\r
+                               uint32_t PageByteAddress = ((uint32_t)PageIndex << 8);\r
+                               #endif\r
+                       \r
                                /* Erase the given FLASH page, ready to be programmed */\r
-                               boot_page_erase(PageAddress);\r
+                               boot_page_erase(PageByteAddress);\r
                                boot_spm_busy_wait();\r
                                \r
                                /* Write each of the FLASH page's bytes in sequence */\r
@@ -134,15 +140,12 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                                        }\r
 \r
                                        /* Write the next data word to the FLASH page */\r
-                                       boot_page_fill(PageAddress + PageByte, Endpoint_Read_Word_LE());\r
+                                       boot_page_fill(PageByteAddress + PageByte, Endpoint_Read_Word_LE());\r
                                }\r
 \r
                                /* Write the filled FLASH page to memory */\r
-                               boot_page_write(PageAddress);\r
+                               boot_page_write(PageByteAddress);\r
                                boot_spm_busy_wait();\r
-\r
-                               /* Re-enable RWW section */\r
-                               boot_rww_enable();\r
                        }\r
 \r
                        Endpoint_ClearOUT();\r
index 9dac8f5..1034c1c 100644 (file)
@@ -13,7 +13,7 @@
  *  - AT90USB162 (Teensy 1.0)\r
  *  - AT90USB646 (Teensy++ 1.0)\r
  *  - ATMEGA32U4 (Teensy 2.0)\r
- *  - AT90USB1287 (Teensy++ 2.0)\r
+ *  - AT90USB1286 (Teensy++ 2.0)\r
  *\r
  *  \section SSec_Info USB Information:\r
  *\r
@@ -51,7 +51,9 @@
  *  \r
  * Out of the box this bootloader builds for the ATMEGA32U4, and will fit into 2-4KB of bootloader space. For other\r
  * devices, the makefile will need to be updated to reflect the altered MCU model and bootloader start address. When\r
- * calculating the bootloader start address, use (TARGET_FLASH_SIZE_BYTES - 4096).\r
+ * calculating the bootloader start address, use (TARGET_FLASH_SIZE_BYTES - 4096) for targets where the bootloader\r
+ * compiles larger than 2KB, or (TARGET_FLASH_SIZE_BYTES - 2048) for smaller targets where the bootloader compiles\r
+ * under 2KB.\r
  *\r
  * This spoofs (with permission) the official Teensy bootloader's VID and PID, so that the software remains\r
  * compatible with no changes.\r
index 404b55f..9a9f5ff 100644 (file)
@@ -68,7 +68,7 @@ BOARD  =
 #     does not *change* the processor frequency - it should merely be updated to\r
 #     reflect the processor speed set externally so that the code can use accurate\r
 #     software delays.\r
-F_CPU = 16000000\r
+F_CPU = 8000000\r
 \r
 \r
 # Input clock frequency.\r
index 18bfe0c..4a1dba0 100644 (file)
@@ -36,6 +36,8 @@
   *    selected (thanks to Steffan Woltjer)\r
   *  - Removed software PDI and TPI emulation from the AVRISP-MKII clone project as it was very buggy and slow - PDI and TPI must\r
   *    now be implemented via seperate programming headers\r
+  *  - The CDC class bootloader now uses a watchdog reset rather than a soft-reset when exited to ensure that all hardware is\r
+  *    properly reset to their defaults\r
   *\r
   *  <b>Fixed:</b>\r
   *  - Fixed software PDI/TPI programming mode in the AVRISP project not correctly toggling just the clock pin\r
@@ -63,6 +65,7 @@
   *    HID_HOST_BOOT_PROTOCOL_ONLY compile time option is set\r
   *  - Fixed INTERRUPT_CONTROL_ENDPOINT compile time option preventing other interrupts from occuring while the control endpoint\r
   *    request is being processed, causing possible lockups if a USB interrupt occurs during a transfer\r
+  *  - Fixed TeensyHID bootloader not working on some USB AVR models with the official TeensyLoader GUI application\r
   *\r
   *  \section Sec_ChangeLog100219 Version 100219\r
   *\r