Skip to content

Commit f43810b

Browse files
committed
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 <damien@micropython.org>
1 parent 14b5080 commit f43810b

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

@@ -342,10 +329,36 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
342329
NVIC_SetPriority(OTG_HS_IRQn, IRQ_PRI_OTG_HS);
343330
HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
344331
}
345-
#endif // MICROPY_HW_USB_HS
346332
}
333+
#endif // MICROPY_HW_USB_HS
334+
335+
#if MICROPY_HW_TINYUSB_STACK
336+
337+
void pyb_usbd_init(void) {
338+
#if MICROPY_HW_USB_FS
339+
mp_usbd_ll_init_fs();
340+
#endif
341+
342+
#if MICROPY_HW_USB_HS
343+
mp_usbd_ll_init_hs();
344+
#endif
345+
}
346+
347+
#elif MICROPY_HW_STM_USB_STACK
347348

348-
#if MICROPY_HW_STM_USB_STACK
349+
void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) {
350+
#if MICROPY_HW_USB_FS
351+
if (hpcd->Instance == USB_OTG_FS) {
352+
mp_usbd_ll_init_fs();
353+
}
354+
#endif
355+
356+
#if MICROPY_HW_USB_HS
357+
if (hpcd->Instance == USB_OTG_HS) {
358+
mp_usbd_ll_init_hs();
359+
}
360+
#endif
361+
}
349362

350363
/**
351364
* @brief DeInitializes the PCD MSP.

0 commit comments

Comments
 (0)