Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shared/tinyusb/mp_usbd_cdc: Fix short CDC TX timeouts. #15339

Merged

Conversation

dpgeorge
Copy link
Member

The mp_event_wait_ms() function may return earlier than the requested timeout, and if that happens repeatedly (eg due to lots of USB data and IRQs) then the loop waiting for CDC TX FIFO space to become available may exit much earlier than MICROPY_HW_USB_CDC_TX_TIMEOUT, even when there is no space.

Fix this by using mp_hal_ticks_ms() to compute a more accurate timeout.

The basics/int_big_mul.py test fails on RPI_PICO without this fix.

@dpgeorge dpgeorge added the shared Relates to shared/ directory in source label Jun 24, 2024
@dpgeorge
Copy link
Member Author

@andrewleech @projectgus FYI

Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.42%. Comparing base (0c28a5a) to head (880f7bc).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #15339   +/-   ##
=======================================
  Coverage   98.42%   98.42%           
=======================================
  Files         161      161           
  Lines       21249    21249           
=======================================
  Hits        20915    20915           
  Misses        334      334           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andrewleech
Copy link
Contributor

Ah that makes sense, thanks the fix looks good to me!

Copy link

github-actions bot commented Jun 24, 2024

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:   +16 +0.004% TEENSY40
        rp2:   +64 +0.007% RPI_PICO_W
       samd:   +28 +0.011% ADAFRUIT_ITSYBITSY_M4_EXPRESS

@robert-hh
Copy link
Contributor

I do not know if that was the intention, but it does not change the odd behavior which I brought up in the discussion PR #15158 and to which @projectgus referred in issue #15298.

@andrewleech
Copy link
Contributor

I do not know if that was the intention, but it does not change the odd behavior which I brought up in the discussion PR #15158 and to which @projectgus referred in issue #15298.

No I wouldn't expect this to affect / help with that one.
The fix for that one is still going to be somewhat complicated I feel, likely needing further changes in tinyusb itself to support.

@projectgus
Copy link
Contributor

LGTM!

The `mp_event_wait_ms()` function may return earlier than the requested
timeout, and if that happens repeatedly (eg due to lots of USB data and
IRQs) then the loop waiting for CDC TX FIFO space to become available may
exit much earlier than MICROPY_HW_USB_CDC_TX_TIMEOUT, even when there is
no space.

Fix this by using `mp_hal_ticks_ms()` to compute a more accurate timeout.

The `basics/int_big_mul.py` test fails on RPI_PICO without this fix.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the shared-tinyusb-fix-cdc-tx-timeout branch from 0129368 to 880f7bc Compare June 26, 2024 04:51
@dpgeorge dpgeorge merged commit 880f7bc into micropython:master Jun 26, 2024
56 of 62 checks passed
@dpgeorge dpgeorge deleted the shared-tinyusb-fix-cdc-tx-timeout branch June 26, 2024 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shared Relates to shared/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants