diff options
| author | Damien George <damien@micropython.org> | 2025-11-27 23:24:24 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2025-11-29 23:35:20 +1100 |
| commit | f43810b1cd4142474a99df4e08d51a97eb9af00a (patch) | |
| tree | 55c34d528f78732a363bbf2904b821ad62939f6f | |
| parent | 14b5080515ec483f0f7be843a089eea835e4519f (diff) | |
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>
| -rw-r--r-- | ports/stm32/usbd_conf.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/ports/stm32/usbd_conf.c b/ports/stm32/usbd_conf.c index 76142789d..be56b2202 100644 --- a/ports/stm32/usbd_conf.c +++ b/ports/stm32/usbd_conf.c @@ -62,16 +62,8 @@ PCD_HandleTypeDef pcd_hs_handle; #define OTG_HS_IRQn USB1_OTG_HS_IRQn #endif -#if MICROPY_HW_TINYUSB_STACK -void pyb_usbd_init(void) -#else -void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) -#endif -{ - #if MICROPY_HW_USB_FS - #if MICROPY_HW_STM_USB_STACK - if (hpcd->Instance == USB_OTG_FS) - #endif +#if MICROPY_HW_USB_FS +static void mp_usbd_ll_init_fs(void) { { // Configure USB GPIO's. @@ -192,17 +184,12 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) #endif #endif #endif - - #if MICROPY_HW_STM_USB_STACK - return; - #endif } - #endif +} +#endif // MICROPY_HW_USB_FS - #if MICROPY_HW_USB_HS - #if MICROPY_HW_STM_USB_STACK - if (hpcd->Instance == USB_OTG_HS) - #endif +#if MICROPY_HW_USB_HS +static void mp_usbd_ll_init_hs(void) { { #if MICROPY_HW_USB_HS_IN_FS @@ -342,10 +329,36 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) NVIC_SetPriority(OTG_HS_IRQn, IRQ_PRI_OTG_HS); HAL_NVIC_EnableIRQ(OTG_HS_IRQn); } - #endif // MICROPY_HW_USB_HS } +#endif // MICROPY_HW_USB_HS + +#if MICROPY_HW_TINYUSB_STACK + +void pyb_usbd_init(void) { + #if MICROPY_HW_USB_FS + mp_usbd_ll_init_fs(); + #endif + + #if MICROPY_HW_USB_HS + mp_usbd_ll_init_hs(); + #endif +} + +#elif MICROPY_HW_STM_USB_STACK -#if MICROPY_HW_STM_USB_STACK +void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) { + #if MICROPY_HW_USB_FS + if (hpcd->Instance == USB_OTG_FS) { + mp_usbd_ll_init_fs(); + } + #endif + + #if MICROPY_HW_USB_HS + if (hpcd->Instance == USB_OTG_HS) { + mp_usbd_ll_init_hs(); + } + #endif +} /** * @brief DeInitializes the PCD MSP. |
