diff --git a/src/main/drivers/serial_usb_vcp.c b/src/main/drivers/serial_usb_vcp.c index f225dd62b..61b397996 100644 --- a/src/main/drivers/serial_usb_vcp.c +++ b/src/main/drivers/serial_usb_vcp.c @@ -90,7 +90,6 @@ static void usbVcpWriteBuf(serialPort_t *instance, void *data, int count) { UNUSED(instance); - if (!(usbIsConnected() && usbIsConfigured())) { return; } @@ -120,12 +119,12 @@ static bool usbVcpFlush(vcpPort_t *port) return false; } - uint32_t txed; + uint8_t txed = 0; uint32_t start = millis(); do { - txed = CDC_Send_DATA(port->txBuf, count); - } while (txed != count && (millis() - start < USB_TIMEOUT)); + txed += CDC_Send_DATA(&port->txBuf[txed], count-txed); + } while (txed < count && (millis() - start < USB_TIMEOUT)); return txed == count; } diff --git a/src/main/vcpf4/usbd_cdc_vcp.c b/src/main/vcpf4/usbd_cdc_vcp.c index f312e4a34..879b2edc6 100644 --- a/src/main/vcpf4/usbd_cdc_vcp.c +++ b/src/main/vcpf4/usbd_cdc_vcp.c @@ -166,7 +166,7 @@ uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength) * this function. * @param Buf: Buffer of data to be sent * @param Len: Number of data to be sent (in bytes) - * @retval Result of the opeartion: USBD_OK if all operations are OK else VCP_FAIL + * @retval Result of the operation: USBD_OK if all operations are OK else VCP_FAIL */ static uint16_t VCP_DataTx(uint8_t* Buf, uint32_t Len) { @@ -191,18 +191,17 @@ uint8_t usbAvailable(void) *******************************************************************************/ uint32_t CDC_Receive_DATA(uint8_t* recvBuf, uint32_t len) { - uint32_t ch = 0; + uint32_t count = 0; - while (usbAvailable() && ch < len) { - recvBuf[ch] = usbData.buffer[usbData.bufferOutPosition]; + while (usbAvailable() && count < len) { + recvBuf[count] = usbData.buffer[usbData.bufferOutPosition]; usbData.bufferOutPosition = (usbData.bufferOutPosition + 1) % USB_RX_BUFSIZE; - ch++; + count++; receiveLength--; } - return ch; + return count; } - /** * @brief VCP_DataRx * Data received over USB OUT endpoint are sent over CDC interface