From 6380d057f8911f5d09bdffff4220aa9602df49e2 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Fri, 17 Apr 2009 04:10:30 +0000 Subject: Fixed CDC and USBtoSerial demos freezing where buffers were full while still transmitting or receiving (thanks to Peter Hand). --- Demos/Device/CDC/CDC.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'Demos/Device/CDC') diff --git a/Demos/Device/CDC/CDC.c b/Demos/Device/CDC/CDC.c index 3dc624057..29bc00373 100644 --- a/Demos/Device/CDC/CDC.c +++ b/Demos/Device/CDC/CDC.c @@ -300,14 +300,22 @@ TASK(CDC_Task) /* Write the String to the Endpoint */ Endpoint_Write_Stream_LE(ReportString, strlen(ReportString)); + /* Remember if the packet to send completely fills the endpoint */ + bool IsFull = (Endpoint_BytesInEndpoint() == CDC_TXRX_EPSIZE); + /* Finalize the stream transfer to send the last packet */ Endpoint_ClearIN(); - /* Wait until the endpoint is ready for another packet */ - while (!(Endpoint_IsINReady())); - - /* Send an empty packet to ensure that the host does not buffer data sent to it */ - Endpoint_ClearIN(); + /* If the last packet filled the endpoint, send an empty packet to release the buffer on + * the receiver (otherwise all data will be cached until a non-full packet is received) */ + if (IsFull) + { + /* Wait until the endpoint is ready for another packet */ + while (!(Endpoint_IsINReady())); + + /* Send an empty packet to ensure that the host does not buffer data sent to it */ + Endpoint_ClearIN(); + } } /* Select the Serial Rx Endpoint */ -- cgit v1.2.3