mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 13:01:10 +02:00
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 <angus@redyak.com.au>
This commit is contained in:
committed by
Damien George
parent
49f81d5046
commit
22f1d76633
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
@@ -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
|
||||
|
@@ -268,7 +268,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/,\
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
)
|
||||
|
||||
|
@@ -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 += \
|
||||
|
@@ -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) {
|
||||
@@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user