diff --git a/bsp/stm32/libraries/HAL_Drivers/Kconfig b/bsp/stm32/libraries/HAL_Drivers/Kconfig index 59f0939245..6dc0c5bcbb 100644 --- a/bsp/stm32/libraries/HAL_Drivers/Kconfig +++ b/bsp/stm32/libraries/HAL_Drivers/Kconfig @@ -1,3 +1,28 @@ +if BSP_USING_USBD + config BSP_USBD_TYPE_FS + bool + # "USB Full Speed (FS) Core" + config BSP_USBD_TYPE_HS + bool + # "USB High Speed (HS) Core" + + config BSP_USBD_SPEED_HS + bool + # "USB High Speed (HS) Mode" + config BSP_USBD_SPEED_HSINFS + bool + # "USB High Speed (HS) Core in FS mode" + + config BSP_USBD_PHY_EMBEDDED + bool + # "Using Embedded phy interface" + config BSP_USBD_PHY_UTMI + bool + # "UTMI: USB 2.0 Transceiver Macrocell Interace" + config BSP_USBD_PHY_ULPI + bool + # "ULPI: UTMI+ Low Pin Interface" +endif config BSP_USING_CRC bool "Enable CRC (CRC-32 0x04C11DB7 Polynomial)" diff --git a/bsp/stm32/libraries/HAL_Drivers/SConscript b/bsp/stm32/libraries/HAL_Drivers/SConscript index 1d37075fcd..02f68afa25 100644 --- a/bsp/stm32/libraries/HAL_Drivers/SConscript +++ b/bsp/stm32/libraries/HAL_Drivers/SConscript @@ -82,8 +82,8 @@ if GetDepend(['BSP_USING_WDT']): if GetDepend(['BSP_USING_SDIO']): src += ['drv_sdio.c'] -if GetDepend(['BSP_USING_USBD_FS']): - src += ['drv_usbd_fs.c'] +if GetDepend(['BSP_USING_USBD']): + src += ['drv_usbd.c'] if GetDepend(['BSP_USING_PULSE_ENCODER']): src += ['drv_pulse_encoder.c'] diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_fs_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_config.h similarity index 62% rename from bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_fs_config.h rename to bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_config.h index 520934aa4b..4ad6540896 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_fs_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_config.h @@ -8,11 +8,13 @@ * 2019-04-10 ZYH first version * 2019-07-29 Chinese66 change from f4 to f1 */ -#ifndef __USBD_FS_CONFIG_H__ -#define __USBD_FS_CONFIG_H__ +#ifndef __USBD_CONFIG_H__ +#define __USBD_CONFIG_H__ -#define USBD_FS_IRQ_HANDLER USB_LP_CAN1_RX0_IRQHandler +#define USBD_IRQ_HANDLER USB_LP_CAN1_RX0_IRQHandler #define USBD_INSTANCE USB +#define USBD_PCD_SPEED PCD_SPEED_FULL +#define USBD_PCD_PHY_MODULE PCD_PHY_EMBEDDED #define BSP_USB_CONNECT_PIN -1 #endif diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f4/usbd_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f4/usbd_config.h new file mode 100644 index 0000000000..9714ee4ac5 --- /dev/null +++ b/bsp/stm32/libraries/HAL_Drivers/config/f4/usbd_config.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2019-04-10 ZYH first version + * 2019-10-27 flybreak Compatible with the HS + */ +#ifndef __USBD_CONFIG_H__ +#define __USBD_CONFIG_H__ + +#include + +#ifdef BSP_USBD_TYPE_HS +#define USBD_IRQ_HANDLER OTG_HS_IRQHandler +#define USBD_INSTANCE USB_OTG_HS +#else +#define USBD_IRQ_HANDLER OTG_FS_IRQHandler +#define USBD_INSTANCE USB_OTG_FS +#endif + +#ifdef BSP_USBD_SPEED_HS +#define USBD_PCD_SPEED PCD_SPEED_HIGH +#elif BSP_USBD_SPEED_HSINFS +#define USBD_PCD_SPEED PCD_SPEED_HIGH_IN_FULL +#else +#define USBD_PCD_SPEED PCD_SPEED_FULL +#endif + +#ifdef BSP_USBD_PHY_ULPI +#define USBD_PCD_PHY_MODULE PCD_PHY_ULPI +#elif BSP_USBD_PHY_UTMI +#define USBD_PCD_PHY_MODULE PCD_PHY_UTMI +#else +#define USBD_PCD_PHY_MODULE PCD_PHY_EMBEDDED +#endif + +#endif diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f4/usbd_fs_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f4/usbd_fs_config.h deleted file mode 100644 index b987356c7d..0000000000 --- a/bsp/stm32/libraries/HAL_Drivers/config/f4/usbd_fs_config.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2006-2018, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2019-04-10 ZYH first version - */ -#ifndef __USBD_FS_CONFIG_H__ -#define __USBD_FS_CONFIG_H__ - -#define USBD_FS_IRQ_HANDLER OTG_FS_IRQHandler -#define USBD_INSTANCE USB_OTG_FS -#endif diff --git a/bsp/stm32/libraries/HAL_Drivers/config/g4/usbd_config.h b/bsp/stm32/libraries/HAL_Drivers/config/g4/usbd_config.h new file mode 100644 index 0000000000..e30f7c11a6 --- /dev/null +++ b/bsp/stm32/libraries/HAL_Drivers/config/g4/usbd_config.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2019-04-10 ZYH first version + * 2019-10-27 flybreak Compatible with the HS + */ +#ifndef __USBD_CONFIG_H__ +#define __USBD_CONFIG_H__ + +#include + +#ifdef BSP_USBD_TYPE_HS +#define USBD_IRQ_HANDLER OTG_HS_IRQHandler +#define USBD_INSTANCE USB_OTG_HS +#else +#define USBD_IRQ_HANDLER OTG_FS_IRQHandler +#define USBD_INSTANCE USB_OTG_FS +#endif + +#ifdef BSP_USBD_SPEED_HS +#define USBD_PCD_SPEED PCD_SPEED_HIGH +#elif BSP_USBD_SPEED_HSINFS +#define USBD_PCD_SPEED PCD_SPEED_HIGH_IN_FULL +#else +#define USBD_PCD_SPEED PCD_SPEED_FULL +#endif + +#ifdef BSP_USBD_PHY_ULPI +#define USBD_PCD_PHY_MODULE PCD_PHY_ULPI +#elif BSP_USBD_PHY_UTMI +#define USBD_PCD_PHY_MODULE PCD_PHY_UTMI +#else +#define USBD_PCD_PHY_MODULE PCD_PHY_EMBEDDED +#endif + +#endif diff --git a/bsp/stm32/libraries/HAL_Drivers/config/g4/usbd_fs_config.h b/bsp/stm32/libraries/HAL_Drivers/config/g4/usbd_fs_config.h deleted file mode 100644 index b987356c7d..0000000000 --- a/bsp/stm32/libraries/HAL_Drivers/config/g4/usbd_fs_config.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2006-2018, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2019-04-10 ZYH first version - */ -#ifndef __USBD_FS_CONFIG_H__ -#define __USBD_FS_CONFIG_H__ - -#define USBD_FS_IRQ_HANDLER OTG_FS_IRQHandler -#define USBD_INSTANCE USB_OTG_FS -#endif diff --git a/bsp/stm32/libraries/HAL_Drivers/config/h7/usbd_config.h b/bsp/stm32/libraries/HAL_Drivers/config/h7/usbd_config.h new file mode 100644 index 0000000000..9714ee4ac5 --- /dev/null +++ b/bsp/stm32/libraries/HAL_Drivers/config/h7/usbd_config.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2019-04-10 ZYH first version + * 2019-10-27 flybreak Compatible with the HS + */ +#ifndef __USBD_CONFIG_H__ +#define __USBD_CONFIG_H__ + +#include + +#ifdef BSP_USBD_TYPE_HS +#define USBD_IRQ_HANDLER OTG_HS_IRQHandler +#define USBD_INSTANCE USB_OTG_HS +#else +#define USBD_IRQ_HANDLER OTG_FS_IRQHandler +#define USBD_INSTANCE USB_OTG_FS +#endif + +#ifdef BSP_USBD_SPEED_HS +#define USBD_PCD_SPEED PCD_SPEED_HIGH +#elif BSP_USBD_SPEED_HSINFS +#define USBD_PCD_SPEED PCD_SPEED_HIGH_IN_FULL +#else +#define USBD_PCD_SPEED PCD_SPEED_FULL +#endif + +#ifdef BSP_USBD_PHY_ULPI +#define USBD_PCD_PHY_MODULE PCD_PHY_ULPI +#elif BSP_USBD_PHY_UTMI +#define USBD_PCD_PHY_MODULE PCD_PHY_UTMI +#else +#define USBD_PCD_PHY_MODULE PCD_PHY_EMBEDDED +#endif + +#endif diff --git a/bsp/stm32/libraries/HAL_Drivers/config/l4/usbd_config.h b/bsp/stm32/libraries/HAL_Drivers/config/l4/usbd_config.h new file mode 100644 index 0000000000..e30f7c11a6 --- /dev/null +++ b/bsp/stm32/libraries/HAL_Drivers/config/l4/usbd_config.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2019-04-10 ZYH first version + * 2019-10-27 flybreak Compatible with the HS + */ +#ifndef __USBD_CONFIG_H__ +#define __USBD_CONFIG_H__ + +#include + +#ifdef BSP_USBD_TYPE_HS +#define USBD_IRQ_HANDLER OTG_HS_IRQHandler +#define USBD_INSTANCE USB_OTG_HS +#else +#define USBD_IRQ_HANDLER OTG_FS_IRQHandler +#define USBD_INSTANCE USB_OTG_FS +#endif + +#ifdef BSP_USBD_SPEED_HS +#define USBD_PCD_SPEED PCD_SPEED_HIGH +#elif BSP_USBD_SPEED_HSINFS +#define USBD_PCD_SPEED PCD_SPEED_HIGH_IN_FULL +#else +#define USBD_PCD_SPEED PCD_SPEED_FULL +#endif + +#ifdef BSP_USBD_PHY_ULPI +#define USBD_PCD_PHY_MODULE PCD_PHY_ULPI +#elif BSP_USBD_PHY_UTMI +#define USBD_PCD_PHY_MODULE PCD_PHY_UTMI +#else +#define USBD_PCD_PHY_MODULE PCD_PHY_EMBEDDED +#endif + +#endif diff --git a/bsp/stm32/libraries/HAL_Drivers/config/l4/usbd_fs_config.h b/bsp/stm32/libraries/HAL_Drivers/config/l4/usbd_fs_config.h deleted file mode 100644 index b987356c7d..0000000000 --- a/bsp/stm32/libraries/HAL_Drivers/config/l4/usbd_fs_config.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2006-2018, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2019-04-10 ZYH first version - */ -#ifndef __USBD_FS_CONFIG_H__ -#define __USBD_FS_CONFIG_H__ - -#define USBD_FS_IRQ_HANDLER OTG_FS_IRQHandler -#define USBD_INSTANCE USB_OTG_FS -#endif diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_config.h b/bsp/stm32/libraries/HAL_Drivers/drv_config.h index b10628e988..cc1c3f5bde 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/drv_config.h @@ -33,7 +33,7 @@ extern "C" { #include "f1/tim_config.h" #include "f1/sdio_config.h" #include "f1/pwm_config.h" -#include "f1/usbd_fs_config.h" +#include "f1/usbd_config.h" #include "f1/pulse_encoder_config.h" #elif defined(SOC_SERIES_STM32F2) #include "f2/dma_config.h" @@ -48,7 +48,7 @@ extern "C" { #include "f4/uart_config.h" #include "f4/spi_config.h" #include "f4/qspi_config.h" -#include "f4/usbd_fs_config.h" +#include "f4/usbd_config.h" #include "f4/adc_config.h" #include "f4/tim_config.h" #include "f4/sdio_config.h" @@ -75,7 +75,7 @@ extern "C" { #include "l4/tim_config.h" #include "l4/sdio_config.h" #include "l4/pwm_config.h" -#include "l4/usbd_fs_config.h" +#include "l4/usbd_config.h" #elif defined(SOC_SERIES_STM32G0) #include "g0/dma_config.h" #include "g0/uart_config.h" @@ -88,7 +88,7 @@ extern "C" { #include "g4/uart_config.h" #include "g4/spi_config.h" #include "g4/qspi_config.h" -#include "g4/usbd_fs_config.h" +#include "g4/usbd_config.h" #include "g4/adc_config.h" #include "g4/tim_config.h" #include "g4/sdio_config.h" @@ -103,6 +103,7 @@ extern "C" { #include "h7/tim_config.h" #include "h7/sdio_config.h" #include "h7/pwm_config.h" +#include "h7/usbd_config.h" #endif #ifdef __cplusplus diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usbd_fs.c b/bsp/stm32/libraries/HAL_Drivers/drv_usbd.c similarity index 97% rename from bsp/stm32/libraries/HAL_Drivers/drv_usbd_fs.c rename to bsp/stm32/libraries/HAL_Drivers/drv_usbd.c index 91371a38ec..1f40117750 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usbd_fs.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usbd.c @@ -6,11 +6,12 @@ * Change Logs: * Date Author Notes * 2019-04-10 ZYH first version + * 2019-10-27 flybreak Compatible with the HS */ #include -#ifdef BSP_USING_USBD_FS +#ifdef BSP_USING_USBD #include #include "board.h" #include @@ -32,13 +33,12 @@ static struct ep_id _ep_pool[] = {0xFF, USB_EP_ATTR_TYPE_MASK, USB_DIR_MASK, 0, ID_ASSIGNED }, }; -void USBD_FS_IRQ_HANDLER(void) +void USBD_IRQ_HANDLER(void) { rt_interrupt_enter(); HAL_PCD_IRQHandler(&_stm_pcd); /* leave interrupt */ rt_interrupt_leave(); - } void HAL_PCD_ResetCallback(PCD_HandleTypeDef *pcd) @@ -194,10 +194,10 @@ static rt_err_t _init(rt_device_t device) pcd->Instance = USBD_INSTANCE; memset(&pcd->Init, 0, sizeof pcd->Init); pcd->Init.dev_endpoints = 8; - pcd->Init.speed = PCD_SPEED_FULL; + pcd->Init.speed = USBD_PCD_SPEED; pcd->Init.ep0_mps = DEP0CTL_MPS_64; #if !defined(SOC_SERIES_STM32F1) - pcd->Init.phy_itface = PCD_PHY_EMBEDDED; + pcd->Init.phy_itface = USBD_PCD_PHY_MODULE; #endif /* Initialize LL Driver */ HAL_PCD_Init(pcd); diff --git a/bsp/stm32/libraries/templates/stm32xx_board_Kconfig b/bsp/stm32/libraries/templates/stm32xx_board_Kconfig index d419b4aea9..42c8528c60 100644 --- a/bsp/stm32/libraries/templates/stm32xx_board_Kconfig +++ b/bsp/stm32/libraries/templates/stm32xx_board_Kconfig @@ -171,7 +171,7 @@ menu "On-chip Peripheral Drivers" select RT_USING_WDT default n - config BSP_USING_USBD_FS + config BSP_USING_USBD bool "Enable OTGFS as USB device" select RT_USING_USB_DEVICE default n diff --git a/bsp/stm32/stm32f429-st-disco/board/Kconfig b/bsp/stm32/stm32f429-st-disco/board/Kconfig index 78788870d9..20b1a98ab3 100644 --- a/bsp/stm32/stm32f429-st-disco/board/Kconfig +++ b/bsp/stm32/stm32f429-st-disco/board/Kconfig @@ -76,7 +76,7 @@ menu "On-chip Peripheral Drivers" bool "Enable FMC" default n - config BSP_USING_USBD_FS + config BSP_USING_USBD bool "Enable OTGFS as USB device" select RT_USING_USB_DEVICE default n diff --git a/bsp/stm32/stm32f469-st-disco/board/Kconfig b/bsp/stm32/stm32f469-st-disco/board/Kconfig index 9cf1430600..a1dd9ff7f7 100644 --- a/bsp/stm32/stm32f469-st-disco/board/Kconfig +++ b/bsp/stm32/stm32f469-st-disco/board/Kconfig @@ -149,7 +149,7 @@ menu "On-chip Peripheral Drivers" select RT_USING_DFS default n - config BSP_USING_USBD_FS + config BSP_USING_USBD bool "Enable OTGFS as USB device" select RT_USING_USB_DEVICE default n diff --git a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig index 16ebda7a35..63c82c08cc 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig +++ b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig @@ -300,7 +300,7 @@ menu "On-chip Peripheral Drivers" select RT_USING_WDT default n - config BSP_USING_USBD_FS + config BSP_USING_USBD bool "Enable OTGFS as USB device" select RT_USING_USB_DEVICE default n