diff --git a/bsp/stm32/libraries/HAL_Drivers/Kconfig b/bsp/stm32/libraries/HAL_Drivers/Kconfig index 59f09392455686478b51934740e450ab9fe9fa2e..6dc0c5bcbbd1156bbd4a7dfb2991fce8f13db055 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 1d37075fcda9a9686c06ff4e1930a6ad41b35816..02f68afa25679fe7b1b1104ae021267131654fbd 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 520934aa4bb4653143599f0da4525d7f7ff15e2f..4ad654089620c363b97617639df180ee436fc2be 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 0000000000000000000000000000000000000000..9714ee4ac527bc1c8de5fa4e33d5437288f0ea63 --- /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 b987356c7d38fb93c26decaa58cd48c81afafecd..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..e30f7c11a6d333f88a2e0e3844e7da34a7bc63ac --- /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 b987356c7d38fb93c26decaa58cd48c81afafecd..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..9714ee4ac527bc1c8de5fa4e33d5437288f0ea63 --- /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 0000000000000000000000000000000000000000..e30f7c11a6d333f88a2e0e3844e7da34a7bc63ac --- /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 b987356c7d38fb93c26decaa58cd48c81afafecd..0000000000000000000000000000000000000000 --- 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 b10628e988ff111b7d68d4e62c928b007bfa2536..cc1c3f5bde0a717d2a2f46f85b9af10543bfa940 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 91371a38ec309024909ec7366ba65b5212f4a8ed..1f401177505cd1158ef95c337e28e269d5b1319f 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 d419b4aea965fdf22fcd8c8b01677af4f2c220ca..42c8528c603c2f3cb14b92528b20c772d36c946b 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 78788870d9ceae49c78ef5892bfdfe1fddc66c99..20b1a98ab3fccb07f928a60689c8b41ad6b1d811 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 9cf1430600aeb3a98ec85b57082be815a91d5549..a1dd9ff7f72742f8e14d79be35e977b60924c4ea 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 16ebda7a3527895d2615d810b77f6a126206b4c6..63c82c08ccd525949cbb3788f67097b6bf17f1c1 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