-
Notifications
You must be signed in to change notification settings - Fork 46
Integration for STM32 without XPD
As the STM32_XPD drivers break CMSIS compliance, any existing CMSIS-based STM32 software is incompatible with XPD. In order to be able to integrate this library as part of an existing software, a workaround solution is described below.
Whichever STM32 device you may be using, it has either one of the two possible USB peripheral IPs, the USB or the OTG_FS/OTG_HS. Therefore the peripheral drivers contained in STM32L4_XPD will be suitable for any STM32. The following files are required:
- inc/xpd_common.h
- inc/xpd_usb.h
- inc/xpd_usb_otg.h
- src/xpd_usb.c
- src/xpd_usb_otg.c
These copied files include a list of headers that need to be created. The list of headers with their contents follow:
[empty]
[empty]
(Assuming that the clock enabling is done separately.)
#define RCC_vClockEnable(A)
#define RCC_vClockDisable(A)
If the USB_eChargerDetect()
API is used, then the following two functions have to be implemented:
void XPD_vDelay_ms (uint32_t ulMilliseconds);
XPD_ReturnType XPD_eWaitForDiff (volatile uint32_t * pulVarAddress, uint32_t ulBitSelector,
uint32_t ulMatch, uint32_t * pulTimeout);
In other cases simply define them as empty macros:
#define XPD_vDelay_ms(A)
#define XPD_eWaitForDiff(A, B, C, D)
This header file will be responsible for uniting the XPD USB peripheral driver with the CMSIS-compliant device header. The final step to complete this file is to copy the USB peripherals structures (which are mentioned in the comments) from a device header in STM32_XPD/CMSIS/Device/ST. You should be able to find a supported device which has the same peripheral version as yours. In general for USB this device is recommended, while for USB_OTG this device is.
/* TODO Include the proper CMSIS device header */
#include "stm32l4xx.h"
/* Replace type definitions */
#define USB_TypeDef __USB_TypeDef
#define USB_OTG_INEndpointTypeDef __USB_OTG_INEndpointTypeDef
#define USB_OTG_OUTEndpointTypeDef __USB_OTG_OUTEndpointTypeDef
#define USB_OTG_HostChannelTypeDef __USB_OTG_HostChannelTypeDef
#define USB_OTG_TypeDef __USB_OTG_TypeDef
#undef USB
#define USB ((__USB_TypeDef*)USB_BASE)
/* TODO Copy USB peripheral registers structures from a compatible device header */
/* typedef of USB_TypeDef */
/* AND/OR */
/* typedef of USB_OTG_INEndpointTypeDef
typedef of USB_OTG_OUTEndpointTypeDef
typedef of USB_OTG_HostChannelTypeDef
typedef of USB_OTG_TypeDef */
After these files are copied and created, the USBDevice is ready to be built. Remember to add /PDs/STM32_XPD to the include directories as well.