Skip to content

Commit 22f1d76

Browse files
projectgusdpgeorge
authored andcommitted
shared/tinyusb: Use device event hook to schedule USB task.
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. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent 49f81d5 commit 22f1d76

File tree

7 files changed

+2
-30
lines changed

7 files changed

+2
-30
lines changed

ports/alif/alif.mk

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ CFLAGS += -Wl,-T$(BUILD)/ensemble.ld \
103103
-Wl,--print-memory-usage \
104104
-Wl,--no-warn-rwx-segment
105105

106-
ifeq ($(MCU_CORE),M55_HP)
107-
CFLAGS += -Wl,--wrap=dcd_event_handler
108-
endif
109-
110106
################################################################################
111107
# Source files and libraries
112108

ports/esp32/esp32_common.cmake

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ if(MICROPY_PY_TINYUSB)
9797
list(APPEND MICROPY_INC_TINYUSB
9898
${MICROPY_DIR}/shared/tinyusb/
9999
)
100-
101-
list(APPEND MICROPY_LINK_TINYUSB
102-
-Wl,--wrap=dcd_event_handler
103-
)
104100
endif()
105101

106102
list(APPEND MICROPY_SOURCE_PORT
@@ -261,10 +257,6 @@ target_compile_options(${MICROPY_TARGET} PUBLIC
261257
-Wno-missing-field-initializers
262258
)
263259

264-
target_link_options(${MICROPY_TARGET} PUBLIC
265-
${MICROPY_LINK_TINYUSB}
266-
)
267-
268260
# Additional include directories needed for private NimBLE headers.
269261
target_include_directories(${MICROPY_TARGET} PUBLIC
270262
${IDF_PATH}/components/bt/host/nimble/nimble

ports/nrf/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ SRC_C += $(addprefix lib/tinyusb/src/,\
268268
portable/nordic/nrf5x/dcd_nrf5x.c \
269269
)
270270

271-
LDFLAGS += -Wl,--wrap=dcd_event_handler
272271
endif
273272

274273
DRIVERS_SRC_C += $(addprefix modules/,\

ports/renesas-ra/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ LIBSTDCPP_FILE_NAME = "$(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a)"
157157
LDFLAGS += -L"$(shell dirname $(LIBSTDCPP_FILE_NAME))"
158158
endif
159159

160-
# Hook tinyusb USB interrupt if used to service usb task.
161-
LDFLAGS += --wrap=dcd_event_handler
162-
163160
# Options for mpy-cross
164161
MPY_CROSS_FLAGS += -march=armv7m
165162

ports/rp2/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ target_compile_options(${MICROPY_TARGET} PRIVATE
525525

526526
target_link_options(${MICROPY_TARGET} PRIVATE
527527
-Wl,--defsym=__micropy_c_heap_size__=${MICROPY_C_HEAP_SIZE}
528-
-Wl,--wrap=dcd_event_handler
529528
-Wl,--wrap=runtime_init_clocks
530529
)
531530

ports/samd/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ LIBSTDCPP_FILE_NAME = "$(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a)"
113113
LDFLAGS += -L"$(shell dirname $(LIBSTDCPP_FILE_NAME))"
114114
endif
115115

116-
LDFLAGS += --wrap=dcd_event_handler
117-
118116
MPY_CROSS_FLAGS += -march=$(MPY_CROSS_MCU_ARCH)
119117

120118
SRC_C += \

shared/tinyusb/mp_usbd.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030

3131
#include "mp_usbd.h"
3232

33-
#ifndef NO_QSTR
34-
#include "device/dcd.h"
35-
#endif
36-
3733
#if !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
3834

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

4844
#endif // !MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
4945

50-
extern void __real_dcd_event_handler(dcd_event_t const *event, bool in_isr);
51-
52-
// If -Wl,--wrap=dcd_event_handler is passed to the linker, then this wrapper
53-
// will be called and allows MicroPython to schedule the TinyUSB task when
54-
// dcd_event_handler() is called from an ISR.
55-
TU_ATTR_FAST_FUNC void __wrap_dcd_event_handler(dcd_event_t const *event, bool in_isr) {
56-
__real_dcd_event_handler(event, in_isr);
46+
// Schedule the TinyUSB task on demand, when there is a new USB device event
47+
TU_ATTR_FAST_FUNC void tud_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr) {
5748
mp_usbd_schedule_task();
5849
mp_hal_wake_main_task_from_isr();
5950
}

0 commit comments

Comments
 (0)