Skip to content

Commit 061eb6f

Browse files
dhylandsdpgeorge
authored andcommitted
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.
1 parent 7dec35d commit 061eb6f

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

stmhal/boards/STM32F429DISC/stm32f4xx_hal_conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
/* Exported types ------------------------------------------------------------*/
4747
/* Exported constants --------------------------------------------------------*/
4848

49+
#define USE_USB_HS
4950
#define USE_USB_HS_IN_FS
5051

5152
/* ########################## Module Selection ############################## */

stmhal/stm32_it.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ void SysTick_Handler(void) {
301301
#if defined(USE_USB_FS)
302302
#define OTG_XX_IRQHandler OTG_FS_IRQHandler
303303
#define OTG_XX_WKUP_IRQHandler OTG_FS_WKUP_IRQHandler
304-
#elif defined(USE_USB_HS) || defined(USE_USB_HS_IN_FS)
304+
#elif defined(USE_USB_HS)
305305
#define OTG_XX_IRQHandler OTG_HS_IRQHandler
306306
#define OTG_XX_WKUP_IRQHandler OTG_HS_WKUP_IRQHandler
307307
#endif
@@ -352,7 +352,7 @@ void OTG_XX_WKUP_IRQHandler(void) {
352352
#ifdef USE_USB_FS
353353
/* Clear EXTI pending Bit*/
354354
__HAL_USB_FS_EXTI_CLEAR_FLAG();
355-
#elif defined(USE_USB_HS) || defined(USE_USB_HS_IN_FS)
355+
#elif defined(USE_USB_HS)
356356
/* Clear EXTI pending Bit*/
357357
__HAL_USB_HS_EXTI_CLEAR_FLAG();
358358
#endif

stmhal/stm32_it.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ void PendSV_Handler(void);
7474
void SysTick_Handler(void);
7575
#ifdef USE_USB_FS
7676
void OTG_FS_IRQHandler(void);
77-
#elif defined(USE_USB_HS) || defined(USE_USB_HS_IN_FS)
77+
#elif defined(USE_USB_HS)
7878
void OTG_HS_IRQHandler(void);
7979
#endif

stmhal/usbd_conf.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
9595
/* Enable USBFS Interrupt */
9696
HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
9797
}
98-
98+
#if defined(USE_USB_HS)
9999
else if(hpcd->Instance == USB_OTG_HS)
100100
{
101101
#if defined(USE_USB_HS_IN_FS)
@@ -139,7 +139,7 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
139139
/* Enable USB HS Clocks */
140140
__USB_OTG_HS_CLK_ENABLE();
141141

142-
#elif defined(USE_USB_HS)
142+
#else // !USE_USB_HS_IN_FS
143143

144144
/* Configure USB HS GPIOs */
145145
__GPIOA_CLK_ENABLE();
@@ -196,14 +196,15 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
196196
/* Enable USB HS Clocks */
197197
__USB_OTG_HS_CLK_ENABLE();
198198
__USB_OTG_HS_ULPI_CLK_ENABLE();
199-
#endif
199+
#endif // !USE_USB_HS_IN_FS
200200

201201
/* Set USBHS Interrupt to the lowest priority */
202202
HAL_NVIC_SetPriority(OTG_HS_IRQn, IRQ_PRI_OTG_HS, IRQ_SUBPRI_OTG_HS);
203203

204204
/* Enable USBHS Interrupt */
205205
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
206206
}
207+
#endif // USE_USB_HS
207208
}
208209
/**
209210
* @brief DeInitializes the PCD MSP.
@@ -218,7 +219,7 @@ void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
218219
__USB_OTG_FS_CLK_DISABLE();
219220
__SYSCFG_CLK_DISABLE();
220221
}
221-
#if defined(USE_USB_HS) || defined(USE_USB_HS_IN_FS)
222+
#if defined(USE_USB_HS)
222223
else if(hpcd->Instance == USB_OTG_HS)
223224
{
224225
/* Disable USB FS Clocks */
@@ -404,7 +405,8 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
404405
HAL_PCD_SetTxFiFo(&pcd_handle, 1, 0x40);
405406
HAL_PCD_SetTxFiFo(&pcd_handle, 2, 0x20);
406407
HAL_PCD_SetTxFiFo(&pcd_handle, 3, 0x40);
407-
#elif defined(USE_USB_HS_IN_FS)
408+
#elif defined(USE_USB_HS)
409+
#if defined(USE_USB_HS_IN_FS)
408410
/*Set LL Driver parameters */
409411
pcd_handle.Instance = USB_OTG_HS;
410412
pcd_handle.Init.dev_endpoints = 4;
@@ -431,7 +433,7 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
431433
HAL_PCD_SetTxFiFo(&pcd_handle, 1, 0x40);
432434
HAL_PCD_SetTxFiFo(&pcd_handle, 2, 0x20);
433435
HAL_PCD_SetTxFiFo(&pcd_handle, 3, 0x40);
434-
#elif defined(USE_USB_HS)
436+
#else // !defined(USE_USB_HS_IN_FS)
435437
/*Set LL Driver parameters */
436438
pcd_handle.Instance = USB_OTG_HS;
437439
pcd_handle.Init.dev_endpoints = 6;
@@ -460,8 +462,8 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
460462
HAL_PCD_SetTxFiFo(&pcd_handle, 0, 0x80);
461463
HAL_PCD_SetTxFiFo(&pcd_handle, 1, 0x174);
462464

463-
464-
#endif
465+
#endif // !USE_USB_HS_IN_FS
466+
#endif // USE_USB_HS
465467
return USBD_OK;
466468
}
467469

0 commit comments

Comments
 (0)