Fixed TeensyHID bootloader not enumerating to the host correctly.
authorDean Camera <dean@fourwalledcubicle.com>
Sun, 20 Dec 2009 12:09:22 +0000 (12:09 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Sun, 20 Dec 2009 12:09:22 +0000 (12:09 +0000)
Bootloaders/TeensyHID/TeensyHID.c
Bootloaders/TeensyHID/TeensyHID.h
Bootloaders/TeensyHID/TeensyHID.txt
Bootloaders/TeensyHID/makefile
LUFA/ManPages/ChangeLog.txt

index 84ec7aa..585cffd 100644 (file)
@@ -52,12 +52,12 @@ int main(void)
        while (RunBootloader)\r
          USB_USBTask();\r
        \r
        while (RunBootloader)\r
          USB_USBTask();\r
        \r
-       /* Turn off the USB interface, disconnect from the host */\r
-       USB_ShutDown();\r
+       /* Disconnect from the host - USB interface will be reset later along with the AVR */\r
+       USB_Detach();\r
 \r
        /* Enable the watchdog and force a timeout to reset the AVR */\r
        wdt_enable(WDTO_250MS);\r
 \r
        /* Enable the watchdog and force a timeout to reset the AVR */\r
        wdt_enable(WDTO_250MS);\r
-                                       \r
+\r
        for (;;);\r
 }\r
 \r
        for (;;);\r
 }\r
 \r
@@ -100,53 +100,50 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
        switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_SetReport:\r
        switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_SetReport:\r
-                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
-                       {\r
-                               Endpoint_ClearSETUP();\r
-                               \r
-                               /* Wait until the command has been sent by the host */\r
-                               while (!(Endpoint_IsOUTReceived()));\r
+                       Endpoint_ClearSETUP();\r
                        \r
                        \r
-                               /* Read in the write destination address */\r
-                               uint16_t PageAddress = Endpoint_Read_Word_LE();\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
+                       \r
+                       /* Check if the command is a program page command, or a start application command */\r
+                       if (PageAddress == TEENSY_STARTAPPLICATION)\r
+                       {\r
+                               RunBootloader = false;\r
+                       }\r
+                       else\r
+                       {\r
+                               /* Erase the given FLASH page, ready to be programmed */\r
+                               boot_page_erase(PageAddress);\r
+                               boot_spm_busy_wait();\r
                                \r
                                \r
-                               /* Check if the command is a program page command, or a start application command */\r
-                               if (PageAddress == TEENSY_STARTAPPLICATION)\r
-                               {\r
-                                       RunBootloader = false;\r
-                               }\r
-                               else\r
+                               /* Write each of the FLASH page's bytes in sequence */\r
+                               for (uint8_t PageByte = 0; PageByte < SPM_PAGESIZE; PageByte += 2)\r
                                {\r
                                {\r
-                                       /* Erase the given FLASH page, ready to be programmed */\r
-                                       boot_page_erase(PageAddress);\r
-                                       boot_spm_busy_wait();\r
-                                       \r
-                                       /* Write each of the FLASH page's bytes in sequence */\r
-                                       for (uint8_t PageByte = 0; PageByte < SPM_PAGESIZE; PageByte += 2)\r
+                                       /* Check if endpoint is empty - if so clear it and wait until ready for next packet */\r
+                                       if (!(Endpoint_BytesInEndpoint()))\r
                                        {\r
                                        {\r
-                                               /* Check if endpoint is empty - if so clear it and wait until ready for next packet */\r
-                                               if (!(Endpoint_BytesInEndpoint()))\r
-                                               {\r
-                                                       Endpoint_ClearOUT();\r
-                                                       while (!(Endpoint_IsOUTReceived()));\r
-                                               }\r
-\r
-                                               /* Write the next data word to the FLASH page */\r
-                                               boot_page_fill(PageAddress + PageByte, Endpoint_Read_Word_LE());\r
+                                               Endpoint_ClearOUT();\r
+                                               while (!(Endpoint_IsOUTReceived()));\r
                                        }\r
 \r
                                        }\r
 \r
-                                       /* Write the filled FLASH page to memory */\r
-                                       boot_page_write(PageAddress);\r
-                                       boot_spm_busy_wait();\r
-\r
-                                       /* Re-enable RWW section */\r
-                                       boot_rww_enable();\r
+                                       /* Write the next data word to the FLASH page */\r
+                                       boot_page_fill(PageAddress + PageByte, Endpoint_Read_Word_LE());\r
                                }\r
 \r
                                }\r
 \r
-                               Endpoint_ClearOUT();\r
+                               /* Write the filled FLASH page to memory */\r
+                               boot_page_write(PageAddress);\r
+                               boot_spm_busy_wait();\r
 \r
 \r
-                               Endpoint_ClearStatusStage();\r
+                               /* Re-enable RWW section */\r
+                               boot_rww_enable();\r
                        }\r
                        }\r
+\r
+                       Endpoint_ClearOUT();\r
+\r
+                       Endpoint_ClearStatusStage();\r
                        \r
                        break;\r
        }\r
                        \r
                        break;\r
        }\r
index a05729a..fe94b11 100644 (file)
 \r
                #include <LUFA/Drivers/USB/USB.h>\r
                \r
 \r
                #include <LUFA/Drivers/USB/USB.h>\r
                \r
-       /* Preprocessor Checks: */\r
-               #if !defined(__AVR_AT90USB162__) && !defined(__AVR_AT90USB646__)\r
-                       #error This bootloader is not compatible with the selected AVR model.\r
-               #endif\r
-\r
        /* Macros: */\r
                /** HID Class specific request to send the next HID report to the device. */\r
                #define REQ_SetReport             0x09\r
        /* Macros: */\r
                /** HID Class specific request to send the next HID report to the device. */\r
                #define REQ_SetReport             0x09\r
index 2f97a3d..bc4e15f 100644 (file)
  *\r
  *  The following list indicates what microcontrollers are compatible with this demo.\r
  *\r
  *\r
  *  The following list indicates what microcontrollers are compatible with this demo.\r
  *\r
- *  - AT90USB646\r
  *  - AT90USB162\r
  *  - AT90USB162\r
+ *  - ATMEGA32U4\r
+ *  - AT90USB646\r
+ *  - AT90USB1286\r
  *\r
  *  \section SSec_Info USB Information:\r
  *\r
  *\r
  *  \section SSec_Info USB Information:\r
  *\r
@@ -47,7 +49,9 @@
  * This bootloader enumerates to the host as a HID Class device, allowing for Teensy compatible programming\r
  * software to load firmware onto the AVR, such as the official software at <a>http://www.pjrc.com/teensy/</a>.\r
  *  \r
  * This bootloader enumerates to the host as a HID Class device, allowing for Teensy compatible programming\r
  * software to load firmware onto the AVR, such as the official software at <a>http://www.pjrc.com/teensy/</a>.\r
  *  \r
- * Out of the box this bootloader builds for the AT90USB162, and will fit into 4KB of bootloader space.\r
+ * Out of the box this bootloader builds for the ATMEGA32U4, and will fit into 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
  *\r
  * This spoofs (with permission) the official Teensy bootloader's VID and PID, so that the software remains\r
  * compatible with no changes.\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 6f45cf5..99e3b48 100644 (file)
@@ -60,7 +60,7 @@
 \r
 \r
 # MCU name\r
 \r
 \r
 # MCU name\r
-MCU = at90usb162\r
+MCU = atmega32u4\r
 \r
 \r
 # Target board (see library "Board Types" documentation, USER or blank for projects not requiring\r
 \r
 \r
 # Target board (see library "Board Types" documentation, USER or blank for projects not requiring\r
@@ -98,7 +98,7 @@ F_CLOCK = $(F_CPU)
 \r
 \r
 # Starting byte address of the bootloader\r
 \r
 \r
 # Starting byte address of the bootloader\r
-BOOT_START = 0xC000\r
+BOOT_START = 0x7000\r
 \r
 \r
 # Output format. (can be srec, ihex, binary)\r
 \r
 \r
 # Output format. (can be srec, ihex, binary)\r
@@ -121,7 +121,6 @@ LUFA_PATH = ../..
 \r
 # LUFA library compile-time options\r
 LUFA_OPTS  = -D USB_DEVICE_ONLY\r
 \r
 # LUFA library compile-time options\r
 LUFA_OPTS  = -D USB_DEVICE_ONLY\r
-LUFA_OPTS += -D CONTROL_ONLY_DEVICE\r
 LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0\r
 LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8\r
 LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1\r
 LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0\r
 LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8\r
 LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1\r
index ef2edbd..3bb5489 100644 (file)
@@ -66,6 +66,7 @@
   *  - Fixed Still Image Host Class driver truncating the PIMA response code (thanks to Daniel Seibert)\r
   *  - Fixed USB_CurrentMode not being reset to USB_MODE_NONE when the USB interface is shut down and both Host and Device modes can be\r
   *    used (thanks to Daniel Levy)\r
   *  - Fixed Still Image Host Class driver truncating the PIMA response code (thanks to Daniel Seibert)\r
   *  - Fixed USB_CurrentMode not being reset to USB_MODE_NONE when the USB interface is shut down and both Host and Device modes can be\r
   *    used (thanks to Daniel Levy)\r
+  *  - Fixed TeensyHID bootloader not enumerating to the host correctly\r
   *\r
   *  \section Sec_ChangeLog091122 Version 091122\r
   *\r
   *\r
   *  \section Sec_ChangeLog091122 Version 091122\r
   *\r