Skip to content

Commit 25f189f

Browse files
dpgeorgeiabdalkader
authored andcommitted
stm32/usbd_conf: Clean up USBD hardware initialization functions.
Break the FS and HS initialization routines out into separate functions, and call them as necessary from the TinyUSB or STM USB helper functions. Signed-off-by: Damien George <[email protected]>
1 parent 9a065b7 commit 25f189f

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

ports/stm32/usbd_conf.c

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,8 @@ PCD_HandleTypeDef pcd_hs_handle;
6262
#define OTG_HS_IRQn USB1_OTG_HS_IRQn
6363
#endif
6464

65-
#if MICROPY_HW_TINYUSB_STACK
66-
void pyb_usbd_init(void)
67-
#else
68-
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
69-
#endif
70-
{
71-
#if MICROPY_HW_USB_FS
72-
#if MICROPY_HW_STM_USB_STACK
73-
if (hpcd->Instance == USB_OTG_FS)
74-
#endif
65+
#if MICROPY_HW_USB_FS
66+
static void mp_usbd_ll_init_fs(void) {
7567
{
7668
// Configure USB GPIO's.
7769

@@ -192,17 +184,12 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
192184
#endif
193185
#endif
194186
#endif
195-
196-
#if MICROPY_HW_STM_USB_STACK
197-
return;
198-
#endif
199187
}
200-
#endif
188+
}
189+
#endif // MICROPY_HW_USB_FS
201190

202-
#if MICROPY_HW_USB_HS
203-
#if MICROPY_HW_STM_USB_STACK
204-
if (hpcd->Instance == USB_OTG_HS)
205-
#endif
191+
#if MICROPY_HW_USB_HS
192+
static void mp_usbd_ll_init_hs(void) {
206193
{
207194
#if MICROPY_HW_USB_HS_IN_FS
208195

@@ -313,10 +300,36 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
313300
NVIC_SetPriority(OTG_HS_IRQn, IRQ_PRI_OTG_HS);
314301
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
315302
}
316-
#endif // MICROPY_HW_USB_HS
317303
}
304+
#endif // MICROPY_HW_USB_HS
305+
306+
#if MICROPY_HW_TINYUSB_STACK
307+
308+
void pyb_usbd_init(void) {
309+
#if MICROPY_HW_USB_FS
310+
mp_usbd_ll_init_fs();
311+
#endif
312+
313+
#if MICROPY_HW_USB_HS
314+
mp_usbd_ll_init_hs();
315+
#endif
316+
}
317+
318+
#elif MICROPY_HW_STM_USB_STACK
318319

319-
#if MICROPY_HW_STM_USB_STACK
320+
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) {
321+
#if MICROPY_HW_USB_FS
322+
if (hpcd->Instance == USB_OTG_FS) {
323+
mp_usbd_ll_init_fs();
324+
}
325+
#endif
326+
327+
#if MICROPY_HW_USB_HS
328+
if (hpcd->Instance == USB_OTG_HS) {
329+
mp_usbd_ll_init_hs();
330+
}
331+
#endif
332+
}
320333

321334
/**
322335
* @brief DeInitializes the PCD MSP.

0 commit comments

Comments
 (0)