Fix the TeensyHID bootloader for the larger USB AVR devices, since Paul uses a different (undocumented) addressing scheme on these devices.
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
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
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
/* 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
/** 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
/* 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
}\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
* - 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
* \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
# 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
* 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
* 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