Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.2k
shared/tinyusb: Use device event hook to schedule USB task.#17338
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Conversation
codecovbot commentedMay 22, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@## master #17338 +/- ##======================================= Coverage 98.54% 98.54% ======================================= Files 169 169 Lines 21898 21898 ======================================= Hits 21579 21579 Misses 319 319 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code size report:
|
andrewleech left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Very nice find@projectgus ! That's much cleaner.
I do see thatqueue_event()
/tud_event_hook_cb()
is called from a number of places in the ISR for different types of events, my initial thought was maybe we only want to trigger on some events or prevent repeat calls if there are multiple events in one ISR.
But now I've confirmed that's not an issue, this new hook is queing up the usb task in the c-scheduler which has built in protection against re-scheduling of the same node, subsequent schedules are just ignored if it's already queued to be run (py/scheduler.c
->mp_sched_schedule_node()
)
Tested on ARDUINO_NANO_33_BLE_SENSE with the following: >>>importtime>>>print('test');time.sleep(1)test>>> Prior to this PR, the "test" output would not appear until after the 1 second elapsed. With this PR it now works properly, "test" is printed immediately, and then it waits 1 second before the prompt appears. Great work@projectgus getting this hook merged to TinyUSB! |
Could we now get rid of |
71b180b
to6de46d1
Compareprojectgus commentedMay 23, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Oh, good catch! Have taken it out as well.
Huh, that's good! I see the nrf port of TinyUSB sometimes calls |
Previously MicroPython ports would linker-wrap dcd_event_handlerin order to schedule the USB task callback to run when needed.TinyUSB 0.16 added proper support for an event hook to do thesame thing without the hacky linker wrapping.This work was funded through GitHub Sponsors.Signed-off-by: Angus Gratton <angus@redyak.com.au>
This reverts commit62e0fa0.Reverting as the only linker wrap needed for nrf port was removedin the parent commit.This work was funded through GitHub Sponsors.Signed-off-by: Angus Gratton <angus@redyak.com.au>
6de46d1
toda7017f
ComparePushed one more small tweak, can remove the dcd.h include line from mp_usbd.c |
Very good! |
@dpgeorge I tried to replicate your test with |
Uh oh!
There was an error while loading.Please reload this page.
Summary
Previously MicroPython ports would linker-wrap dcd_event_handler in order to schedule the USB task callback to run when needed.
TinyUSB 0.16 added proper support for an event hook to do the same thing without the hacky linker wrapping. (Seehathach/tinyusb#2303)
(The vendored TinyUSB is 0.17.0 since09fa90e, the version in ESP-IDF is 0.18.0 for both ESP-IDF V5.2 and V5.4.1.)
As a bonus:
This work was funded through GitHub Sponsors.
Testing
RPI_PICO
andESP32_GENERIC_S3
boards, interacted with the default REPL, and also ran theusb/device/mouse
example on both boards.