Skip to content

Commit 965e26d

Browse files
committed
add support for native SAMD HCD
1 parent 8b1e40c commit 965e26d

File tree

7 files changed

+806
-14
lines changed

7 files changed

+806
-14
lines changed

Diff for: hw/bsp/samd21/family.c

+14-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@
6060
// Forward USB interrupt events to TinyUSB IRQ Handler
6161
//--------------------------------------------------------------------+
6262
void USB_Handler(void) {
63+
#if CFG_TUD_ENABLED
6364
tud_int_handler(0);
65+
#endif
66+
67+
#if CFG_TUH_ENABLED && !(defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421)
68+
tuh_int_handler(0);
69+
#endif
6470
}
6571

6672
//--------------------------------------------------------------------+
@@ -140,8 +146,14 @@ void board_init(void) {
140146
gpio_set_pin_function(PIN_PA19, PINMUX_PA19F_TCC0_WO3);
141147
_gclk_enable_channel(TCC0_GCLK_ID, GCLK_CLKCTRL_GEN_GCLK0_Val);
142148

143-
#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
144-
max3421_init();
149+
#if CFG_TUH_ENABLED
150+
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
151+
max3421_init();
152+
#else
153+
// VBUS Power
154+
gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_OUT);
155+
gpio_set_pin_level(PIN_PA28, true);
156+
#endif
145157
#endif
146158
}
147159

Diff for: hw/bsp/samd21/family.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function(family_configure_example TARGET RTOS)
9999
family_add_tinyusb(${TARGET} OPT_MCU_SAMD21 ${RTOS})
100100
target_sources(${TARGET}-tinyusb PUBLIC
101101
${TOP}/src/portable/microchip/samd/dcd_samd.c
102+
${TOP}/src/portable/microchip/samd/hcd_samd.c
102103
)
103104
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
104105

Diff for: hw/bsp/samd21/family.mk

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ LDFLAGS_CLANG +=
2323

2424
SRC_C += \
2525
src/portable/microchip/samd/dcd_samd.c \
26+
src/portable/microchip/samd/hcd_samd.c \
2627
${SDK_DIR}/gcc/gcc/startup_samd21.c \
2728
${SDK_DIR}/gcc/system_samd21.c \
2829
${SDK_DIR}/hal/src/hal_atomic.c \

Diff for: hw/bsp/samd5x_e5x/family.c

+21-12
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,24 @@
5656
//--------------------------------------------------------------------+
5757
// Forward USB interrupt events to TinyUSB IRQ Handler
5858
//--------------------------------------------------------------------+
59-
void USB_0_Handler(void) {
59+
TU_ATTR_ALWAYS_INLINE inline void USB_Any_Handler(void)
60+
{
61+
#if CFG_TUD_ENABLED
6062
tud_int_handler(0);
61-
}
63+
#endif
6264

63-
void USB_1_Handler(void) {
64-
tud_int_handler(0);
65+
#if CFG_TUH_ENABLED && !CFG_TUH_MAX3421
66+
tuh_int_handler(0);
67+
#endif
6568
}
6669

67-
void USB_2_Handler(void) {
68-
tud_int_handler(0);
69-
}
70+
void USB_0_Handler(void) { USB_Any_Handler(); }
7071

71-
void USB_3_Handler(void) {
72-
tud_int_handler(0);
73-
}
72+
void USB_1_Handler(void) { USB_Any_Handler(); }
73+
74+
void USB_2_Handler(void) { USB_Any_Handler(); }
75+
76+
void USB_3_Handler(void) { USB_Any_Handler(); }
7477

7578
//--------------------------------------------------------------------+
7679
// Implementation
@@ -138,8 +141,14 @@ void board_init(void) {
138141
gpio_set_pin_function(PIN_PA24, PINMUX_PA24H_USB_DM);
139142
gpio_set_pin_function(PIN_PA25, PINMUX_PA25H_USB_DP);
140143

141-
#if CFG_TUH_ENABLED && CFG_TUH_MAX3421
142-
max3421_init();
144+
#if CFG_TUH_ENABLED
145+
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
146+
max3421_init();
147+
#else
148+
// VBUS Power
149+
gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_OUT);
150+
gpio_set_pin_level(PIN_PA28, true);
151+
#endif
143152
#endif
144153
}
145154

Diff for: hw/bsp/samd5x_e5x/family.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ function(family_configure_example TARGET RTOS)
9696
family_add_tinyusb(${TARGET} OPT_MCU_SAMD51 ${RTOS})
9797
target_sources(${TARGET}-tinyusb PUBLIC
9898
${TOP}/src/portable/microchip/samd/dcd_samd.c
99+
${TOP}/src/portable/microchip/samd/hcd_samd.c
99100
)
100101
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
101102

Diff for: hw/bsp/samd5x_e5x/family.mk

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ LDFLAGS_GCC += \
1818

1919
SRC_C += \
2020
src/portable/microchip/samd/dcd_samd.c \
21+
src/portable/microchip/samd/hcd_samd.c \
2122
${SDK_DIR}/gcc/gcc/startup_${SAM_FAMILY}.c \
2223
${SDK_DIR}/gcc/system_${SAM_FAMILY}.c \
2324
${SDK_DIR}/hpl/gclk/hpl_gclk.c \

0 commit comments

Comments
 (0)