Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
projectgus wants to merge2 commits intomicropython:master
base:master
Choose a base branch
Loading
fromprojectgus:refactor/tinyusb_event_hook

Conversation

projectgus
Copy link
Contributor

@projectgusprojectgus commentedMay 22, 2025
edited
Loading

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

  • BuiltRPI_PICO andESP32_GENERIC_S3 boards, interacted with the default REPL, and also ran theusb/device/mouse example on both boards.

@projectgusprojectgus added the sharedRelates to shared/ directory in source labelMay 22, 2025
@codecovCodecov
Copy link

codecovbot commentedMay 22, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base(dc1af38) to head(da7017f).
Report is 1 commits behind head on master.

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.
📢 Have feedback on the report?Share it here.

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actionsGitHub Actions
Copy link

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:   -24 -0.003% RPI_PICO_W       samd:   -16 -0.006% ADAFRUIT_ITSYBITSY_M4_EXPRESS  qemu rv32:    +0 +0.000% VIRT_RV32

Copy link
Contributor

@andrewleechandrewleech left a comment
edited
Loading

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())

@dpgeorge
Copy link
Member

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!

@dpgeorge
Copy link
Member

Could we now get rid ofMICROPY_LINK_TINYUSB inports/esp32/esp32_common.cmake?

@projectgusprojectgusforce-pushed therefactor/tinyusb_event_hook branch from71b180b to6de46d1CompareMay 23, 2025 04:05
@projectgus
Copy link
ContributorAuthor

projectgus commentedMay 23, 2025
edited
Loading

Could we now get rid of MICROPY_LINK_TINYUSB in ports/esp32/esp32_common.cmake?

Oh, good catch! Have taken it out as well.

Prior to this PR, the "test" output would not appear until after the 1 second elapsed. With this PR it now works properly,

Huh, that's good! I see the nrf port of TinyUSB sometimes callsusb_defer_func() to defer an ISR callback, and this invokes the new hook function as well (previously it would have bypasseddcd_event_handler)

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>
@projectgusprojectgusforce-pushed therefactor/tinyusb_event_hook branch from6de46d1 toda7017fCompareMay 23, 2025 04:11
@projectgus
Copy link
ContributorAuthor

Pushed one more small tweak, can remove the dcd.h include line from mp_usbd.c

@dpgeorge
Copy link
Member

can remove the dcd.h include line from mp_usbd.c

Very good!

@robert-hh
Copy link
Contributor

@dpgeorge I tried to replicate your test withprint('test');time.sleep(1) by fetching the actual PR and building it. It still prints "test" after one second. Did you update the tinyusb lib?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@andrewleechandrewleechandrewleech approved these changes

@dpgeorgedpgeorgedpgeorge approved these changes

Assignees
No one assigned
Labels
sharedRelates to shared/ directory in source
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@projectgus@dpgeorge@robert-hh@andrewleech

[8]ページ先頭

©2009-2025 Movatter.jp