From 760b80f06836ad97f7fddab0f68ca7f78cf1879a Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Fri, 10 Mar 2023 16:47:26 +0100 Subject: [PATCH] cpu/stm32: move number of EP definition to periph_cpu.h --- cpu/stm32/include/periph_cpu.h | 51 ++++++++++++++++++++++++++++++++ cpu/stm32/include/usbdev_stm32.h | 27 ++++------------- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/cpu/stm32/include/periph_cpu.h b/cpu/stm32/include/periph_cpu.h index 77cb3ac776..2fa42b2c81 100644 --- a/cpu/stm32/include/periph_cpu.h +++ b/cpu/stm32/include/periph_cpu.h @@ -113,6 +113,57 @@ typedef struct { #define HAVE_PTP_TIMER_SET_ABSOLUTE 1 /**< Native implementation available */ /** @} */ +#if !DOXYGEN /* hide implementation details */ +/** + * @name USB device definitions + * @{ + */ +/* Detect the IP version based on the available register define */ +#if defined(USB_OTG_GCCFG_NOVBUSSENS) +#define STM32_USB_OTG_CID_1x /**< USB OTG FS version 0x00001200 */ +#elif defined(USB_OTG_GCCFG_VBDEN) +#define STM32_USB_OTG_CID_2x /**< USB OTG FS version 0x00002000 */ +#elif defined(USB) +#define STM32_USB_FS_CID_1x /**< USB FS version 0x00001200 */ +#endif + +/** + * @brief Number of endpoints available with the OTG FS peripheral + * including the control endpoint + */ +#ifdef STM32_USB_OTG_CID_1x +#define STM32_USB_OTG_FS_NUM_EP (4) /**< OTG FS with 4 endpoints */ +#elif defined(STM32_USB_OTG_CID_2x) +#define STM32_USB_OTG_FS_NUM_EP (6) /**< OTG FS with 6 endpoints */ +#endif + +/** + * @brief Number of endpoints available with the OTG HS peripheral + * including the control endpoint + */ +#ifdef STM32_USB_OTG_CID_1x +#define STM32_USB_OTG_HS_NUM_EP (6) /**< OTG HS with 6 endpoints */ +#elif defined(STM32_USB_OTG_CID_2x) +#define STM32_USB_OTG_HS_NUM_EP (9) /**< OTG HS with 9 endpoints */ +#endif + +/** + * @brief Number of IN/OUT endpoints including EP0 as used by USBUS + * + * @note Since only a single number of EPs can be defined for USBUS that is + * valid for all devices, the smallest number of EPs must be used for + * multiple USB devices. + */ +#if defined(STM32_USB_OTG_FS_NUM_EP) +#define USBDEV_NUM_ENDPOINTS STM32_USB_OTG_FS_NUM_EP +#elif defined(STM32_USB_OTG_HS_NUM_EP) +#define USBDEV_NUM_ENDPOINTS STM32_USB_OTG_HS_NUM_EP +#else +#define USBDEV_NUM_ENDPOINTS 8 +#endif + +#endif /* !DOXYGEN */ + #ifdef __cplusplus } #endif diff --git a/cpu/stm32/include/usbdev_stm32.h b/cpu/stm32/include/usbdev_stm32.h index 02d234e7a2..1d0c397f1a 100644 --- a/cpu/stm32/include/usbdev_stm32.h +++ b/cpu/stm32/include/usbdev_stm32.h @@ -41,42 +41,22 @@ #include #include #include "periph_cpu.h" -#include "periph/usbdev.h" #ifdef __cplusplus extern "C" { #endif -/* Detect the IP version based on the available register define */ -#if defined(USB_OTG_GCCFG_NOVBUSSENS) -#define STM32_USB_OTG_CID_1x /**< USB OTG FS version 0x00001200 */ -#elif defined(USB_OTG_GCCFG_VBDEN) -#define STM32_USB_OTG_CID_2x /**< USB OTG FS version 0x00002000 */ -#elif defined(USB) -#define STM32_USB_FS_CID_1x /**< USB FS version 0x00001200 */ -#else -#error Unknown USB peripheral version -#endif - /** * @brief Number of endpoints available with the OTG FS peripheral * including the control endpoint */ -#ifdef STM32_USB_OTG_CID_1x -#define DWC2_USB_OTG_FS_NUM_EP (4) /**< OTG FS with 4 endpoints */ -#elif defined(STM32_USB_OTG_CID_2x) -#define DWC2_USB_OTG_FS_NUM_EP (6) /**< OTG FS with 6 endpoints */ -#endif +#define DWC2_USB_OTG_FS_NUM_EP STM32_USB_OTG_FS_NUM_EP /** * @brief Number of endpoints available with the OTG HS peripheral * including the control endpoint */ -#ifdef STM32_USB_OTG_CID_1x -#define DWC2_USB_OTG_HS_NUM_EP (6) /**< OTG HS with 6 endpoints */ -#elif defined(STM32_USB_OTG_CID_2x) -#define DWC2_USB_OTG_HS_NUM_EP (9) /**< OTG HS with 9 endpoints */ -#endif +#define DWC2_USB_OTG_HS_NUM_EP STM32_USB_OTG_HS_NUM_EP /** * @brief USB OTG FS FIFO reception buffer space in 32-bit words @@ -144,6 +124,9 @@ extern "C" { #endif #endif +/* periph/usbdev.h is included after the definitions above by intention */ +#include "periph/usbdev.h" + /** * @brief stm32 USB Device FS only peripheral device context */