Skip to content
Snippets Groups Projects
Commit cce7119a authored by Damien George's avatar Damien George
Browse files

stmhal: Work around crazy bug in USB CDC.

Packets of 64 bytes length are not send to the host until the following
packet is sent.  Fixed by never sending packets of 64 bytes length.
parent 7e5be0b1
No related branches found
No related tags found
No related merge requests found
...@@ -60,7 +60,7 @@ static uint16_t UserRxBufLen = 0; // counts number of valid characters in UserRx ...@@ -60,7 +60,7 @@ static uint16_t UserRxBufLen = 0; // counts number of valid characters in UserRx
static uint8_t UserTxBuffer[APP_TX_DATA_SIZE]; // data for USB IN endpoind is stored in this buffer static uint8_t UserTxBuffer[APP_TX_DATA_SIZE]; // data for USB IN endpoind is stored in this buffer
static uint16_t UserTxBufPtrIn = 0; // increment this pointer modulo APP_TX_DATA_SIZE when new data is available static uint16_t UserTxBufPtrIn = 0; // increment this pointer modulo APP_TX_DATA_SIZE when new data is available
static uint16_t UserTxBufPtrOut = 0; // increment this pointer modulo APP_TX_DATA_SIZE when data is drained static __IO uint16_t UserTxBufPtrOut = 0; // increment this pointer modulo APP_TX_DATA_SIZE when data is drained
static int user_interrupt_char = VCP_CHAR_NONE; static int user_interrupt_char = VCP_CHAR_NONE;
static void *user_interrupt_data = NULL; static void *user_interrupt_data = NULL;
...@@ -266,6 +266,14 @@ void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void) { ...@@ -266,6 +266,14 @@ void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void) {
buffptr = UserTxBufPtrOut; buffptr = UserTxBufPtrOut;
// dpgeorge: For some reason that I don't understand, a packet size of 64 bytes
// (CDC_DATA_FS_MAX_PACKET_SIZE) does not get through to the USB host until the
// next packet is sent. To work around this, we just make sure that we never
// send a packet 64 bytes in length.
if (buffsize == CDC_DATA_FS_MAX_PACKET_SIZE) {
buffsize -= 1;
}
USBD_CDC_SetTxBuffer(&hUSBDDevice, (uint8_t*)&UserTxBuffer[buffptr], buffsize); USBD_CDC_SetTxBuffer(&hUSBDDevice, (uint8_t*)&UserTxBuffer[buffptr], buffsize);
if(USBD_CDC_TransmitPacket(&hUSBDDevice) == USBD_OK) if(USBD_CDC_TransmitPacket(&hUSBDDevice) == USBD_OK)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment