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

stmhal/usbd_cdc_interface: Increase in-endpoint timeout to 500ms.

The previous timeout value of 150ms could lead to data being lost (ie never
received by the host) in some rare cases, eg when the host is under load.
A value of 500ms is quite conservative and allows the host plenty of time
to read our data.
parent 2908c3ca
No related branches found
No related tags found
No related merge requests found
...@@ -261,8 +261,10 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) { ...@@ -261,8 +261,10 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
if (UserTxBufPtrOut != UserTxBufPtrOutShadow) { if (UserTxBufPtrOut != UserTxBufPtrOutShadow) {
// We have sent data and are waiting for the low-level USB driver to // We have sent data and are waiting for the low-level USB driver to
// finish sending it over the USB in-endpoint. // finish sending it over the USB in-endpoint.
// SOF occurs every 1ms, so we have a 150 * 1ms = 150ms timeout // SOF occurs every 1ms, so we have a 500 * 1ms = 500ms timeout
if (UserTxBufPtrWaitCount < 150) { // We have a relatively large timeout because the USB host may be busy
// doing other things and we must give it a chance to read our data.
if (UserTxBufPtrWaitCount < 500) {
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
if (USBx_INEP(CDC_IN_EP & 0x7f)->DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ) { if (USBx_INEP(CDC_IN_EP & 0x7f)->DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ) {
// USB in-endpoint is still reading the data // USB in-endpoint is still reading the data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment