Fixed device state not being reset back to the default state if the host sets the...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 4 May 2010 10:07:22 +0000 (10:07 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 4 May 2010 10:07:22 +0000 (10:07 +0000)
Fixed Set Configuration requests not being stalled until the host has set the device's address.

Fixed possibility of internal signature retrieval being corrupted if an interrupt occurs during a signature byte read (thanks to Andrei Krainev).

Bootloaders/TeensyHID/Descriptors.c
LUFA/Drivers/USB/LowLevel/DevChapter9.c
LUFA/Drivers/USB/LowLevel/DevChapter9.h
LUFA/ManPages/ChangeLog.txt
Projects/AVRISP-MKII/AVRISP.txt

index 2832ec3..4142f12 100644 (file)
@@ -157,26 +157,29 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, const uint8_t wIndex,
        void*    Address = NULL;\r
        uint16_t Size    = NO_DESCRIPTOR;\r
 \r
        void*    Address = NULL;\r
        uint16_t Size    = NO_DESCRIPTOR;\r
 \r
-       switch (DescriptorType)\r
+       /* If/Else If chain compiles slightly smaller than a switch case */\r
+\r
+       if (DescriptorType == DTYPE_Device)\r
+       {\r
+               Address = (void*)&DeviceDescriptor;\r
+               Size    = sizeof(USB_Descriptor_Device_t);      \r
+       }\r
+       else if (DescriptorType == DTYPE_Device)\r
+       {\r
+               Address = (void*)&ConfigurationDescriptor;\r
+               Size    = sizeof(USB_Descriptor_Configuration_t);       \r
+       }\r
+       else if (DescriptorType == DTYPE_HID)\r
+       {\r
+               Address = (void*)&ConfigurationDescriptor.HID_VendorHID;\r
+               Size    = sizeof(USB_Descriptor_HID_t);\r
+       }\r
+       else\r
        {\r
        {\r
-               case DTYPE_Device:\r
-                       Address = (void*)&DeviceDescriptor;\r
-                       Size    = sizeof(USB_Descriptor_Device_t);\r
-                       break;\r
-               case DTYPE_Configuration:\r
-                       Address = (void*)&ConfigurationDescriptor;\r
-                       Size    = sizeof(USB_Descriptor_Configuration_t);\r
-                       break;\r
-               case DTYPE_HID:\r
-                       Address = (void*)&ConfigurationDescriptor.HID_VendorHID;\r
-                       Size    = sizeof(USB_Descriptor_HID_t);\r
-                       break;\r
-               case DTYPE_Report:\r
-                       Address = (void*)&HIDReport;\r
-                       Size    = sizeof(HIDReport);\r
-                       break;\r
+               Address = (void*)&HIDReport;\r
+               Size    = sizeof(HIDReport);\r
        }\r
        }\r
-       \r
+\r
        *DescriptorAddress = Address;\r
        return Size;\r
 }\r
        *DescriptorAddress = Address;\r
        return Size;\r
 }\r
index 17a5fd4..b7f811b 100644 (file)
@@ -136,8 +136,7 @@ static void USB_Device_SetAddress(void)
                  return;\r
        }\r
 \r
                  return;\r
        }\r
 \r
-       if (DeviceAddress)\r
-         USB_DeviceState = DEVICE_STATE_Addressed;\r
+       USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default;\r
 \r
        UDADDR = ((1 << ADDEN) | DeviceAddress);\r
 \r
 \r
        UDADDR = ((1 << ADDEN) | DeviceAddress);\r
 \r
@@ -146,12 +145,21 @@ static void USB_Device_SetAddress(void)
 \r
 static void USB_Device_SetConfiguration(void)\r
 {\r
 \r
 static void USB_Device_SetConfiguration(void)\r
 {\r
+       if (USB_DeviceState != DEVICE_STATE_Addressed)\r
+         return;\r
+       \r
 #if defined(FIXED_NUM_CONFIGURATIONS)\r
        if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS)\r
          return;\r
 #else\r
 #if defined(FIXED_NUM_CONFIGURATIONS)\r
        if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS)\r
          return;\r
 #else\r
-       #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS)\r
-       uint8_t MemoryAddressSpace;\r
+       #if defined(USE_FLASH_DESCRIPTORS)\r
+               #define MemoryAddressSpace  MEMSPACE_FLASH\r
+       #elif defined(USE_EEPROM_DESCRIPTORS)\r
+               #define MemoryAddressSpace  MEMSPACE_EEPROM\r
+       #elif defined(USE_SRAM_DESCRIPTORS)\r
+               #define MemoryAddressSpace  MEMSPACE_SRAM\r
+       #else\r
+               uint8_t MemoryAddressSpace;\r
        #endif\r
        \r
        USB_Descriptor_Device_t* DevDescriptorPtr;\r
        #endif\r
        \r
        USB_Descriptor_Device_t* DevDescriptorPtr;\r
@@ -165,16 +173,6 @@ static void USB_Device_SetConfiguration(void)
                return;\r
        }\r
        \r
                return;\r
        }\r
        \r
-       #if defined(USE_RAM_DESCRIPTORS)\r
-       if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations)\r
-         return;\r
-       #elif defined (USE_EEPROM_DESCRIPTORS)\r
-       if ((uint8_t)USB_ControlRequest.wValue > eeprom_read_byte(&DevDescriptorPtr->NumberOfConfigurations))\r
-         return;\r
-       #elif defined (USE_FLASH_DESCRIPTORS)\r
-       if ((uint8_t)USB_ControlRequest.wValue > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations))\r
-         return;\r
-       #else\r
        if (MemoryAddressSpace == MEMSPACE_FLASH)\r
        {\r
                if (((uint8_t)USB_ControlRequest.wValue > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))\r
        if (MemoryAddressSpace == MEMSPACE_FLASH)\r
        {\r
                if (((uint8_t)USB_ControlRequest.wValue > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))\r
@@ -190,7 +188,6 @@ static void USB_Device_SetConfiguration(void)
                if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations)\r
                  return;\r
        }\r
                if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations)\r
                  return;\r
        }\r
-       #endif\r
 #endif\r
        \r
        Endpoint_ClearSETUP();\r
 #endif\r
        \r
        Endpoint_ClearSETUP();\r
@@ -234,17 +231,20 @@ static void USB_Device_GetInternalSerialDescriptor(void)
        \r
        uint8_t SigReadAddress = 0x0E;\r
 \r
        \r
        uint8_t SigReadAddress = 0x0E;\r
 \r
-       for (uint8_t SerialCharNum = 0; SerialCharNum < 20; SerialCharNum++)\r
+       ATOMIC_BLOCK(ATOMIC_RESTORESTATE)\r
        {\r
        {\r
-               uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);\r
-               \r
-               if (SerialCharNum & 0x01)\r
+               for (uint8_t SerialCharNum = 0; SerialCharNum < 20; SerialCharNum++)\r
                {\r
                {\r
-                       SerialByte >>= 4;\r
-                       SigReadAddress++;\r
+                       uint8_t SerialByte = boot_signature_byte_get(SigReadAddress);\r
+                       \r
+                       if (SerialCharNum & 0x01)\r
+                       {\r
+                               SerialByte >>= 4;\r
+                               SigReadAddress++;\r
+                       }\r
+                       \r
+                       SignatureDescriptor.UnicodeString[SerialCharNum] = USB_Device_NibbleToASCII(SerialByte);\r
                }\r
                }\r
-               \r
-               SignatureDescriptor.UnicodeString[SerialCharNum] = USB_Device_NibbleToASCII(SerialByte);\r
        }\r
        \r
        Endpoint_ClearSETUP();\r
        }\r
        \r
        Endpoint_ClearSETUP();\r
index d591327..868c3fa 100644 (file)
@@ -46,6 +46,7 @@
                #include <avr/pgmspace.h>\r
                #include <avr/eeprom.h>\r
                #include <avr/boot.h>\r
                #include <avr/pgmspace.h>\r
                #include <avr/eeprom.h>\r
                #include <avr/boot.h>\r
+               #include <util/atomic.h>\r
                \r
                #include "../HighLevel/StdDescriptors.h"\r
                #include "../HighLevel/Events.h"\r
                \r
                #include "../HighLevel/StdDescriptors.h"\r
                #include "../HighLevel/Events.h"\r
index 8d5a7ab..c38f9e7 100644 (file)
   *  - Fixed Set/Clear Feature requests directed to a non-configured endpoint not returning a stall to the host\r
   *  - Fixed HID Device Class Driver not allocating a temporary buffer when the host requests a report via the control endpoint and the\r
   *    user has set the PrevReportINBuffer driver configuration element to NULL (thanks to Lars Noschinski)\r
   *  - Fixed Set/Clear Feature requests directed to a non-configured endpoint not returning a stall to the host\r
   *  - Fixed HID Device Class Driver not allocating a temporary buffer when the host requests a report via the control endpoint and the\r
   *    user has set the PrevReportINBuffer driver configuration element to NULL (thanks to Lars Noschinski)\r
+  *  - Fixed device state not being reset to DEVICE_STATE_Default if the host sets a 0x00 device address\r
+  *  - Fixed device not stalling configuration requests before the device's address has been set\r
+  *  - Fixed possibility of internal signature retrieval being corrupted if an interrupt occurs during a signature byte\r
+  *    read (thanks to Andrei Krainev)\r
+  *  - Fixed device state not being reset back to the default state if the host sets the address to 0\r
+  *  - Fixed Set Configuration requests not being stalled until the host has set the device's address\r
   *\r
   *  \section Sec_ChangeLog100219 Version 100219\r
   *\r
   *\r
   *  \section Sec_ChangeLog100219 Version 100219\r
   *\r
index fddae6d..6109031 100644 (file)
  *  Note that this design currently has the following limitations:\r
  *    - Minimum ISP target clock speed of 500KHz due to hardware SPI module prescaler limitations\r
  *    - No reversed/shorted target connector detection and notification\r
  *  Note that this design currently has the following limitations:\r
  *    - Minimum ISP target clock speed of 500KHz due to hardware SPI module prescaler limitations\r
  *    - No reversed/shorted target connector detection and notification\r
+ *    - Very slow TPI and PDI programming when in software emulated USART mode\r
  *\r
  *  On AVR models with an ADC converter, AVCC should be tied to 5V (e.g. VBUS) and the VTARGET_ADC_CHANNEL token should be\r
  *  set to an appropriate ADC channel number in the project makefile for VTARGET detection to operate correctly. On models\r
  *  without an ADC converter, VTARGET will report a fixed 5V level at all times.\r
  *\r
  *  When compiled for the XPLAIN board target, this will automatically configure itself for the correct connections to the\r
  *\r
  *  On AVR models with an ADC converter, AVCC should be tied to 5V (e.g. VBUS) and the VTARGET_ADC_CHANNEL token should be\r
  *  set to an appropriate ADC channel number in the project makefile for VTARGET detection to operate correctly. On models\r
  *  without an ADC converter, VTARGET will report a fixed 5V level at all times.\r
  *\r
  *  When compiled for the XPLAIN board target, this will automatically configure itself for the correct connections to the\r
- *  XPLAIN's XMEGA AVR, and will enable PDI/TPI only programming support (since ISP mode is not needed). Note that the\r
- *  first revision XPLAIN board lacks a bootloader on the AT90USB1287, and thus for this firmware to be loaded, an external\r
+ *  XPLAIN's XMEGA AVR, and will enable hardware PDI/TPI only programming support (since ISP mode is not needed). Note that\r
+ *  the first revision XPLAIN board lacks a bootloader on the AT90USB1287, and thus for this firmware to be loaded, an external\r
  *  programmer will be required.\r
  *\r
  *  While this application can be compiled for USB AVRs with as little as 8KB of FLASH, for full functionality 16KB or more\r
  *  programmer will be required.\r
  *\r
  *  While this application can be compiled for USB AVRs with as little as 8KB of FLASH, for full functionality 16KB or more\r