Fix issue with CDC device demos causing broken communications when the device tries to send data before the host has set the line encoding.

pull/1469/head
Dean Camera 16 years ago
parent 5c069f909a
commit eff07bb877

@ -49,6 +49,12 @@ CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600,
.CharFormat = OneStopBit, .CharFormat = OneStopBit,
.ParityType = Parity_None, .ParityType = Parity_None,
.DataBits = 8 }; .DataBits = 8 };
/** Indicates if the host has set the device line encoding. Until the line encoding is set by the host, the device should
* not attempt to send any bytes.
*/
bool LineEncodingSet = false;
#if 0 #if 0
/* NOTE: Here you can set up a standard stream using the created virtual serial port, so that the standard stream functions in /* NOTE: Here you can set up a standard stream using the created virtual serial port, so that the standard stream functions in
@ -59,6 +65,9 @@ static int CDC_putchar(char c, FILE *stream)
{ {
Endpoint_SelectEndpoint(CDC_TX_EPNUM); Endpoint_SelectEndpoint(CDC_TX_EPNUM);
if (!(LineEncodingSet))
return -1;
while (!(Endpoint_IsReadWriteAllowed())) while (!(Endpoint_IsReadWriteAllowed()))
{ {
if (USB_DeviceState != DEVICE_STATE_Configured) if (USB_DeviceState != DEVICE_STATE_Configured)
@ -74,7 +83,10 @@ static int CDC_putchar(char c, FILE *stream)
static int CDC_getchar(FILE *stream) static int CDC_getchar(FILE *stream)
{ {
int c; int c;
if (!(LineEncodingSet))
return -1;
Endpoint_SelectEndpoint(CDC_RX_EPNUM); Endpoint_SelectEndpoint(CDC_RX_EPNUM);
for (;;) for (;;)
@ -216,6 +228,9 @@ void EVENT_USB_UnhandledControlPacket(void)
/* Read the line coding data in from the host into the global struct */ /* Read the line coding data in from the host into the global struct */
Endpoint_Read_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t)); Endpoint_Read_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t));
/* Indicate that the line encoding has been set, and the device may now send data */
LineEncodingSet = true;
/* Finalize the stream transfer to clear the last packet from the host */ /* Finalize the stream transfer to clear the last packet from the host */
Endpoint_ClearIN(); Endpoint_ClearIN();
@ -299,7 +314,7 @@ void CDC_Task(void)
{ {
ActionSent = false; ActionSent = false;
} }
else if (ActionSent == false) else if ((ActionSent == false) && LineEncodingSet)
{ {
ActionSent = true; ActionSent = true;

@ -139,16 +139,16 @@ void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
void CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, char* const Data, const uint16_t Length) void CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, char* const Data, const uint16_t Length)
{ {
if (USB_DeviceState != DEVICE_STATE_Configured) if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
return; return;
Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);
Endpoint_Write_Stream_LE(Data, Length, NO_STREAM_CALLBACK); Endpoint_Write_Stream_LE(Data, Length, NO_STREAM_CALLBACK);
} }
void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, const uint8_t Data) void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, const uint8_t Data)
{ {
if (USB_DeviceState != DEVICE_STATE_Configured) if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
return; return;
Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);

@ -58,6 +58,8 @@
* internal control * internal control
* - Interrupts are no longer disabled during the processing of Control Requests on the default endpoint while in device mode * - Interrupts are no longer disabled during the processing of Control Requests on the default endpoint while in device mode
* - AudioOutput demos now always output to board LEDs, regardless of output mode (removed AUDIO_OUT_LEDS project option) * - AudioOutput demos now always output to board LEDs, regardless of output mode (removed AUDIO_OUT_LEDS project option)
* - Removed SINGLE_DEVICE_CONFIGURATION compile time option in favour of the new FIXED_NUM_CONFIGURATIONS option so that the exact number
* of device configurations can be defined statically
* *
* <b>Fixed:</b> * <b>Fixed:</b>
* - Changed bootloaders to use FLASHEND rather than the existence of RAMPZ to determine if far FLASH pointers are needed to fix * - Changed bootloaders to use FLASHEND rather than the existence of RAMPZ to determine if far FLASH pointers are needed to fix

Loading…
Cancel
Save