summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-04-04 15:18:58 +1000
committerDamien George <damien.p.george@gmail.com>2017-04-04 15:18:58 +1000
commit9a8e7f7a8e93e9319d2ff5795f4b8a6b9e4ba5ad (patch)
tree7c5c3d3110c91a199b7bcbd10853695376b00b64
parent2908c3ca4168f963958e4a97e54800667ff34ccf (diff)
downloadmicropython-9a8e7f7a8e93e9319d2ff5795f4b8a6b9e4ba5ad.tar.gz
micropython-9a8e7f7a8e93e9319d2ff5795f4b8a6b9e4ba5ad.zip
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.
-rw-r--r--stmhal/usbd_cdc_interface.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/stmhal/usbd_cdc_interface.c b/stmhal/usbd_cdc_interface.c
index 1c12cdc1c8..647fe09e99 100644
--- a/stmhal/usbd_cdc_interface.c
+++ b/stmhal/usbd_cdc_interface.c
@@ -261,8 +261,10 @@ void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
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.
- // SOF occurs every 1ms, so we have a 150 * 1ms = 150ms timeout
- if (UserTxBufPtrWaitCount < 150) {
+ // SOF occurs every 1ms, so we have a 500 * 1ms = 500ms timeout
+ // 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;
if (USBx_INEP(CDC_IN_EP & 0x7f)->DIEPTSIZ & USB_OTG_DIEPTSIZ_XFRSIZ) {
// USB in-endpoint is still reading the data