-
Notifications
You must be signed in to change notification settings - Fork 338
Description
I explored the VirtualSerial example for AVRDX devices and was not able to get the CDC_REQ_SetLineEncoding transfer running. The OUT buffer of EP0 seems to hold the SETUP data (0x21,0x20,0,0,0,0,0x07,0). But the IN Buffer holds the expected data. The reason is probably the following special feature (cited from datasheet):
"Control transfers use the endpoint buffers differently from IN and OUT endpoints. The data packet in the Setup stage is stored in the endpoint’s OUT data buffer, while data packets in the Data stage (i.e., IN or OUT) are stored in the IN data buffer. In other words, EP[n].OUT.DATAPTR points to the received Setup stage packet and EP[n].IN.DATAPTR points to data to be transmitted or received in the Data stage."
Currently I substituted Endpoint_Read_Control_EStream_LE by Endpoint_Read_DATA_Stage_Payload (see below, no other changes done):
`
uint8_t Endpoint_Read_DATA_Stage_Payload(void* const Buffer){
//Control transfers use the endpoint buffers differently from IN and OUT endpoints.
//IN endpoint holds the DATA stage payload, regardless of direction.
//SETUP packet is stored in the IN endpoint.
uint8_t* DataStream = (uint8_t*)Buffer;
Endpoint_SelectEndpoint(USB_Endpoint_SelectedEndpoint | ENDPOINT_DIR_IN);//select in
uint8_t Length=USB_Endpoint_SelectedFIFO->Length;
if (!(Length))
Endpoint_ClearIN();
while (Length)
{
uint8_t USB_DeviceState_LCL = USB_DeviceState;
if (USB_DeviceState_LCL == DEVICE_STATE_Unattached)
return ENDPOINT_RWCSTREAM_DeviceDisconnected;
else if (USB_DeviceState_LCL == DEVICE_STATE_Suspended)
return ENDPOINT_RWCSTREAM_BusSuspended;
else if (Endpoint_IsSETUPReceived())
return ENDPOINT_RWCSTREAM_HostAborted;
if (Endpoint_IsINReady())
{
volatile uint8_t BytesInEndpoint=(USB_Endpoint_SelectedFIFO->Length - USB_Endpoint_SelectedFIFO->Position);
while (Length && BytesInEndpoint)
{
*DataStream = Endpoint_Read_8();
DataStream += 1;
Length--;
}
Endpoint_ClearIN();
}
}
return ENDPOINT_RWCSTREAM_NoError;
}`
I am not sure if this approach is OK and does not have side effects.
Is this Issue known and what would be the appropriate solution for now?