Skip to content

Commit

Permalink
samd: Switch TinyUSB to run via a scheduled task.
Browse files Browse the repository at this point in the history
Previously the TinyUSB task was run in the ISR immediately after the
interrupt handler.  This approach gives very similar performance (no change
in CDC throughput tests) but reduces the amount of time spent in the ISR,
and allows TinyUSB callbacks to run in thread mode.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
  • Loading branch information
projectgus authored and dpgeorge committed Nov 9, 2023
1 parent bcbdee2 commit 26d5032
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 35 deletions.
3 changes: 3 additions & 0 deletions ports/samd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ 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 Expand Up @@ -131,6 +133,7 @@ SHARED_SRC_C += \
shared/runtime/sys_stdio_mphal.c \
shared/timeutils/timeutils.c \
shared/tinyusb/mp_cdc_common.c \
shared/tinyusb/mp_usbd.c

ASF4_SRC_C += $(addprefix lib/asf4/$(MCU_SERIES_LOWER)/,\
hal/src/hal_atomic.c \
Expand Down
8 changes: 4 additions & 4 deletions ports/samd/samd_isr.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ const ISR isr_vector[] __attribute__((section(".isr_vector"))) = {
&Sercom7_Handler, // 77 Serial Communication Interface 7 (SERCOM7): SERCOM7_3 - 6
0, // 78 Control Area Network 0 (CAN0)
0, // 79 Control Area Network 1 (CAN1)
&USB_0_Handler_wrapper, // 80 Universal Serial Bus (USB): USB_EORSM_DNRS, ...
&USB_1_Handler_wrapper, // 81 Universal Serial Bus (USB): USB_SOF_HSOF
&USB_2_Handler_wrapper, // 82 Universal Serial Bus (USB): USB_TRCPT0_0 - _7
&USB_3_Handler_wrapper, // 83 Universal Serial Bus (USB): USB_TRCPT1_0 - _7
&USB_Handler_wrapper, // 80 Universal Serial Bus (USB): USB_EORSM_DNRS, ...
&USB_Handler_wrapper, // 81 Universal Serial Bus (USB): USB_SOF_HSOF
&USB_Handler_wrapper, // 82 Universal Serial Bus (USB): USB_TRCPT0_0 - _7
&USB_Handler_wrapper, // 83 Universal Serial Bus (USB): USB_TRCPT1_0 - _7
0, // 84 Ethernet MAC (GMAC)
0, // 85 Timer Counter Control 0 (TCC0): TCC0_CNT_A ...
0, // 86 Timer Counter Control 0 (TCC0): TCC0_MC_0
Expand Down
4 changes: 0 additions & 4 deletions ports/samd/samd_soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ void samd_init(void);
void samd_main(void);

void USB_Handler_wrapper(void);
void USB_0_Handler_wrapper(void);
void USB_1_Handler_wrapper(void);
void USB_2_Handler_wrapper(void);
void USB_3_Handler_wrapper(void);

void sercom_enable(Sercom *spi, int state);
void sercom_register_irq(int sercom_id, void (*sercom_irq_handler));
Expand Down
27 changes: 0 additions & 27 deletions ports/samd/tusb_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,33 +117,6 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
return desc_str;
}

#if defined(MCU_SAMD21)

void USB_Handler_wrapper(void) {
tud_int_handler(0);
tud_task();
}

#elif defined(MCU_SAMD51)

void USB_0_Handler_wrapper(void) {
tud_int_handler(0);
tud_task();
}

void USB_1_Handler_wrapper(void) {
tud_int_handler(0);
tud_task();
}

void USB_2_Handler_wrapper(void) {
tud_int_handler(0);
tud_task();
}

void USB_3_Handler_wrapper(void) {
tud_int_handler(0);
tud_task();
}

#endif

0 comments on commit 26d5032

Please sign in to comment.