Fixed random enumeration failure while in device mode due to interrupts causing the Set Address request to exceed maximum timings.

pull/1469/head
Dean Camera 14 years ago
parent bea72a8412
commit c1cfffd8eb

@ -126,27 +126,28 @@ static void USB_Device_SetAddress(void)
{ {
uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F); uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F);
Endpoint_ClearSETUP(); ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
{
Endpoint_ClearSETUP();
Endpoint_ClearStatusStage(); Endpoint_ClearStatusStage();
while (!(Endpoint_IsINReady())) while (!(Endpoint_IsINReady()));
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default; USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default;
USB_Device_SetDeviceAddress(DeviceAddress); USB_Device_SetDeviceAddress(DeviceAddress);
}
} }
static void USB_Device_SetConfiguration(void) static void USB_Device_SetConfiguration(void)
{ {
#if defined(FIXED_NUM_CONFIGURATIONS) #if defined(FIXED_NUM_CONFIGURATIONS)
if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS) if ((uint8_t)USB_ControlRequest.wValue > FIXED_NUM_CONFIGURATIONS)
return; return;
#else #else
USB_Descriptor_Device_t* DevDescriptorPtr;
#if defined(USE_FLASH_DESCRIPTORS) #if defined(USE_FLASH_DESCRIPTORS)
#define MemoryAddressSpace MEMSPACE_FLASH #define MemoryAddressSpace MEMSPACE_FLASH
#elif defined(USE_EEPROM_DESCRIPTORS) #elif defined(USE_EEPROM_DESCRIPTORS)
@ -157,8 +158,6 @@ static void USB_Device_SetConfiguration(void)
uint8_t MemoryAddressSpace; uint8_t MemoryAddressSpace;
#endif #endif
USB_Descriptor_Device_t* DevDescriptorPtr;
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr
#if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS)
, &MemoryAddressSpace , &MemoryAddressSpace
@ -183,7 +182,7 @@ static void USB_Device_SetConfiguration(void)
if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations) if ((uint8_t)USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations)
return; return;
} }
#endif #endif
Endpoint_ClearSETUP(); Endpoint_ClearSETUP();
@ -199,7 +198,7 @@ static void USB_Device_SetConfiguration(void)
EVENT_USB_Device_ConfigurationChanged(); EVENT_USB_Device_ConfigurationChanged();
} }
void USB_Device_GetConfiguration(void) static void USB_Device_GetConfiguration(void)
{ {
Endpoint_ClearSETUP(); Endpoint_ClearSETUP();
@ -259,7 +258,7 @@ static void USB_Device_GetDescriptor(void)
uint16_t DescriptorSize; uint16_t DescriptorSize;
#if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS) #if !defined(USE_FLASH_DESCRIPTORS) && !defined(USE_EEPROM_DESCRIPTORS) && !defined(USE_RAM_DESCRIPTORS)
uint8_t DescriptorAddressSpace; uint8_t DescriptorAddressSpace;
#endif #endif
#if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR) #if !defined(NO_INTERNAL_SERIAL) && (USE_INTERNAL_SERIAL != NO_DESCRIPTOR)
@ -306,20 +305,20 @@ static void USB_Device_GetStatus(void)
switch (USB_ControlRequest.bmRequestType) switch (USB_ControlRequest.bmRequestType)
{ {
#if !defined(NO_DEVICE_SELF_POWER) || !defined(NO_DEVICE_REMOTE_WAKEUP) #if !defined(NO_DEVICE_SELF_POWER) || !defined(NO_DEVICE_REMOTE_WAKEUP)
case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE): case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE):
#if !defined(NO_DEVICE_SELF_POWER) #if !defined(NO_DEVICE_SELF_POWER)
if (USB_CurrentlySelfPowered) if (USB_CurrentlySelfPowered)
CurrentStatus |= FEATURE_SELFPOWERED_ENABLED; CurrentStatus |= FEATURE_SELFPOWERED_ENABLED;
#endif #endif
#if !defined(NO_DEVICE_REMOTE_WAKEUP) #if !defined(NO_DEVICE_REMOTE_WAKEUP)
if (USB_RemoteWakeupEnabled) if (USB_RemoteWakeupEnabled)
CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED; CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED;
#endif #endif
break; break;
#endif #endif
#if !defined(CONTROL_ONLY_DEVICE) #if !defined(CONTROL_ONLY_DEVICE)
case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT): case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT):
Endpoint_SelectEndpoint((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK); Endpoint_SelectEndpoint((uint8_t)USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);
@ -328,7 +327,7 @@ static void USB_Device_GetStatus(void)
Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);
break; break;
#endif #endif
default: default:
return; return;
} }
@ -345,7 +344,7 @@ static void USB_Device_ClearSetFeature(void)
{ {
switch (USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) switch (USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT)
{ {
#if !defined(NO_DEVICE_REMOTE_WAKEUP) #if !defined(NO_DEVICE_REMOTE_WAKEUP)
case REQREC_DEVICE: case REQREC_DEVICE:
if ((uint8_t)USB_ControlRequest.wValue == FEATURE_REMOTE_WAKEUP) if ((uint8_t)USB_ControlRequest.wValue == FEATURE_REMOTE_WAKEUP)
USB_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature); USB_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature);
@ -353,8 +352,8 @@ static void USB_Device_ClearSetFeature(void)
return; return;
break; break;
#endif #endif
#if !defined(CONTROL_ONLY_DEVICE) #if !defined(CONTROL_ONLY_DEVICE)
case REQREC_ENDPOINT: case REQREC_ENDPOINT:
if ((uint8_t)USB_ControlRequest.wValue == FEATURE_ENDPOINT_HALT) if ((uint8_t)USB_ControlRequest.wValue == FEATURE_ENDPOINT_HALT)
{ {
@ -381,7 +380,7 @@ static void USB_Device_ClearSetFeature(void)
} }
break; break;
#endif #endif
default: default:
return; return;
} }

@ -71,6 +71,7 @@
* - Fixed broken FLASH/EEPROM programming in the AVRISP-MKII clone project when writing in non-paged mode and the polling byte cannot be used * - Fixed broken FLASH/EEPROM programming in the AVRISP-MKII clone project when writing in non-paged mode and the polling byte cannot be used
* - Fixed SPI driver not explicitly setting /SS and MISO pins as inputs when SPI_Init() is called * - Fixed SPI driver not explicitly setting /SS and MISO pins as inputs when SPI_Init() is called
* - Fixed ISR definition conflict in the XPLAIN bridge between the software UART and the AVRISP-MKII ISP modules * - Fixed ISR definition conflict in the XPLAIN bridge between the software UART and the AVRISP-MKII ISP modules
* - Fixed random enumeration failure while in device mode due to interrupts causing the Set Address request to exceed maximum timings
* *
* \section Sec_ChangeLog100807 Version 100807 * \section Sec_ChangeLog100807 Version 100807
* <b>New:</b> * <b>New:</b>

Loading…
Cancel
Save