summaryrefslogtreecommitdiff
path: root/stmhal/usbd_cdc_interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'stmhal/usbd_cdc_interface.c')
-rw-r--r--stmhal/usbd_cdc_interface.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/stmhal/usbd_cdc_interface.c b/stmhal/usbd_cdc_interface.c
index 61553e27d..801bcb753 100644
--- a/stmhal/usbd_cdc_interface.c
+++ b/stmhal/usbd_cdc_interface.c
@@ -257,12 +257,10 @@ static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t* pbuf, uint16_t length) {
return USBD_OK;
}
-/**
- * @brief TIM period elapsed callback
- * @param htim: TIM handle
- * @retval None
- */
-void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void) {
+// This function is called to process outgoing data. We hook directly into the
+// SOF (start of frame) callback so that it is called exactly at the time it is
+// needed (reducing latency), and often enough (increasing bandwidth).
+void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
if (!dev_is_connected) {
// CDC device is not connected to a host, so we are unable to send any data
return;
@@ -276,9 +274,8 @@ void USBD_CDC_HAL_TIM_PeriodElapsedCallback(void) {
if (UserTxBufPtrOut != UserTxBufPtrOutShadow) {
// We have sent data and are waiting for the low-level USB driver to
// finish sending it over the USB in-endpoint.
- // We have a 15 * 10ms = 150ms timeout
- if (UserTxBufPtrWaitCount < 15) {
- PCD_HandleTypeDef *hpcd = hUSBDDevice.pData;
+ // SOF occurs every 1ms, so we have a 150 * 1ms = 150ms timeout
+ if (UserTxBufPtrWaitCount < 150) {
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
if (USBx_INEP(CDC_IN_EP & 0x7f)->DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ) {
// USB in-endpoint is still reading the data
@@ -457,7 +454,7 @@ void USBD_CDC_TxAlways(const uint8_t *buf, uint32_t len) {
}
// Some unused code that makes sure the low-level USB buffer is drained.
- // Waiting for low-level is handled in USBD_CDC_HAL_TIM_PeriodElapsedCallback.
+ // Waiting for low-level is handled in HAL_PCD_SOFCallback.
/*
start = HAL_GetTick();
PCD_HandleTypeDef *hpcd = hUSBDDevice.pData;