Skip to content

Commit a5a4251

Browse files
committed
add support for native SAMD HCD
1 parent 5738757 commit a5a4251

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
@@ -94,6 +94,7 @@ function(family_configure_example TARGET RTOS)
9494
family_add_tinyusb(${TARGET} OPT_MCU_SAMD21 ${RTOS})
9595
target_sources(${TARGET}-tinyusb PUBLIC
9696
${TOP}/src/portable/microchip/samd/dcd_samd.c
97+
${TOP}/src/portable/microchip/samd/hcd_samd.c
9798
)
9899
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
99100

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

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ LDFLAGS_GCC += -specs=nosys.specs -specs=nano.specs
2020

2121
SRC_C += \
2222
src/portable/microchip/samd/dcd_samd.c \
23+
src/portable/microchip/samd/hcd_samd.c \
2324
${SDK_DIR}/gcc/gcc/startup_samd21.c \
2425
${SDK_DIR}/gcc/system_samd21.c \
2526
${SDK_DIR}/hpl/gclk/hpl_gclk.c \

Diff for: hw/bsp/samd51/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
@@ -136,8 +139,14 @@ void board_init(void) {
136139
gpio_set_pin_function(PIN_PA24, PINMUX_PA24H_USB_DM);
137140
gpio_set_pin_function(PIN_PA25, PINMUX_PA25H_USB_DP);
138141

139-
#if CFG_TUH_ENABLED && CFG_TUH_MAX3421
140-
max3421_init();
142+
#if CFG_TUH_ENABLED
143+
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
144+
max3421_init();
145+
#else
146+
// VBUS Power
147+
gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_OUT);
148+
gpio_set_pin_level(PIN_PA28, true);
149+
#endif
141150
#endif
142151
}
143152

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

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function(family_configure_example TARGET RTOS)
9393
family_add_tinyusb(${TARGET} OPT_MCU_SAMD51 ${RTOS})
9494
target_sources(${TARGET}-tinyusb PUBLIC
9595
${TOP}/src/portable/microchip/samd/dcd_samd.c
96+
${TOP}/src/portable/microchip/samd/hcd_samd.c
9697
)
9798
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
9899

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

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ LDFLAGS_GCC += -specs=nosys.specs -specs=nano.specs
1616

1717
SRC_C += \
1818
src/portable/microchip/samd/dcd_samd.c \
19+
src/portable/microchip/samd/hcd_samd.c \
1920
hw/mcu/microchip/samd51/gcc/gcc/startup_samd51.c \
2021
hw/mcu/microchip/samd51/gcc/system_samd51.c \
2122
hw/mcu/microchip/samd51/hpl/gclk/hpl_gclk.c \

0 commit comments

Comments
 (0)