aboutsummaryrefslogtreecommitdiffstats
path: root/Bootloaders/TeensyHID
diff options
context:
space:
mode:
Diffstat (limited to 'Bootloaders/TeensyHID')
-rw-r--r--Bootloaders/TeensyHID/TeensyHID.c77
-rw-r--r--Bootloaders/TeensyHID/TeensyHID.h5
-rw-r--r--Bootloaders/TeensyHID/TeensyHID.txt8
-rw-r--r--Bootloaders/TeensyHID/makefile5
4 files changed, 45 insertions, 50 deletions
diff --git a/Bootloaders/TeensyHID/TeensyHID.c b/Bootloaders/TeensyHID/TeensyHID.c
index 84ec7aac7..585cffd4d 100644
--- a/Bootloaders/TeensyHID/TeensyHID.c
+++ b/Bootloaders/TeensyHID/TeensyHID.c
@@ -52,12 +52,12 @@ int main(void)
while (RunBootloader)
USB_USBTask();
- /* Turn off the USB interface, disconnect from the host */
- USB_ShutDown();
+ /* Disconnect from the host - USB interface will be reset later along with the AVR */
+ USB_Detach();
/* Enable the watchdog and force a timeout to reset the AVR */
wdt_enable(WDTO_250MS);
-
+
for (;;);
}
@@ -100,53 +100,50 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
switch (USB_ControlRequest.bRequest)
{
case REQ_SetReport:
- if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
- {
- Endpoint_ClearSETUP();
-
- /* Wait until the command has been sent by the host */
- while (!(Endpoint_IsOUTReceived()));
+ Endpoint_ClearSETUP();
- /* Read in the write destination address */
- uint16_t PageAddress = Endpoint_Read_Word_LE();
+ /* Wait until the command has been sent by the host */
+ while (!(Endpoint_IsOUTReceived()));
+
+ /* Read in the write destination address */
+ uint16_t PageAddress = Endpoint_Read_Word_LE();
+
+ /* Check if the command is a program page command, or a start application command */
+ if (PageAddress == TEENSY_STARTAPPLICATION)
+ {
+ RunBootloader = false;
+ }
+ else
+ {
+ /* Erase the given FLASH page, ready to be programmed */
+ boot_page_erase(PageAddress);
+ boot_spm_busy_wait();
- /* Check if the command is a program page command, or a start application command */
- if (PageAddress == TEENSY_STARTAPPLICATION)
- {
- RunBootloader = false;
- }
- else
+ /* Write each of the FLASH page's bytes in sequence */
+ for (uint8_t PageByte = 0; PageByte < SPM_PAGESIZE; PageByte += 2)
{
- /* Erase the given FLASH page, ready to be programmed */
- boot_page_erase(PageAddress);
- boot_spm_busy_wait();
-
- /* Write each of the FLASH page's bytes in sequence */
- for (uint8_t PageByte = 0; PageByte < SPM_PAGESIZE; PageByte += 2)
+ /* Check if endpoint is empty - if so clear it and wait until ready for next packet */
+ if (!(Endpoint_BytesInEndpoint()))
{
- /* Check if endpoint is empty - if so clear it and wait until ready for next packet */
- if (!(Endpoint_BytesInEndpoint()))
- {
- Endpoint_ClearOUT();
- while (!(Endpoint_IsOUTReceived()));
- }
-
- /* Write the next data word to the FLASH page */
- boot_page_fill(PageAddress + PageByte, Endpoint_Read_Word_LE());
+ Endpoint_ClearOUT();
+ while (!(Endpoint_IsOUTReceived()));
}
- /* Write the filled FLASH page to memory */
- boot_page_write(PageAddress);
- boot_spm_busy_wait();
-
- /* Re-enable RWW section */
- boot_rww_enable();
+ /* Write the next data word to the FLASH page */
+ boot_page_fill(PageAddress + PageByte, Endpoint_Read_Word_LE());
}
- Endpoint_ClearOUT();
+ /* Write the filled FLASH page to memory */
+ boot_page_write(PageAddress);
+ boot_spm_busy_wait();
- Endpoint_ClearStatusStage();
+ /* Re-enable RWW section */
+ boot_rww_enable();
}
+
+ Endpoint_ClearOUT();
+
+ Endpoint_ClearStatusStage();
break;
}
diff --git a/Bootloaders/TeensyHID/TeensyHID.h b/Bootloaders/TeensyHID/TeensyHID.h
index a05729a50..fe94b1116 100644
--- a/Bootloaders/TeensyHID/TeensyHID.h
+++ b/Bootloaders/TeensyHID/TeensyHID.h
@@ -49,11 +49,6 @@
#include <LUFA/Drivers/USB/USB.h>
- /* Preprocessor Checks: */
- #if !defined(__AVR_AT90USB162__) && !defined(__AVR_AT90USB646__)
- #error This bootloader is not compatible with the selected AVR model.
- #endif
-
/* Macros: */
/** HID Class specific request to send the next HID report to the device. */
#define REQ_SetReport 0x09
diff --git a/Bootloaders/TeensyHID/TeensyHID.txt b/Bootloaders/TeensyHID/TeensyHID.txt
index 2f97a3d63..bc4e15f1c 100644
--- a/Bootloaders/TeensyHID/TeensyHID.txt
+++ b/Bootloaders/TeensyHID/TeensyHID.txt
@@ -10,8 +10,10 @@
*
* The following list indicates what microcontrollers are compatible with this demo.
*
- * - AT90USB646
* - AT90USB162
+ * - ATMEGA32U4
+ * - AT90USB646
+ * - AT90USB1286
*
* \section SSec_Info USB Information:
*
@@ -47,7 +49,9 @@
* This bootloader enumerates to the host as a HID Class device, allowing for Teensy compatible programming
* software to load firmware onto the AVR, such as the official software at <a>http://www.pjrc.com/teensy/</a>.
*
- * Out of the box this bootloader builds for the AT90USB162, and will fit into 4KB of bootloader space.
+ * Out of the box this bootloader builds for the ATMEGA32U4, and will fit into 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
+ * calculating the bootloader start address, use (TARGET_FLASH_SIZE_BYTES - 4096).
*
* This spoofs (with permission) the official Teensy bootloader's VID and PID, so that the software remains
* compatible with no changes.
diff --git a/Bootloaders/TeensyHID/makefile b/Bootloaders/TeensyHID/makefile
index 6f45cf543..99e3b4804 100644
--- a/Bootloaders/TeensyHID/makefile
+++ b/Bootloaders/TeensyHID/makefile
@@ -60,7 +60,7 @@
# MCU name
-MCU = at90usb162
+MCU = atmega32u4
# Target board (see library "Board Types" documentation, USER or blank for projects not requiring
@@ -98,7 +98,7 @@ F_CLOCK = $(F_CPU)
# Starting byte address of the bootloader
-BOOT_START = 0xC000
+BOOT_START = 0x7000
# Output format. (can be srec, ihex, binary)
@@ -121,7 +121,6 @@ LUFA_PATH = ../..
# LUFA library compile-time options
LUFA_OPTS = -D USB_DEVICE_ONLY
-LUFA_OPTS += -D CONTROL_ONLY_DEVICE
LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1