Skip to content

Commit

Permalink
add support for native SAMD HCD
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDeadman committed Apr 4, 2024
1 parent 5738757 commit a5a4251
Show file tree
Hide file tree
Showing 7 changed files with 806 additions and 14 deletions.
16 changes: 14 additions & 2 deletions hw/bsp/samd21/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_Handler(void) {
#if CFG_TUD_ENABLED
tud_int_handler(0);
#endif

#if CFG_TUH_ENABLED && !(defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421)
tuh_int_handler(0);
#endif
}

//--------------------------------------------------------------------+
Expand Down Expand Up @@ -140,8 +146,14 @@ void board_init(void) {
gpio_set_pin_function(PIN_PA19, PINMUX_PA19F_TCC0_WO3);
_gclk_enable_channel(TCC0_GCLK_ID, GCLK_CLKCTRL_GEN_GCLK0_Val);

#if CFG_TUH_ENABLED && defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
max3421_init();
#if CFG_TUH_ENABLED
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
max3421_init();
#else
// VBUS Power
gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_OUT);
gpio_set_pin_level(PIN_PA28, true);
#endif
#endif
}

Expand Down
1 change: 1 addition & 0 deletions hw/bsp/samd21/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function(family_configure_example TARGET RTOS)
family_add_tinyusb(${TARGET} OPT_MCU_SAMD21 ${RTOS})
target_sources(${TARGET}-tinyusb PUBLIC
${TOP}/src/portable/microchip/samd/dcd_samd.c
${TOP}/src/portable/microchip/samd/hcd_samd.c
)
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})

Expand Down
1 change: 1 addition & 0 deletions hw/bsp/samd21/family.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ LDFLAGS_GCC += -specs=nosys.specs -specs=nano.specs

SRC_C += \
src/portable/microchip/samd/dcd_samd.c \
src/portable/microchip/samd/hcd_samd.c \
${SDK_DIR}/gcc/gcc/startup_samd21.c \
${SDK_DIR}/gcc/system_samd21.c \
${SDK_DIR}/hpl/gclk/hpl_gclk.c \
Expand Down
33 changes: 21 additions & 12 deletions hw/bsp/samd51/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,24 @@
//--------------------------------------------------------------------+
// Forward USB interrupt events to TinyUSB IRQ Handler
//--------------------------------------------------------------------+
void USB_0_Handler(void) {
TU_ATTR_ALWAYS_INLINE inline void USB_Any_Handler(void)
{
#if CFG_TUD_ENABLED
tud_int_handler(0);
}
#endif

void USB_1_Handler(void) {
tud_int_handler(0);
#if CFG_TUH_ENABLED && !CFG_TUH_MAX3421
tuh_int_handler(0);
#endif
}

void USB_2_Handler(void) {
tud_int_handler(0);
}
void USB_0_Handler(void) { USB_Any_Handler(); }

void USB_3_Handler(void) {
tud_int_handler(0);
}
void USB_1_Handler(void) { USB_Any_Handler(); }

void USB_2_Handler(void) { USB_Any_Handler(); }

void USB_3_Handler(void) { USB_Any_Handler(); }

//--------------------------------------------------------------------+
// Implementation
Expand Down Expand Up @@ -136,8 +139,14 @@ void board_init(void) {
gpio_set_pin_function(PIN_PA24, PINMUX_PA24H_USB_DM);
gpio_set_pin_function(PIN_PA25, PINMUX_PA25H_USB_DP);

#if CFG_TUH_ENABLED && CFG_TUH_MAX3421
max3421_init();
#if CFG_TUH_ENABLED
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
max3421_init();
#else
// VBUS Power
gpio_set_pin_direction(PIN_PA28, GPIO_DIRECTION_OUT);
gpio_set_pin_level(PIN_PA28, true);
#endif
#endif
}

Expand Down
1 change: 1 addition & 0 deletions hw/bsp/samd51/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function(family_configure_example TARGET RTOS)
family_add_tinyusb(${TARGET} OPT_MCU_SAMD51 ${RTOS})
target_sources(${TARGET}-tinyusb PUBLIC
${TOP}/src/portable/microchip/samd/dcd_samd.c
${TOP}/src/portable/microchip/samd/hcd_samd.c
)
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})

Expand Down
1 change: 1 addition & 0 deletions hw/bsp/samd51/family.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ LDFLAGS_GCC += -specs=nosys.specs -specs=nano.specs

SRC_C += \
src/portable/microchip/samd/dcd_samd.c \
src/portable/microchip/samd/hcd_samd.c \
hw/mcu/microchip/samd51/gcc/gcc/startup_samd51.c \
hw/mcu/microchip/samd51/gcc/system_samd51.c \
hw/mcu/microchip/samd51/hpl/gclk/hpl_gclk.c \
Expand Down

0 comments on commit a5a4251

Please sign in to comment.