Skip to content

Commit

Permalink
Merge pull request #18714 from gschorcht/drivers/usbdev_synopsys_dwc2…
Browse files Browse the repository at this point in the history
…_hs_utmi

drivers/usbdev_synopsys_dwc2: add support for internal UTMI HS PHY
  • Loading branch information
bergzand authored Oct 16, 2022
2 parents 72d16e1 + f1bc9af commit 0fca912
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 47 deletions.
85 changes: 85 additions & 0 deletions boards/common/stm32/include/cfg_usb_otg_hs_phy_utmi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2019 Koen Zandberg
* 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 boards_common_stm32
* @{
*
* @file
* @brief Common configuration for STM32 OTG HS peripheral with internal UTMI HS PHY
*
* All STM32 boards which use the internal UTMI HS PHY for the USB OTG HS
* peripheral use the same configuration. Therefore a common configuration file
* can be used for these boards.
*
* @author Koen Zandberg <koen@bergzand.net>
* @author Gunar Schorcht <gunar@schorcht.net>
*/

#ifndef CFG_USB_OTG_HS_PHY_UTMI_H
#define CFG_USB_OTG_HS_PHY_UTMI_H

#include "periph_cpu.h"
#include "usbdev_synopsys_dwc2.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Enable the high speed USB OTG peripheral
*/
#define DWC2_USB_OTG_HS_ENABLED

#ifndef USBPHYC_TUNE_VALUE
/**
* @brief Default value of USBPHYC tuning control register
*
* The value of the USBPHYC tuning control register (USBPHYC_TUNE) is used by
* the USB HS PHY controller for the tuning interface of the internal
* USB HS PHY, please refer the Reference Manual for STM32F72xxx and STM32F73xxx
* for details.
*
* The value as defined in the [STM32CubeF7 HAL Driver MCU Component for F7]
* (https://bit.ly/3es9eFA) is used as default value.
* If necessary, it can be overridden by the board configuration in
* `periph_conf.h` by defining the value before this file is included.
*/
#define USBPHYC_TUNE_VALUE 0x00000f13U
#endif

/**
* @brief Common USB OTG HS configuration
*/
static const dwc2_usb_otg_fshs_config_t dwc2_usb_otg_fshs_config[] = {
{
.periph = USB_OTG_HS_PERIPH_BASE,
.type = DWC2_USB_OTG_HS,
.phy = DWC2_USB_OTG_PHY_UTMI,
.rcc_mask = RCC_AHB1ENR_OTGHSEN,
.irqn = OTG_HS_IRQn,
.ahb = AHB1,
.dm = GPIO_PIN(PORT_B, 14),
.dp = GPIO_PIN(PORT_B, 15),
.af = GPIO_AF10,
.phy_tune = USBPHYC_TUNE_VALUE,
}
};

/**
* @brief Number of available USB OTG peripherals
*/
#define USBDEV_NUMOF ARRAY_SIZE(dwc2_usb_otg_fshs_config)

#ifdef __cplusplus
}
#endif

#endif /* CFG_USB_OTG_HS_PHY_UTMI_H */
/** @} */
1 change: 1 addition & 0 deletions boards/stm32f723e-disco/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ config BOARD_STM32F723E_DISCO
select HAS_PERIPH_UART
select HAS_PERIPH_UART_HW_FC
select HAS_PERIPH_USBDEV
select HAS_PERIPH_USBDEV_HS_UTMI

# Put other features for this board (in alphabetical order)
select HAS_TINYUSB_DEVICE
Expand Down
1 change: 1 addition & 0 deletions boards/stm32f723e-disco/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_uart_hw_fc
FEATURES_PROVIDED += periph_usbdev
FEATURES_PROVIDED += periph_usbdev_hs_utmi

# Put other features for this board (in alphabetical order)
FEATURES_PROVIDED += tinyusb_device
Expand Down
6 changes: 6 additions & 0 deletions boards/stm32f723e-disco/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ Use the `term` target to open a terminal:

make BOARD=stm32f723e-disco -C examples/hello-world term

### USB OTG Peripheral Device Driver

By default, the USB OTG FS port is used. To use the USB OTG HS port with the
internal UTMI+ HS PHY, enable the module `periph_usbdev_hs_utmi`:

make BOARD=stm32f723e-disco USEMODULE=periph_usbdev_hs_utmi -C examples/usbus_minimal
*/
4 changes: 4 additions & 0 deletions boards/stm32f723e-disco/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
#include "periph_cpu.h"
#include "clk_conf.h"
#include "cfg_rtt_default.h"
#if defined(MODULE_PERIPH_USBDEV_HS_UTMI)
#include "cfg_usb_otg_hs_phy_utmi.h"
#else
#include "cfg_usb_otg_fs.h"
#endif

#ifdef __cplusplus
extern "C" {
Expand Down
4 changes: 4 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ ifneq (,$(filter periph_usbdev_hs_ulpi,$(USEMODULE)))
FEATURES_REQUIRED += periph_usbdev_hs_ulpi
endif

ifneq (,$(filter periph_usbdev_hs_utmi,$(USEMODULE)))
FEATURES_REQUIRED += periph_usbdev_hs_utmi
endif

ifneq (,$(filter pn532_i2c,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c
USEMODULE += pn532
Expand Down
7 changes: 6 additions & 1 deletion drivers/include/usbdev_synopsys_dwc2.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef enum {
} dwc2_usb_otg_fshs_phy_t;

/**
* @brief stm32 USB OTG configuration
* @brief USB OTG configuration
*/
typedef struct {
uintptr_t periph; /**< USB peripheral base address */
Expand Down Expand Up @@ -95,6 +95,11 @@ typedef struct {
gpio_t dm; /**< Data- gpio */
gpio_t dp; /**< Data+ gpio */
gpio_af_t af; /**< Alternative function */
#if defined(MODULE_PERIPH_USBDEV_HS_UTMI) || DOXYGEN
uint32_t phy_tune; /**< USB HS PHY controller tuning register
* value (STM32-specific), see USBPHYC_TUNE
* register in STM32 Reference Manual */
#endif /* defined(MODULE_PERIPH_USBDEV_HS_UTMI) */
#endif /* defined(MCU_STM32) || DOXYGEN */
} dwc2_usb_otg_fshs_config_t;

Expand Down
34 changes: 1 addition & 33 deletions drivers/periph_common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -156,39 +156,7 @@ config MODULE_PERIPH_INIT_TEMPERATURE
depends on MODULE_PERIPH_TEMPERATURE

rsource "Kconfig.uart"

config MODULE_PERIPH_USBDEV
bool "USBDEV peripheral driver"
depends on HAS_PERIPH_USBDEV
select MODULE_PERIPH_COMMON
select MODULE_PERIPH_USBDEV_CLK

config MODULE_PERIPH_INIT_USBDEV
bool "Auto initialize USBDEV peripheral"
default y if MODULE_PERIPH_INIT
depends on MODULE_PERIPH_USBDEV

config MODULE_PERIPH_USBDEV_HS_ULPI
bool "Use USB HS pripheral with UPLI HS PHY"
depends on HAS_PERIPH_USBDEV_HS_ULPI
depends on MODULE_PERIPH_USBDEV

config MODULE_PERIPH_INIT_USBDEV_HS_ULPI
bool
default y if MODULE_PERIPH_INIT && MODULE_PERIPH_USBDEV_HS_ULPI
depends on HAS_PERIPH_USBDEV_HS_ULPI
depends on MODULE_PERIPH_USBDEV

config MODULE_PERIPH_USBDEV_CLK
bool
depends on HAS_PERIPH_USBDEV
help
Enable the USB device specific clock settings, if there are any

config MODULE_PERIPH_INIT_USBDEV_CLK
bool
default y if MODULE_PERIPH_INIT && MODULE_PERIPH_USBDEV_CLK
depends on HAS_PERIPH_USBDEV
rsource "Kconfig.usbdev"

endif # TEST_KCONFIG

Expand Down
54 changes: 54 additions & 0 deletions drivers/periph_common/Kconfig.usbdev
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2020 HAW Hamburg
# 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.
#

menuconfig MODULE_PERIPH_USBDEV
bool "USBDEV peripheral driver"
depends on HAS_PERIPH_USBDEV
select MODULE_PERIPH_COMMON
select MODULE_PERIPH_USBDEV_CLK

if MODULE_PERIPH_USBDEV

# TODO: the 'init' modules are actually just artifacts from the way
# periph_init_% modules are handled in Makefile. We need to define them to keep
# the list the same for now. We should be able to remove them later on.

config MODULE_PERIPH_INIT_USBDEV
bool "Auto initialize USBDEV peripheral"
default y if MODULE_PERIPH_INIT

config MODULE_PERIPH_USBDEV_HS_ULPI
bool "Use USB HS peripheral with ULPI HS PHY"
depends on HAS_PERIPH_USBDEV_HS_ULPI

config MODULE_PERIPH_INIT_USBDEV_HS_ULPI
bool
depends on MODULE_PERIPH_USBDEV_HS_ULPI
default y if MODULE_PERIPH_INIT

config MODULE_PERIPH_USBDEV_HS_UTMI
bool "Use USB HS peripheral with internal UTMI+ HS PHY"
depends on HAS_PERIPH_USBDEV_HS_UTMI

config MODULE_PERIPH_INIT_USBDEV_HS_UTMI
bool
depends on MODULE_PERIPH_USBDEV_HS_UTMI
default y if MODULE_PERIPH_INIT

endif

config MODULE_PERIPH_USBDEV_CLK
bool
depends on HAS_PERIPH_USBDEV
help
Enable the USB device specific clock settings, if there are any

config MODULE_PERIPH_INIT_USBDEV_CLK
bool
depends on MODULE_PERIPH_USBDEV_CLK
default y if MODULE_PERIPH_INIT
Loading

0 comments on commit 0fca912

Please sign in to comment.