diff --git a/bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_config.h b/bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_config.h index 4ad654089620c363b97617639df180ee436fc2be..d58b86f6d371ca0a5aa2aea50700c5fbd3d84e8e 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/f1/usbd_config.h @@ -11,10 +11,17 @@ #ifndef __USBD_CONFIG_H__ #define __USBD_CONFIG_H__ +#define USBD_IRQ_TYPE USB_LP_CAN1_RX0_IRQn #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 + +#ifndef BSP_USB_CONNECT_PIN #define BSP_USB_CONNECT_PIN -1 +#endif +#ifndef BSP_USB_PULL_UP_STATUS +#define BSP_USB_PULL_UP_STATUS 1 +#endif #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 index 9714ee4ac527bc1c8de5fa4e33d5437288f0ea63..a6fc9a4c4d1b934135ba6a8d9d85d07dc4a17ae5 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/f4/usbd_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/f4/usbd_config.h @@ -14,9 +14,11 @@ #include #ifdef BSP_USBD_TYPE_HS +#define USBD_IRQ_TYPE OTG_HS_IRQn #define USBD_IRQ_HANDLER OTG_HS_IRQHandler #define USBD_INSTANCE USB_OTG_HS -#else +#else +#define USBD_IRQ_TYPE OTG_FS_IRQn #define USBD_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 index e30f7c11a6d333f88a2e0e3844e7da34a7bc63ac..a6fc9a4c4d1b934135ba6a8d9d85d07dc4a17ae5 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/g4/usbd_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/g4/usbd_config.h @@ -14,9 +14,11 @@ #include #ifdef BSP_USBD_TYPE_HS +#define USBD_IRQ_TYPE OTG_HS_IRQn #define USBD_IRQ_HANDLER OTG_HS_IRQHandler #define USBD_INSTANCE USB_OTG_HS #else +#define USBD_IRQ_TYPE OTG_FS_IRQn #define USBD_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 index 9714ee4ac527bc1c8de5fa4e33d5437288f0ea63..a6fc9a4c4d1b934135ba6a8d9d85d07dc4a17ae5 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/h7/usbd_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/h7/usbd_config.h @@ -14,9 +14,11 @@ #include #ifdef BSP_USBD_TYPE_HS +#define USBD_IRQ_TYPE OTG_HS_IRQn #define USBD_IRQ_HANDLER OTG_HS_IRQHandler #define USBD_INSTANCE USB_OTG_HS -#else +#else +#define USBD_IRQ_TYPE OTG_FS_IRQn #define USBD_IRQ_HANDLER OTG_FS_IRQHandler #define USBD_INSTANCE USB_OTG_FS #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 index e30f7c11a6d333f88a2e0e3844e7da34a7bc63ac..a6fc9a4c4d1b934135ba6a8d9d85d07dc4a17ae5 100644 --- a/bsp/stm32/libraries/HAL_Drivers/config/l4/usbd_config.h +++ b/bsp/stm32/libraries/HAL_Drivers/config/l4/usbd_config.h @@ -14,9 +14,11 @@ #include #ifdef BSP_USBD_TYPE_HS +#define USBD_IRQ_TYPE OTG_HS_IRQn #define USBD_IRQ_HANDLER OTG_HS_IRQHandler #define USBD_INSTANCE USB_OTG_HS #else +#define USBD_IRQ_TYPE OTG_FS_IRQn #define USBD_IRQ_HANDLER OTG_FS_IRQHandler #define USBD_INSTANCE USB_OTG_FS #endif diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usbd.c b/bsp/stm32/libraries/HAL_Drivers/drv_usbd.c index 1f401177505cd1158ef95c337e28e269d5b1319f..79cb327ed8d51782f07ee6619e520e76fd6e4c58 100644 --- a/bsp/stm32/libraries/HAL_Drivers/drv_usbd.c +++ b/bsp/stm32/libraries/HAL_Drivers/drv_usbd.c @@ -99,14 +99,14 @@ void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) { #if defined(SOC_SERIES_STM32F1) rt_pin_mode(BSP_USB_CONNECT_PIN,PIN_MODE_OUTPUT); - rt_pin_write(BSP_USB_CONNECT_PIN, PIN_HIGH); + rt_pin_write(BSP_USB_CONNECT_PIN, BSP_USB_PULL_UP_STATUS); #endif } else { #if defined(SOC_SERIES_STM32F1) rt_pin_mode(BSP_USB_CONNECT_PIN,PIN_MODE_OUTPUT); - rt_pin_write(BSP_USB_CONNECT_PIN, PIN_LOW); + rt_pin_write(BSP_USB_CONNECT_PIN, !BSP_USB_PULL_UP_STATUS); #endif } } @@ -201,6 +201,9 @@ static rt_err_t _init(rt_device_t device) #endif /* Initialize LL Driver */ HAL_PCD_Init(pcd); + /* USB interrupt Init */ + HAL_NVIC_SetPriority(USBD_IRQ_TYPE, 2, 0); + HAL_NVIC_EnableIRQ(USBD_IRQ_TYPE); #if !defined(SOC_SERIES_STM32F1) HAL_PCDEx_SetRxFiFo(pcd, 0x80); HAL_PCDEx_SetTxFiFo(pcd, 0, 0x40); @@ -246,6 +249,9 @@ int stm_usbd_register(void) /* Register endpoint infomation */ _stm_udc.ep_pool = _ep_pool; _stm_udc.ep0.id = &_ep_pool[0]; +#ifdef BSP_USBD_SPEED_HS + _stm_udc.device_is_hs = RT_TRUE; +#endif rt_device_register((rt_device_t)&_stm_udc, "usbd", 0); rt_usb_device_init(); return RT_EOK;