Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/usbdev_synopsys_dwc2: add USB OTG HS peripheral support for external ULPI HS PHYs #18679

Merged
merged 6 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/common/esp32s2/include/periph_conf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ static const dwc2_usb_otg_fshs_config_t dwc2_usb_otg_fshs_config[] = {
{
.periph = USB_OTG_FS_PERIPH_BASE,
.type = DWC2_USB_OTG_FS,
.phy = DWC2_USB_OTG_PHY_BUILTIN,
}
};

Expand Down
1 change: 1 addition & 0 deletions boards/common/esp32s3/include/periph_conf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ static const dwc2_usb_otg_fshs_config_t dwc2_usb_otg_fshs_config[] = {
{
.periph = USB_OTG_FS_PERIPH_BASE,
.type = DWC2_USB_OTG_FS,
.phy = DWC2_USB_OTG_PHY_BUILTIN,
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
* @{
*
* @file
* @brief Common configuration for STM32 OTG HS peripheral with FS phy
* @brief Common configuration for STM32 OTG HS peripheral with on-chip FS PHY
*
* All STM32 boards which use the on-chip FS 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 <[email protected]>
*/

#ifndef CFG_USB_OTG_HS_FS_H
#define CFG_USB_OTG_HS_FS_H
#ifndef CFG_USB_OTG_HS_PHY_FS_H
#define CFG_USB_OTG_HS_PHY_FS_H

#include "periph_cpu.h"
#include "usbdev_synopsys_dwc2.h"
Expand Down Expand Up @@ -57,5 +61,5 @@ static const dwc2_usb_otg_fshs_config_t dwc2_usb_otg_fshs_config[] = {
}
#endif

#endif /* CFG_USB_OTG_HS_FS_H */
#endif /* CFG_USB_OTG_HS_PHY_FS_H */
/** @} */
2 changes: 1 addition & 1 deletion boards/stm32f429i-disc1/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "periph_cpu.h"
#include "clk_conf.h"
#include "cfg_timer_tim5.h"
#include "cfg_usb_otg_hs_fs.h"
#include "cfg_usb_otg_hs_phy_fs.h"

#ifdef __cplusplus
extern "C" {
Expand Down
1 change: 1 addition & 0 deletions boards/stm32f746g-disco/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config BOARD_STM32F746G_DISCO
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
select HAS_PERIPH_USBDEV
select HAS_PERIPH_USBDEV_HS_ULPI

# Clock configuration
select BOARD_HAS_HSE
Expand Down
2 changes: 1 addition & 1 deletion boards/stm32f746g-disco/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Current hardware support:
| I2C | X | I2C1 on PB8/PB9 |
| Ethernet | X | |
| USB OTG FS | X | |
| USB OTG HS | - | |
| USB OTG HS | X | |
| TFT LCD | X | |
| Capacitive touch screen | X | |
| User microphones | - | |
Expand Down
1 change: 1 addition & 0 deletions boards/stm32f746g-disco/features-shared.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += periph_usbdev
FEATURES_PROVIDED += periph_usbdev_hs_ulpi

# stm32f746g-disco provides a custom default Kconfig clock configuration
KCONFIG_BOARD_CONFIG += $(RIOTBOARD)/stm32f746g-disco/clock.config
54 changes: 54 additions & 0 deletions boards/stm32f746g-disco/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
#include "clk_conf.h"
#include "cfg_rtt_default.h"
#include "cfg_timer_tim2.h"
#if defined(MODULE_PERIPH_USBDEV_HS_ULPI)
#include "usbdev_synopsys_dwc2.h"
#else
#include "cfg_usb_otg_fs.h"
#endif
#include "mii.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -265,6 +269,56 @@ static const ltdc_conf_t ltdc_config = {
};
/** @} */

#if defined(MODULE_PERIPH_USBDEV_HS_ULPI) || DOXYGEN
/**
* @name USB OTG FS configuration using ULPI HS PHY
*
* The USB OTG HS peripheral uses a ULPI HS PHY. The configuration of the
* ULPI HS PHY interface is board-specific.
*
* @{
*/

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

/**
* @brief Common USB OTG HS configuration with ULPI HS PHY
*/
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_ULPI,
.rcc_mask = RCC_AHB1ENR_OTGHSEN,
.irqn = OTG_HS_IRQn,
.ahb = AHB1,
.ulpi_af = GPIO_AF10,
.ulpi_clk = GPIO_PIN(PORT_A, 5),
.ulpi_d0 = GPIO_PIN(PORT_A, 3),
.ulpi_d1 = GPIO_PIN(PORT_B, 0),
.ulpi_d2 = GPIO_PIN(PORT_B, 1),
.ulpi_d3 = GPIO_PIN(PORT_B, 10),
.ulpi_d4 = GPIO_PIN(PORT_B, 11),
.ulpi_d5 = GPIO_PIN(PORT_B, 12),
.ulpi_d6 = GPIO_PIN(PORT_B, 13),
.ulpi_d7 = GPIO_PIN(PORT_B, 5),
.ulpi_dir = GPIO_PIN(PORT_C, 2),
.ulpi_stp = GPIO_PIN(PORT_C, 0),
.ulpi_nxt = GPIO_PIN(PORT_H, 4),
}
};

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

/** @} */
#endif /* defined(MODULE_PERIPH_USBDEV_HS_ULPI) || DOXYGEN */

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions boards/stm32f7508-dk/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config BOARD_STM32F7508_DK
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
select HAS_PERIPH_USBDEV
select HAS_PERIPH_USBDEV_HS_ULPI

# Clock configuration
select BOARD_HAS_HSE
Expand Down
4 changes: 4 additions & 0 deletions drivers/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ ifneq (,$(filter periph_usbdev,$(USEMODULE)))
USEMODULE += periph_usbdev_clk
endif

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

ifneq (,$(filter pn532_i2c,$(USEMODULE)))
FEATURES_REQUIRED += periph_i2c
USEMODULE += pn532
Expand Down
47 changes: 37 additions & 10 deletions drivers/include/usbdev_synopsys_dwc2.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,61 @@ typedef enum {
DWC2_USB_OTG_HS = 1, /**< High speed peripheral */
} dwc2_usb_otg_fshs_type_t;

#if defined(MCU_STM32)
/**
* @brief Type of USB OTG peripheral phy.
* @brief Device speed used
*/
enum {
DWC2_USB_OTG_DSPD_HS = 0, /**< High speed */
DWC2_USB_OTG_DSPD_FS_PHY_HS = 1, /**< Full speed on HS PHY */
DWC2_USB_OTG_DSPD_LS = 2, /**< Low speed */
DWC2_USB_OTG_DSPD_FS = 3, /**< Full speed */
};

/**
* @brief Type of USB OTG peripheral PHY.
*
* The FS type only supports the built-in type, the HS phy can have either the
* FS built-in phy enabled or the HS ULPI interface enabled.
* The FS type only supports the built-in PHY, the HS type can have enabled
* either
* - the on-chip FS PHY,
* - the external ULPI HS PHY interface, or
* - the internal UTMI HS PHY.
*/
typedef enum {
DWC2_USB_OTG_PHY_BUILTIN,
DWC2_USB_OTG_PHY_ULPI,
DWC2_USB_OTG_PHY_BUILTIN, /**< on-chip FS PHY */
DWC2_USB_OTG_PHY_ULPI, /**< ULPI for external HS PHY */
DWC2_USB_OTG_PHY_UTMI, /**< UTMI for internal HS PHY */
} dwc2_usb_otg_fshs_phy_t;
#endif

/**
* @brief stm32 USB OTG configuration
*/
typedef struct {
uintptr_t periph; /**< USB peripheral base address */
dwc2_usb_otg_fshs_type_t type; /**< FS or HS type */
#if defined(MCU_STM32)
dwc2_usb_otg_fshs_phy_t phy; /**< Built-in or ULPI phy */
dwc2_usb_otg_fshs_phy_t phy; /**< on-chip FS, ULPI HS or UTMI HS PHY */
#if defined(MODULE_PERIPH_USBDEV_HS_ULPI) || DOXYGEN
gpio_t ulpi_clk; /**< ULPI CLK gpio */
gpio_t ulpi_d0; /**< ULPI D0 gpio */
gpio_t ulpi_d1; /**< ULPI D1 gpio */
gpio_t ulpi_d2; /**< ULPI D2 gpio */
gpio_t ulpi_d3; /**< ULPI D3 gpio */
gpio_t ulpi_d4; /**< ULPI D4 gpio */
gpio_t ulpi_d5; /**< ULPI D5 gpio */
gpio_t ulpi_d6; /**< ULPI D6 gpio */
gpio_t ulpi_d7; /**< ULPI D7 gpio */
gpio_t ulpi_dir; /**< ULPI DIR gpio */
gpio_t ulpi_stp; /**< ULPI STP gpio */
gpio_t ulpi_nxt; /**< ULPI NXT gpio */
gpio_af_t ulpi_af; /**< Alternative function for ULPI */
#endif
#if defined(MCU_STM32) || DOXYGEN
uint32_t rcc_mask; /**< bit in clock enable register */
uint8_t irqn; /**< IRQ channel */
uint8_t ahb; /**< AHB bus */
gpio_t dm; /**< Data- gpio */
gpio_t dp; /**< Data+ gpio */
gpio_af_t af; /**< Alternative function */
#endif /* defined(MCU_STM32) */
#endif /* defined(MCU_STM32) || DOXYGEN */
} dwc2_usb_otg_fshs_config_t;

#ifdef __cplusplus
Expand Down
11 changes: 11 additions & 0 deletions drivers/periph_common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ config MODULE_PERIPH_INIT_USBDEV
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
Expand Down
Loading