/
stm32f407xx.h
#define USB_OTG_HS_PERIPH_BASE 0x40040000UL
#define USB_OTG_HS ((USB_OTG_GlobalTypeDef *) USB_OTG_HS_PERIPH_BASE)
- 定义全局变量 USBD_HandleTypeDef hUsbDeviceHS;并默认全零初始化
-
-
-
- /* USB Device handle structure */
- typedef struct _USBD_HandleTypeDef
- {
- uint8_t id;
- uint32_t dev_config;
- uint32_t dev_default_config;
- uint32_t dev_config_status;
- USBD_SpeedTypeDef dev_speed;
- USBD_EndpointTypeDef ep_in[16];
- USBD_EndpointTypeDef ep_out[16];
- __IO uint32_t ep0_state;
- uint32_t ep0_data_len;
- __IO uint8_t dev_state;
- __IO uint8_t dev_old_state;
- uint8_t dev_address;
- uint8_t dev_connection_status;
- uint8_t dev_test_mode;
- uint32_t dev_remote_wakeup;
- uint8_t ConfIdx;
-
- USBD_SetupReqTypedef request;
- USBD_DescriptorsTypeDef *pDesc;
- USBD_ClassTypeDef *pClass[USBD_MAX_SUPPORTED_CLASS];
- void *pClassData;
- void *pClassDataCmsit[USBD_MAX_SUPPORTED_CLASS];
- void *pUserData[USBD_MAX_SUPPORTED_CLASS];
- void *pData;
- void *pBosDesc;
- void *pConfDesc;
- uint32_t classId;
- uint32_t NumClasses;
- #ifdef USE_USBD_COMPOSITE
- USBD_CompositeElementTypeDef tclasslist[USBD_MAX_SUPPORTED_CLASS];
- #endif /* USE_USBD_COMPOSITE */
- } USBD_HandleTypeDef;
-
- 定义全局变量USBD_DescriptorsTypeDef HS_Desc,并赋值初始化
- /** @defgroup USBD_DESC_Private_Variables USBD_DESC_Private_Variables
- * @brief Private variables.
- * @{
- */
- USBD_DescriptorsTypeDef HS_Desc =
- {
- USBD_HS_DeviceDescriptor
- , USBD_HS_LangIDStrDescriptor
- , USBD_HS_ManufacturerStrDescriptor
- , USBD_HS_ProductStrDescriptor
- , USBD_HS_SerialStrDescriptor
- , USBD_HS_ConfigStrDescriptor
- , USBD_HS_InterfaceStrDescriptor
- #if (USBD_LPM_ENABLED == 1)
- , USBD_HS_USR_BOSDescriptor
- #endif /* (USBD_LPM_ENABLED == 1) */
- };
-
-
- //=====================================================//
- //=====================================================//
- /* USB Device descriptors structure */
- typedef struct
- {
- uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
- uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
- uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
- uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
- uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
- uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
- uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
- #if (USBD_CLASS_USER_STRING_DESC == 1)
- uint8_t *(*GetUserStrDescriptor)(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
- #endif /* USBD_CLASS_USER_STRING_DESC */
- #if ((USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1))
- uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
- #endif /* (USBD_LPM_ENABLED == 1U) || (USBD_CLASS_BOS_ENABLED == 1) */
- } USBD_DescriptorsTypeDef;
-
-
- //=====================================================//
- //=====================================================//
- /**
- * @brief Return the device descriptor
- * @param speed : Current device speed
- * @param length : Pointer to data length variable
- * @retval Pointer to descriptor buffer
- */
- uint8_t * USBD_HS_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
- {
- UNUSED(speed);
- *length = sizeof(USBD_HS_DeviceDesc);
- return USBD_HS_DeviceDesc;
- }
-
- /**
- * @brief Return the LangID string descriptor
- * @param speed : Current device speed
- * @param length : Pointer to data length variable
- * @retval Pointer to descriptor buffer
- */
- uint8_t * USBD_HS_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
- {
- UNUSED(speed);
- *length = sizeof(USBD_LangIDDesc);
- return USBD_LangIDDesc;
- }
-
- /**
- * @brief Return the product string descriptor
- * @param speed : current device speed
- * @param length : pointer to data length variable
- * @retval pointer to descriptor buffer
- */
- uint8_t * USBD_HS_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
- {
- if(speed == 0)
- {
- USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_HS, USBD_StrDesc, length);
- }
- else
- {
- USBD_GetString((uint8_t *)USBD_PRODUCT_STRING_HS, USBD_StrDesc, length);
- }
- return USBD_StrDesc;
- }
-
- /**
- * @brief Return the manufacturer string descriptor
- * @param speed : Current device speed
- * @param length : Pointer to data length variable
- * @retval Pointer to descriptor buffer
- */
- uint8_t * USBD_HS_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
- {
- UNUSED(speed);
- USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
- return USBD_StrDesc;
- }
-
- /**
- * @brief Return the serial number string descriptor
- * @param speed : Current device speed
- * @param length : Pointer to data length variable
- * @retval Pointer to descriptor buffer
- */
- uint8_t * USBD_HS_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
- {
- UNUSED(speed);
- *length = USB_SIZ_STRING_SERIAL;
- /* Update the serial number string descriptor with the data from the unique
- * ID */
- Get_SerialNum();
- /* USER CODE BEGIN USBD_HS_SerialStrDescriptor */
-
- /* USER CODE END USBD_HS_SerialStrDescriptor */
-
- return (uint8_t *) USBD_StringSerial;
- }
-
- /**
- * @brief Return the configuration string descriptor
- * @param speed : Current device speed
- * @param length : Pointer to data length variable
- * @retval Pointer to descriptor buffer
- */
- uint8_t * USBD_HS_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
- {
- if(speed == USBD_SPEED_HIGH)
- {
- USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_HS, USBD_StrDesc, length);
- }
- else
- {
- USBD_GetString((uint8_t *)USBD_CONFIGURATION_STRING_HS, USBD_StrDesc, length);
- }
- return USBD_StrDesc;
- }
-
- /**
- * @brief Return the interface string descriptor
- * @param speed : Current device speed
- * @param length : Pointer to data length variable
- * @retval Pointer to descriptor buffer
- */
- uint8_t * USBD_HS_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
- {
- if(speed == 0)
- {
- USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_HS, USBD_StrDesc, length);
- }
- else
- {
- USBD_GetString((uint8_t *)USBD_INTERFACE_STRING_HS, USBD_StrDesc, length);
- }
- return USBD_StrDesc;
- }
-
- #if (USBD_LPM_ENABLED == 1)
- /**
- * @brief Return the BOS descriptor
- * @param speed : Current device speed
- * @param length : Pointer to data length variable
- * @retval Pointer to descriptor buffer
- */
- uint8_t * USBD_HS_USR_BOSDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
- {
- UNUSED(speed);
- *length = sizeof(USBD_HS_BOSDesc);
- return (uint8_t*)USBD_HS_BOSDesc;
- }
- #endif /* (USBD_LPM_ENABLED == 1) */
-
- 全局宏定义,区分高速和全速USB
- /* #define for FS and HS identification */
- #define DEVICE_FS 0
- #define DEVICE_HS 1
/