From 061eb6fa6b196ed3d17121acb8282d626fdd6a69 Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Wed, 25 Nov 2015 17:09:44 -0800 Subject: [PATCH] stmahl: Fix usbd_conf.c for devices which don't have USB_HS at all. The STMCube examples define both USE_USB_HS and USE_USB_HS_IN_FS when they use the HS in FS mode. The STM32F401 doesn't have a USB_HS at all, so the USB_OTG_HS instance doesn't even exist. --- .../boards/STM32F429DISC/stm32f4xx_hal_conf.h | 1 + stmhal/stm32_it.c | 4 ++-- stmhal/stm32_it.h | 2 +- stmhal/usbd_conf.c | 18 ++++++++++-------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/stmhal/boards/STM32F429DISC/stm32f4xx_hal_conf.h b/stmhal/boards/STM32F429DISC/stm32f4xx_hal_conf.h index 3bd9001c66..7090db1112 100644 --- a/stmhal/boards/STM32F429DISC/stm32f4xx_hal_conf.h +++ b/stmhal/boards/STM32F429DISC/stm32f4xx_hal_conf.h @@ -46,6 +46,7 @@ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ +#define USE_USB_HS #define USE_USB_HS_IN_FS /* ########################## Module Selection ############################## */ diff --git a/stmhal/stm32_it.c b/stmhal/stm32_it.c index f86eb041e9..5f96c6083b 100644 --- a/stmhal/stm32_it.c +++ b/stmhal/stm32_it.c @@ -301,7 +301,7 @@ void SysTick_Handler(void) { #if defined(USE_USB_FS) #define OTG_XX_IRQHandler OTG_FS_IRQHandler #define OTG_XX_WKUP_IRQHandler OTG_FS_WKUP_IRQHandler -#elif defined(USE_USB_HS) || defined(USE_USB_HS_IN_FS) +#elif defined(USE_USB_HS) #define OTG_XX_IRQHandler OTG_HS_IRQHandler #define OTG_XX_WKUP_IRQHandler OTG_HS_WKUP_IRQHandler #endif @@ -352,7 +352,7 @@ void OTG_XX_WKUP_IRQHandler(void) { #ifdef USE_USB_FS /* Clear EXTI pending Bit*/ __HAL_USB_FS_EXTI_CLEAR_FLAG(); -#elif defined(USE_USB_HS) || defined(USE_USB_HS_IN_FS) +#elif defined(USE_USB_HS) /* Clear EXTI pending Bit*/ __HAL_USB_HS_EXTI_CLEAR_FLAG(); #endif diff --git a/stmhal/stm32_it.h b/stmhal/stm32_it.h index 5b17428b33..b84a7f9e09 100644 --- a/stmhal/stm32_it.h +++ b/stmhal/stm32_it.h @@ -74,6 +74,6 @@ void PendSV_Handler(void); void SysTick_Handler(void); #ifdef USE_USB_FS void OTG_FS_IRQHandler(void); -#elif defined(USE_USB_HS) || defined(USE_USB_HS_IN_FS) +#elif defined(USE_USB_HS) void OTG_HS_IRQHandler(void); #endif diff --git a/stmhal/usbd_conf.c b/stmhal/usbd_conf.c index 8cf1fbf735..e0bfbc5684 100644 --- a/stmhal/usbd_conf.c +++ b/stmhal/usbd_conf.c @@ -95,7 +95,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) /* Enable USBFS Interrupt */ HAL_NVIC_EnableIRQ(OTG_FS_IRQn); } - +#if defined(USE_USB_HS) else if(hpcd->Instance == USB_OTG_HS) { #if defined(USE_USB_HS_IN_FS) @@ -139,7 +139,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) /* Enable USB HS Clocks */ __USB_OTG_HS_CLK_ENABLE(); -#elif defined(USE_USB_HS) +#else // !USE_USB_HS_IN_FS /* Configure USB HS GPIOs */ __GPIOA_CLK_ENABLE(); @@ -196,7 +196,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) /* Enable USB HS Clocks */ __USB_OTG_HS_CLK_ENABLE(); __USB_OTG_HS_ULPI_CLK_ENABLE(); - #endif +#endif // !USE_USB_HS_IN_FS /* Set USBHS Interrupt to the lowest priority */ HAL_NVIC_SetPriority(OTG_HS_IRQn, IRQ_PRI_OTG_HS, IRQ_SUBPRI_OTG_HS); @@ -204,6 +204,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) /* Enable USBHS Interrupt */ HAL_NVIC_EnableIRQ(OTG_HS_IRQn); } +#endif // USE_USB_HS } /** * @brief DeInitializes the PCD MSP. @@ -218,7 +219,7 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd) __USB_OTG_FS_CLK_DISABLE(); __SYSCFG_CLK_DISABLE(); } - #if defined(USE_USB_HS) || defined(USE_USB_HS_IN_FS) + #if defined(USE_USB_HS) else if(hpcd->Instance == USB_OTG_HS) { /* Disable USB FS Clocks */ @@ -404,7 +405,8 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) HAL_PCD_SetTxFiFo(&pcd_handle, 1, 0x40); HAL_PCD_SetTxFiFo(&pcd_handle, 2, 0x20); HAL_PCD_SetTxFiFo(&pcd_handle, 3, 0x40); -#elif defined(USE_USB_HS_IN_FS) +#elif defined(USE_USB_HS) +#if defined(USE_USB_HS_IN_FS) /*Set LL Driver parameters */ pcd_handle.Instance = USB_OTG_HS; pcd_handle.Init.dev_endpoints = 4; @@ -431,7 +433,7 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) HAL_PCD_SetTxFiFo(&pcd_handle, 1, 0x40); HAL_PCD_SetTxFiFo(&pcd_handle, 2, 0x20); HAL_PCD_SetTxFiFo(&pcd_handle, 3, 0x40); -#elif defined(USE_USB_HS) +#else // !defined(USE_USB_HS_IN_FS) /*Set LL Driver parameters */ pcd_handle.Instance = USB_OTG_HS; pcd_handle.Init.dev_endpoints = 6; @@ -460,8 +462,8 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) HAL_PCD_SetTxFiFo(&pcd_handle, 0, 0x80); HAL_PCD_SetTxFiFo(&pcd_handle, 1, 0x174); - -#endif +#endif // !USE_USB_HS_IN_FS +#endif // USE_USB_HS return USBD_OK; }