Make CDC class bootloader hard-reset the AVR when exited instead of a soft-reset. Reduce size of the TeensyHID bootloader slightly.

Fix the TeensyHID bootloader for the larger USB AVR devices, since Paul uses a different (undocumented) addressing scheme on these devices.
pull/1469/head
Dean Camera 15 years ago
parent add5192366
commit c3db72afdc

@ -54,8 +54,8 @@ CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600,
uint32_t CurrAddress; uint32_t CurrAddress;
/** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run /** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run
* via a soft reset. When cleared, the bootloader will abort, the USB interface will shut down and the application * via a watchdog reset. When cleared the bootloader will exit, starting the watchdog and entering an infinite
* jumped to via an indirect jump to location 0x0000. * loop until the AVR restarts and the application runs.
*/ */
bool RunBootloader = true; bool RunBootloader = true;
@ -78,12 +78,13 @@ int main(void)
USB_USBTask(); USB_USBTask();
} }
/* Reset all configured hardware to their default states for the user app */ /* Disconnect from the host - USB interface will be reset later along with the AVR */
ResetHardware(); USB_Detach();
/* Start the user application */ /* Enable the watchdog and force a timeout to reset the AVR */
AppPtr_t AppStartPtr = (AppPtr_t)0x0000; wdt_enable(WDTO_250MS);
AppStartPtr();
for (;;);
} }
/** Configures all hardware required for the bootloader. */ /** Configures all hardware required for the bootloader. */
@ -104,20 +105,6 @@ void SetupHardware(void)
USB_Init(); USB_Init();
} }
/** Resets all configured hardware required for the bootloader back to their original states. */
void ResetHardware(void)
{
/* Shut down the USB subsystem */
USB_ShutDown();
/* Relocate the interrupt vector table back to the application section */
MCUCR = (1 << IVCE);
MCUCR = 0;
/* Re-enable RWW section */
boot_rww_enable();
}
/** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready /** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready
* to relay data to and from the attached USB host. * to relay data to and from the attached USB host.
*/ */

@ -117,7 +117,6 @@
/* Function Prototypes: */ /* Function Prototypes: */
void CDC_Task(void); void CDC_Task(void);
void SetupHardware(void); void SetupHardware(void);
void ResetHardware(void);
void EVENT_USB_Device_ConfigurationChanged(void); void EVENT_USB_Device_ConfigurationChanged(void);
void EVENT_USB_Device_UnhandledControlRequest(void); void EVENT_USB_Device_UnhandledControlRequest(void);

@ -93,7 +93,7 @@
/** Vendor usage page for the Teensy 2.0 board */ /** Vendor usage page for the Teensy 2.0 board */
#define TEENSY_USAGEPAGE_20 0x1B #define TEENSY_USAGEPAGE_20 0x1B
/** Vendor usage page for the Teensy++ 1.0 board */ /** Vendor usage page for the Teensy++ 2.0 board */
#define TEENSY_USAGEPAGE_20PP 0x1C #define TEENSY_USAGEPAGE_20PP 0x1C
#if defined(USB_SERIES_2_AVR) #if defined(USB_SERIES_2_AVR)

@ -105,18 +105,24 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
/* Wait until the command has been sent by the host */ /* Wait until the command has been sent by the host */
while (!(Endpoint_IsOUTReceived())); while (!(Endpoint_IsOUTReceived()));
/* Read in the write destination address */ /* Read in the write destination index */
uint16_t PageAddress = Endpoint_Read_Word_LE(); uint16_t PageIndex = Endpoint_Read_Word_LE();
/* Check if the command is a program page command, or a start application command */ /* Check if the command is a program page command, or a start application command */
if (PageAddress == TEENSY_STARTAPPLICATION) if (PageIndex == TEENSY_STARTAPPLICATION)
{ {
RunBootloader = false; RunBootloader = false;
} }
else else
{ {
#if (SPM_PAGESIZE == 128)
uint16_t PageByteAddress = PageIndex;
#else
uint32_t PageByteAddress = ((uint32_t)PageIndex << 8);
#endif
/* Erase the given FLASH page, ready to be programmed */ /* Erase the given FLASH page, ready to be programmed */
boot_page_erase(PageAddress); boot_page_erase(PageByteAddress);
boot_spm_busy_wait(); boot_spm_busy_wait();
/* Write each of the FLASH page's bytes in sequence */ /* Write each of the FLASH page's bytes in sequence */
@ -134,15 +140,12 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
} }
/* Write the next data word to the FLASH page */ /* Write the next data word to the FLASH page */
boot_page_fill(PageAddress + PageByte, Endpoint_Read_Word_LE()); boot_page_fill(PageByteAddress + PageByte, Endpoint_Read_Word_LE());
} }
/* Write the filled FLASH page to memory */ /* Write the filled FLASH page to memory */
boot_page_write(PageAddress); boot_page_write(PageByteAddress);
boot_spm_busy_wait(); boot_spm_busy_wait();
/* Re-enable RWW section */
boot_rww_enable();
} }
Endpoint_ClearOUT(); Endpoint_ClearOUT();

@ -13,7 +13,7 @@
* - AT90USB162 (Teensy 1.0) * - AT90USB162 (Teensy 1.0)
* - AT90USB646 (Teensy++ 1.0) * - AT90USB646 (Teensy++ 1.0)
* - ATMEGA32U4 (Teensy 2.0) * - ATMEGA32U4 (Teensy 2.0)
* - AT90USB1287 (Teensy++ 2.0) * - AT90USB1286 (Teensy++ 2.0)
* *
* \section SSec_Info USB Information: * \section SSec_Info USB Information:
* *
@ -51,7 +51,9 @@
* *
* Out of the box this bootloader builds for the ATMEGA32U4, and will fit into 2-4KB of bootloader space. For other * Out of the box this bootloader builds for the ATMEGA32U4, and will fit into 2-4KB of bootloader space. For other
* devices, the makefile will need to be updated to reflect the altered MCU model and bootloader start address. When * devices, the makefile will need to be updated to reflect the altered MCU model and bootloader start address. When
* calculating the bootloader start address, use (TARGET_FLASH_SIZE_BYTES - 4096). * calculating the bootloader start address, use (TARGET_FLASH_SIZE_BYTES - 4096) for targets where the bootloader
* compiles larger than 2KB, or (TARGET_FLASH_SIZE_BYTES - 2048) for smaller targets where the bootloader compiles
* under 2KB.
* *
* This spoofs (with permission) the official Teensy bootloader's VID and PID, so that the software remains * This spoofs (with permission) the official Teensy bootloader's VID and PID, so that the software remains
* compatible with no changes. * compatible with no changes.

@ -68,7 +68,7 @@ BOARD =
# does not *change* the processor frequency - it should merely be updated to # does not *change* the processor frequency - it should merely be updated to
# reflect the processor speed set externally so that the code can use accurate # reflect the processor speed set externally so that the code can use accurate
# software delays. # software delays.
F_CPU = 16000000 F_CPU = 8000000
# Input clock frequency. # Input clock frequency.

@ -36,6 +36,8 @@
* selected (thanks to Steffan Woltjer) * selected (thanks to Steffan Woltjer)
* - Removed software PDI and TPI emulation from the AVRISP-MKII clone project as it was very buggy and slow - PDI and TPI must * - Removed software PDI and TPI emulation from the AVRISP-MKII clone project as it was very buggy and slow - PDI and TPI must
* now be implemented via seperate programming headers * now be implemented via seperate programming headers
* - The CDC class bootloader now uses a watchdog reset rather than a soft-reset when exited to ensure that all hardware is
* properly reset to their defaults
* *
* <b>Fixed:</b> * <b>Fixed:</b>
* - Fixed software PDI/TPI programming mode in the AVRISP project not correctly toggling just the clock pin * - Fixed software PDI/TPI programming mode in the AVRISP project not correctly toggling just the clock pin
@ -63,6 +65,7 @@
* HID_HOST_BOOT_PROTOCOL_ONLY compile time option is set * HID_HOST_BOOT_PROTOCOL_ONLY compile time option is set
* - Fixed INTERRUPT_CONTROL_ENDPOINT compile time option preventing other interrupts from occuring while the control endpoint * - Fixed INTERRUPT_CONTROL_ENDPOINT compile time option preventing other interrupts from occuring while the control endpoint
* request is being processed, causing possible lockups if a USB interrupt occurs during a transfer * request is being processed, causing possible lockups if a USB interrupt occurs during a transfer
* - Fixed TeensyHID bootloader not working on some USB AVR models with the official TeensyLoader GUI application
* *
* \section Sec_ChangeLog100219 Version 100219 * \section Sec_ChangeLog100219 Version 100219
* *

Loading…
Cancel
Save