mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/tinyusb: add SAM0-based MCU support
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
This commit is contained in:
parent
429ee839cc
commit
35b5e2556e
@ -71,6 +71,9 @@ tinyusb_host:
|
||||
tinyusb_portable_espressif:
|
||||
$(QQ)"$(MAKE)" -C $(PSRC)/portable/espressif/esp32sx -f $(RIOTBASE)/Makefile.base MODULE=$@
|
||||
|
||||
tinyusb_portable_microchip:
|
||||
$(QQ)"$(MAKE)" -C $(PSRC)/portable/microchip/samd -f $(RIOTBASE)/Makefile.base MODULE=$@
|
||||
|
||||
tinyusb_portable_stm32_fsdev:
|
||||
$(QQ)"$(MAKE)" -C $(PSRC)/portable/st/stm32_fsdev -f $(RIOTBASE)/Makefile.base MODULE=$@
|
||||
|
||||
|
@ -54,6 +54,8 @@ endif
|
||||
# tinyUSB hardware driver selection
|
||||
ifneq (,$(filter esp32s2 esp32s3,$(CPU_FAM)))
|
||||
USEMODULE += tinyusb_portable_espressif
|
||||
else ifneq (,$(filter saml21 samd5x samd21,$(CPU)))
|
||||
USEMODULE += tinyusb_portable_microchip
|
||||
else ifeq (stm32,$(CPU))
|
||||
ifneq (,$(filter f2 f4 f7 h7 l4,$(CPU_FAM)))
|
||||
USEMODULE += tinyusb_portable_synopsys_dwc2
|
||||
|
@ -12,6 +12,12 @@ else ifeq (esp32s3,$(CPU_FAM))
|
||||
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S3
|
||||
else ifeq (stm32,$(CPU))
|
||||
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_STM32$(call uppercase_and_underscore,$(CPU_FAM))
|
||||
else ifeq (saml21,$(CPU))
|
||||
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAML21
|
||||
else ifeq (samd21,$(CPU))
|
||||
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAMD21
|
||||
else ifeq (samd5x,$(CPU))
|
||||
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAME5X
|
||||
else
|
||||
$(error CPU $(CPU) or CPU family $(CPU_FAM) not supported)
|
||||
endif
|
||||
|
@ -1,5 +1,9 @@
|
||||
MODULE = tinyusb_hw
|
||||
|
||||
SRC = hw_$(CPU).c
|
||||
ifneq (,$(filter saml21 samd5x samd21,$(CPU)))
|
||||
SRC = hw_sam0.c
|
||||
else
|
||||
SRC = hw_$(CPU).c
|
||||
endif
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
||||
|
91
pkg/tinyusb/hw/hw_sam0.c
Normal file
91
pkg/tinyusb/hw/hw_sam0.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Mesotic SAS
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup pkg_tinyusb
|
||||
* @brief
|
||||
* @{
|
||||
*
|
||||
* @brief tinyUSB hardware driver for SAM0 MCUs
|
||||
* @author Dylan Laduranty <dylan.laduranty@mesotic.com>
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "periph_conf.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "pm_layered.h"
|
||||
#include "log.h"
|
||||
#include "tusb.h"
|
||||
#include "device/usbd.h"
|
||||
#include "host/usbh.h"
|
||||
|
||||
int tinyusb_hw_init(void)
|
||||
{
|
||||
/* Initialize GPIO pins */
|
||||
gpio_init(sam_usbdev_config[0].dp, GPIO_IN);
|
||||
gpio_init(sam_usbdev_config[0].dm, GPIO_IN);
|
||||
gpio_init_mux(sam_usbdev_config[0].dm, sam_usbdev_config[0].d_mux);
|
||||
gpio_init_mux(sam_usbdev_config[0].dp, sam_usbdev_config[0].d_mux);
|
||||
|
||||
/* Initialize clocks */
|
||||
sam0_gclk_enable(sam_usbdev_config[0].gclk_src);
|
||||
|
||||
#if defined(MCLK)
|
||||
MCLK->AHBMASK.reg |= MCLK_AHBMASK_USB;
|
||||
MCLK->APBBMASK.reg |= MCLK_APBBMASK_USB;
|
||||
#else
|
||||
PM->AHBMASK.reg |= PM_AHBMASK_USB;
|
||||
PM->APBBMASK.reg |= PM_APBBMASK_USB;
|
||||
#endif
|
||||
|
||||
#if defined(CPU_COMMON_SAMD21)
|
||||
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_CLKEN
|
||||
| GCLK_CLKCTRL_GEN(sam_usbdev_config[0].gclk_src)
|
||||
| GCLK_CLKCTRL_ID(USB_GCLK_ID);
|
||||
pm_block(SAMD21_PM_IDLE_1);
|
||||
#else
|
||||
GCLK->PCHCTRL[USB_GCLK_ID].reg = GCLK_PCHCTRL_CHEN
|
||||
| GCLK_PCHCTRL_GEN(sam_usbdev_config[0].gclk_src);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void isr_usb(void)
|
||||
{
|
||||
/* call device interrupt handler with the first device */
|
||||
if (IS_USED(MODULE_TINYUSB_DEVICE)) {
|
||||
tud_int_handler(TINYUSB_TUD_RHPORT);
|
||||
}
|
||||
|
||||
/* call host interrupt handler with the first device */
|
||||
if (IS_USED(MODULE_TINYUSB_HOST)) {
|
||||
tuh_int_handler(TINYUSB_TUH_RHPORT);
|
||||
}
|
||||
|
||||
cortexm_isr_end();
|
||||
}
|
||||
|
||||
void isr_usb0(void)
|
||||
{
|
||||
isr_usb();
|
||||
}
|
||||
|
||||
void isr_usb1(void)
|
||||
{
|
||||
isr_usb();
|
||||
}
|
||||
void isr_usb2(void)
|
||||
{
|
||||
isr_usb();
|
||||
}
|
||||
void isr_usb3(void)
|
||||
{
|
||||
isr_usb();
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user