Skip to content

Commit

Permalink
cpu/stm32: move number of EP definition to periph_cpu.h
Browse files Browse the repository at this point in the history
  • Loading branch information
gschorcht committed Mar 11, 2023
1 parent 924931d commit 2bc25f3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 22 deletions.
51 changes: 51 additions & 0 deletions cpu/stm32/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 5 additions & 22 deletions cpu/stm32/include/usbdev_stm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,42 +41,22 @@
#include <stdint.h>
#include <stdlib.h>
#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
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 2bc25f3

Please sign in to comment.