mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/tinyusb: add STM32 FS device support
This commit is contained in:
parent
21956db2fd
commit
e0fb5074a1
@ -30,11 +30,11 @@ menuconfig PACKAGE_TINYUSB
|
||||
select MODULE_TINYUSB_PORTABLE_SYNOPSYS_DWC2 if CPU_STM32 && CPU_FAM_F7
|
||||
select MODULE_TINYUSB_PORTABLE_SYNOPSYS_DWC2 if CPU_STM32 && CPU_FAM_H7
|
||||
select MODULE_TINYUSB_PORTABLE_SYNOPSYS_DWC2 if CPU_STM32 && CPU_FAM_L4
|
||||
select MODULE_TINYUSB_PORTABLE_STM32_FSEDV if CPU_STM32 && CPU_FAM_F0
|
||||
select MODULE_TINYUSB_PORTABLE_STM32_FSEDV if CPU_STM32 && CPU_FAM_F1
|
||||
select MODULE_TINYUSB_PORTABLE_STM32_FSEDV if CPU_STM32 && CPU_FAM_G4
|
||||
select MODULE_TINYUSB_PORTABLE_STM32_FSEDV if CPU_STM32 && CPU_FAM_L0
|
||||
select MODULE_TINYUSB_PORTABLE_STM32_FSEDV if CPU_STM32 && CPU_FAM_WB
|
||||
select MODULE_TINYUSB_PORTABLE_STM32_FSDEV if CPU_STM32 && CPU_FAM_F0
|
||||
select MODULE_TINYUSB_PORTABLE_STM32_FSDEV if CPU_STM32 && CPU_FAM_F1
|
||||
select MODULE_TINYUSB_PORTABLE_STM32_FSDEV if CPU_STM32 && CPU_FAM_G4
|
||||
select MODULE_TINYUSB_PORTABLE_STM32_FSDEV if CPU_STM32 && CPU_FAM_L0
|
||||
select MODULE_TINYUSB_PORTABLE_STM32_FSDEV if CPU_STM32 && CPU_FAM_WB
|
||||
select MODULE_TINYUSB_PORTABLE_MICROCHIP if CPU_FAM_SAMD21 || CPU_FAM_SAMR21 \
|
||||
|| CPU_COMMON_SAMD5X || CPU_FAM_SAML21 || CPU_FAM_SAMR34 \
|
||||
|| CPU_FAM_SAMR30
|
||||
|
@ -58,9 +58,13 @@ else ifneq (,$(filter saml21 samd5x samd21,$(CPU)))
|
||||
USEMODULE += tinyusb_portable_microchip
|
||||
else ifeq (stm32,$(CPU))
|
||||
ifneq (,$(filter f2 f4 f7 h7 l4,$(CPU_FAM)))
|
||||
# STM32 families F2, F4, F7, H7 and L4 use the Synopsys DWC2 USB OTG IP core
|
||||
USEMODULE += tinyusb_portable_synopsys_dwc2
|
||||
else ifneq (,$(filter f0 f1 g4 l0 wb,$(CPU_FAM)))
|
||||
# TODO not yet working, the driver has to be ported
|
||||
else ifneq (,$(filter stm32f105% stm32f107%,$(CPU_MODEL)))
|
||||
# STM32F105xx and STM32F107xx also use the Synopsys DWC2 USB OTG IP core
|
||||
USEMODULE += tinyusb_portable_synopsys_dwc2
|
||||
else
|
||||
# All other STM32 MCUs use the USB Device FS IP core.
|
||||
USEMODULE += tinyusb_portable_stm32_fsdev
|
||||
endif
|
||||
endif
|
||||
|
@ -12,6 +12,7 @@ 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))
|
||||
CFLAGS += -Dasm=__asm
|
||||
else ifeq (saml21,$(CPU))
|
||||
CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_SAML21
|
||||
else ifeq (samd21,$(CPU))
|
||||
|
@ -2,6 +2,17 @@ MODULE = tinyusb_hw
|
||||
|
||||
ifneq (,$(filter saml21 samd5x samd21,$(CPU)))
|
||||
SRC = hw_sam0.c
|
||||
else ifeq (stm32,$(CPU))
|
||||
ifeq (,$(filter f1 f3 wb,$(CPU_FAM)))
|
||||
# All STM32 families except for F1, F3 and WB use the Synopsys DWC2 USB OTG IP core
|
||||
SRC += hw_stm32_otg.c
|
||||
else ifneq (,$(filter stm32f105% stm32f107%,$(CPU_MODEL)))
|
||||
# STM32F105xx and STM32F107xx also use the Synopsys DWC2 USB OTG IP core
|
||||
SRC += hw_stm32_otg.c
|
||||
else
|
||||
# All other STM32 MCUs use the USB Device FS IP core.
|
||||
SRC += hw_stm32_fsdev.c
|
||||
endif
|
||||
else
|
||||
SRC = hw_$(CPU).c
|
||||
endif
|
||||
|
88
pkg/tinyusb/hw/hw_stm32_fsdev.c
Normal file
88
pkg/tinyusb/hw/hw_stm32_fsdev.c
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Gunar Schorcht
|
||||
*
|
||||
* 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 STM32 MCUs with USB FS device port
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "periph_conf.h"
|
||||
#include "periph/gpio.h"
|
||||
#include "periph/pm.h"
|
||||
|
||||
#include "tusb.h"
|
||||
#include "device/usbd.h"
|
||||
#include "host/usbh.h"
|
||||
|
||||
static int tinyusb_hw_init_dev(const stm32_usbdev_fs_config_t *conf)
|
||||
{
|
||||
/* Block both STOP and STANDBY, TODO STOP is unblocked during USB suspend
|
||||
* status */
|
||||
pm_block(STM32_PM_STOP);
|
||||
pm_block(STM32_PM_STANDBY);
|
||||
|
||||
/* Enable the clock to the peripheral */
|
||||
periph_clk_en(conf->apb, conf->rcc_mask);
|
||||
|
||||
#if defined(PWR_CR2_USV)
|
||||
/* Validate USB Supply */
|
||||
PWR->CR2 |= PWR_CR2_USV;
|
||||
#endif
|
||||
|
||||
#if defined(RCC_APB1SMENR_USBSMEN)
|
||||
RCC->APB1SMENR |= RCC_APB1SMENR_USBSMEN;
|
||||
#elif defined(RCC_APB1SMENR1_USBSMEN)
|
||||
RCC->APB1SMENR1 |= RCC_APB1SMENR1_USBSMEN;
|
||||
#endif
|
||||
|
||||
#if defined(CRS_CR_AUTOTRIMEN) && defined(CRS_CR_CEN)
|
||||
/* Enable CRS with auto trim enabled */
|
||||
CRS->CR |= (CRS_CR_AUTOTRIMEN | CRS_CR_CEN);
|
||||
#endif
|
||||
|
||||
if (conf->af != GPIO_AF_UNDEF) {
|
||||
/* Configure AF for the pins */
|
||||
gpio_init_af(conf->dp, conf->af);
|
||||
gpio_init_af(conf->dm, conf->af);
|
||||
}
|
||||
|
||||
if (conf->disconn != GPIO_UNDEF) {
|
||||
/* In case the MCU has no internal D+ pullup, a GPIO is used to
|
||||
* connect/disconnect from USB bus */
|
||||
gpio_init(conf->disconn, GPIO_OUT);
|
||||
gpio_set(conf->disconn);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tinyusb_hw_init(void)
|
||||
{
|
||||
for (unsigned i = 0; i < USBDEV_NUMOF; i++) {
|
||||
if (tinyusb_hw_init_dev(&stm32_usbdev_fs_config[i]) != 0) {
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void USBDEV_ISR(void)
|
||||
{
|
||||
/* call device interrupt handler with the last device */
|
||||
if (IS_USED(MODULE_TINYUSB_DEVICE)) {
|
||||
tud_int_handler(TINYUSB_TUD_RHPORT);
|
||||
}
|
||||
|
||||
cortexm_isr_end();
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
* @brief
|
||||
* @{
|
||||
*
|
||||
* @brief tinyUSB hardware driver for STM32 MCUs
|
||||
* @brief tinyUSB hardware driver for STM32 MCUs with USB OTG FS/HS ports
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user