8000 shared/tinyusb: Use device event hook to schedule USB task. by projectgus · Pull Request #17338 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions ports/alif/alif.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ CFLAGS += -Wl,-T$(BUILD)/ensemble.ld \
-Wl,--print-memory-usage \
-Wl,--no-warn-rwx-segment

ifeq ($(MCU_CORE),M55_HP)
CFLAGS += -Wl,--wrap=dcd_event_handler
endif

################################################################################
# Source files and libraries

Expand Down
8 changes: 0 additions & 8 deletions ports/esp32/esp32_common.cmake
8000
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ if(MICROPY_PY_TINYUSB)
list(APPEND MICROPY_INC_TINYUSB
${MICROPY_DIR}/shared/tinyusb/
)

list(APPEND MICROPY_LINK_TINYUSB
-Wl,--wrap=dcd_event_handler
)
endif()

list(APPEND MICROPY_SOURCE_PORT
Expand Down Expand Up @@ -261,10 +257,6 @@ target_compile_options(${MICROPY_TARGET} PUBLIC
-Wno-missing-field-initializers
)

target_link_options(${MICROPY_TARGET} PUBLIC
${MICROPY_LINK_TINYUSB}
)

# Additional include directories needed for private NimBLE headers.
target_include_directories(${MICROPY_TARGET} PUBLIC
${IDF_PATH}/components/bt/host/nimble/nimble
Expand Down
8 changes: 0 additions & 8 deletions ports/nrf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,7 @@ CFLAGS_MCU_m4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-s

CFLAGS_MCU_m0 = $(CFLAGS_CORTEX_M) -fshort-enums -mtune=cortex-m0 -mcpu=cortex-m0 -mfloat-abi=soft

# linker wrap does not work with lto on older gcc/binutils: https://sourceware.org/bugzilla/show_bug.cgi?id=24406
GCC_VERSION = $(shell arm-none-eabi-gcc -dumpversion)
GCC_MAJOR_VERS = $(word 1,$(subst ., ,$(GCC_VERSION)))
ifeq ($(shell test $(GCC_MAJOR_VERS) -ge 10; echo $$?),0)
LTO ?= 1
else
LTO ?= 0
endif

ifeq ($(LTO),1)
CFLAGS += -flto
Expand Down Expand Up @@ -268,7 +261,6 @@ SRC_C += $(addprefix lib/tinyusb/src/,\
portable/nordic/nrf5x/dcd_nrf5x.c \
)

LDFLAGS += -Wl,--wrap=dcd_event_handler
endif

DRIVERS_SRC_C += $(addprefix modules/,\
Expand Down
3 changes: 0 additions & 3 deletions ports/renesas-ra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ LIBSTDCPP_FILE_NAME = "$(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a)"
LDFLAGS += -L"$(shell dirname $(LIBSTDCPP_FILE_NAME))"
endif

# Hook tinyusb USB interrupt if used to service usb task.
LDFLAGS += --wrap=dcd_event_handler

# Options for mpy-cross
MPY_CROSS_FLAGS += -march=armv7m

Expand Down
1 change: 0 additions & 1 deletion ports/rp2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ target_compile_options(${MICROPY_TARGET} PRIVATE

target_link_options(${MICROPY_TARGET} PRIVATE
-Wl,--defsym=__micropy_c_heap_size__=${MICROPY_C_HEAP_SIZE}
-Wl,--wrap=dcd_event_handler
-Wl,--wrap=runtime_init_clocks
)

Expand Down
2 changes: 0 additions & 2 deletions ports/samd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ LIBSTDCPP_FILE_NAME = "$(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a)"
LDFLAGS += -L"$(shell dirname $(LIBSTDCPP_FILE_NAME))"
endif

LDFLAGS += --wrap=dcd_event_handler

MPY_CROSS_FLAGS += -march=$(MPY_CROSS_MCU_ARCH)

SRC_C += \
Expand Down
13 changes: 2 additions & 11 deletions shared/tinyusb/mp_usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@

#include "mp_usbd.h"

#ifndef NO_QSTR
#include "device/dcd.h"
#endif

#if !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE

void mp_usbd_task(void) {
Expand All @@ -47,13 +43,8 @@ void mp_usbd_task_callback(mp_sched_node_t *node) {

#endif // !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE

extern void __real_dcd_event_handler(dcd_event_t const *event, bool in_isr);

// If -Wl,--wrap=dcd_event_handler is passed to the linker, then this wrapper
// will be called and allows MicroPython to schedule the TinyUSB task when
// dcd_event_handler() is called from an ISR.
TU_ATTR_FAST_FUNC void __wrap_dcd_event_handler(dcd_event_t const *event, bool in_isr) {
__real_dcd_event_handler(event, in_isr);
// Schedule the TinyUSB task on demand, when there is a new USB device event
TU_ATTR_FAST_FUNC void tud_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr) {
mp_usbd_schedule_task();
mp_hal_wake_main_task_from_isr();
}
Expand Down
Loading
0