summaryrefslogtreecommitdiff
path: root/bsp/at32/libraries/usbfs_library/inc
diff options
context:
space:
mode:
Diffstat (limited to 'bsp/at32/libraries/usbfs_library/inc')
-rw-r--r--bsp/at32/libraries/usbfs_library/inc/usb_core.h122
-rw-r--r--bsp/at32/libraries/usbfs_library/inc/usb_std.h368
-rw-r--r--bsp/at32/libraries/usbfs_library/inc/usbd_core.h176
-rw-r--r--bsp/at32/libraries/usbfs_library/inc/usbd_int.h85
-rw-r--r--bsp/at32/libraries/usbfs_library/inc/usbd_sdr.h65
-rw-r--r--bsp/at32/libraries/usbfs_library/inc/usbh_core.h367
-rw-r--r--bsp/at32/libraries/usbfs_library/inc/usbh_ctrl.h98
-rw-r--r--bsp/at32/libraries/usbfs_library/inc/usbh_int.h71
8 files changed, 1352 insertions, 0 deletions
diff --git a/bsp/at32/libraries/usbfs_library/inc/usb_core.h b/bsp/at32/libraries/usbfs_library/inc/usb_core.h
new file mode 100644
index 0000000000..de67131fde
--- /dev/null
+++ b/bsp/at32/libraries/usbfs_library/inc/usb_core.h
@@ -0,0 +1,122 @@
+/**
+ **************************************************************************
+ * @file usb_core.h
+ * @brief usb core header file
+ **************************************************************************
+ * Copyright notice & Disclaimer
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_CORE_H
+#define __USB_CORE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "usb_std.h"
+
+#ifdef USE_OTG_DEVICE_MODE
+#include "usbd_core.h"
+#endif
+#ifdef USE_OTG_HOST_MODE
+#include "usbh_core.h"
+#endif
+
+/** @addtogroup USB_drivers_core
+ * @{
+ */
+
+/** @defgroup USB_core_exported_types
+ * @{
+ */
+
+/**
+ * @brief usb core speed select
+ */
+typedef enum
+{
+ USB_LOW_SPEED_CORE_ID, /*!< usb low speed core id */
+ USB_FULL_SPEED_CORE_ID, /*!< usb full speed core id */
+ USB_HIGH_SPEED_CORE_ID, /*!< usb high speed core id */
+} usb_speed_type;
+
+/**
+ * @brief usb core cofig struct
+ */
+typedef struct
+{
+ uint8_t speed; /*!< otg speed */
+ uint8_t dma_en; /*!< dma enable state, not use*/
+ uint8_t hc_num; /*!< the otg host support number of channel */
+ uint8_t ept_num; /*!< the otg device support number of endpoint */
+
+ uint16_t max_size; /*!< support max packet size */
+ uint16_t fifo_size; /*!< the usb otg total file size */
+ uint8_t phy_itface; /*!< usb phy select */
+ uint8_t core_id; /*!< the usb otg core id */
+ uint8_t low_power; /*!< the usb otg low power option */
+ uint8_t sof_out; /*!< the sof signal output */
+ uint8_t usb_id; /*!< select otgfs1 or otgfs2 */
+ uint8_t vbusig; /*!< vbus ignore */
+} usb_core_cfg;
+
+/**
+ * @brief usb otg core struct type
+ */
+typedef struct
+{
+ usb_reg_type *usb_reg; /*!< the usb otg register type */
+#ifdef USE_OTG_DEVICE_MODE
+ usbd_core_type dev; /*!< the usb device core type */
+#endif
+
+#ifdef USE_OTG_HOST_MODE
+ usbh_core_type host; /*!< the usb host core type */
+#endif
+
+ usb_core_cfg cfg; /*!< the usb otg core config type */
+
+} otg_core_type;
+
+usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id);
+#ifdef USE_OTG_DEVICE_MODE
+usb_sts_type usbd_init(otg_core_type *udev,
+ uint8_t core_id, uint8_t usb_id);
+#endif
+
+#ifdef USE_OTG_HOST_MODE
+usb_sts_type usbh_init(otg_core_type *hdev,
+ uint8_t core_id, uint8_t usb_id);
+#endif
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/bsp/at32/libraries/usbfs_library/inc/usb_std.h b/bsp/at32/libraries/usbfs_library/inc/usb_std.h
new file mode 100644
index 0000000000..9cf57cf988
--- /dev/null
+++ b/bsp/at32/libraries/usbfs_library/inc/usb_std.h
@@ -0,0 +1,368 @@
+/**
+ **************************************************************************
+ * @file usb_std.h
+ * @brief usb standard header file
+ **************************************************************************
+ * Copyright notice & Disclaimer
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_STD_H
+#define __USB_STD_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* includes ------------------------------------------------------------------*/
+#include "drv_config.h"
+
+/** @addtogroup USB_standard
+ * @{
+ */
+
+/** @defgroup USB_standard_define
+ * @{
+ */
+
+/**
+ * @brief usb request recipient
+ */
+#define USB_REQ_RECIPIENT_DEVICE 0x00 /*!< usb request recipient device */
+#define USB_REQ_RECIPIENT_INTERFACE 0x01 /*!< usb request recipient interface */
+#define USB_REQ_RECIPIENT_ENDPOINT 0x02 /*!< usb request recipient endpoint */
+#define USB_REQ_RECIPIENT_OTHER 0x03 /*!< usb request recipient other */
+#define USB_REQ_RECIPIENT_MASK 0x1F /*!< usb request recipient mask */
+
+/**
+ * @brief usb request type
+ */
+#define USB_REQ_TYPE_STANDARD 0x00 /*!< usb request type standard */
+#define USB_REQ_TYPE_CLASS 0x20 /*!< usb request type class */
+#define USB_REQ_TYPE_VENDOR 0x40 /*!< usb request type vendor */
+#define USB_REQ_TYPE_RESERVED 0x60 /*!< usb request type reserved */
+
+/**
+ * @brief usb request data transfer direction
+ */
+#define USB_REQ_DIR_HTD 0x00 /*!< usb request data transfer direction host to device */
+#define USB_REQ_DIR_DTH 0x80 /*!< usb request data transfer direction device to host */
+
+/**
+ * @brief usb standard device requests codes
+ */
+#define USB_STD_REQ_GET_STATUS 0 /*!< usb request code status */
+#define USB_STD_REQ_CLEAR_FEATURE 1 /*!< usb request code clear feature */
+#define USB_STD_REQ_SET_FEATURE 3 /*!< usb request code feature */
+#define USB_STD_REQ_SET_ADDRESS 5 /*!< usb request code address */
+#define USB_STD_REQ_GET_DESCRIPTOR 6 /*!< usb request code get descriptor */
+#define USB_STD_REQ_SET_DESCRIPTOR 7 /*!< usb request code set descriptor */
+#define USB_STD_REQ_GET_CONFIGURATION 8 /*!< usb request code get configuration */
+#define USB_STD_REQ_SET_CONFIGURATION 9 /*!< usb request code set configuration */
+#define USB_STD_REQ_GET_INTERFACE 10 /*!< usb request code get interface */
+#define USB_STD_REQ_SET_INTERFACE 11 /*!< usb request code set interface */
+#define USB_STD_REQ_SYNCH_FRAME 12 /*!< usb request code synch frame */
+
+/**
+ * @brief usb standard device type
+ */
+#define USB_DESCIPTOR_TYPE_DEVICE 1 /*!< usb standard device type device */
+#define USB_DESCIPTOR_TYPE_CONFIGURATION 2 /*!< usb standard device type configuration */
+#define USB_DESCIPTOR_TYPE_STRING 3 /*!< usb standard device type string */
+#define USB_DESCIPTOR_TYPE_INTERFACE 4 /*!< usb standard device type interface */
+#define USB_DESCIPTOR_TYPE_ENDPOINT 5 /*!< usb standard device type endpoint */
+#define USB_DESCIPTOR_TYPE_DEVICE_QUALIFIER 6 /*!< usb standard device type qualifier */
+#define USB_DESCIPTOR_TYPE_OTHER_SPEED 7 /*!< usb standard device type other speed */
+#define USB_DESCIPTOR_TYPE_INTERFACE_POWER 8 /*!< usb standard device type interface power */
+
+/**
+ * @brief usb standard string type
+ */
+#define USB_LANGID_STRING 0 /*!< usb standard string type lang id */
+#define USB_MFC_STRING 1 /*!< usb standard string type mfc */
+#define USB_PRODUCT_STRING 2 /*!< usb standard string type product */
+#define USB_SERIAL_STRING 3 /*!< usb standard string type serial */
+#define USB_CONFIG_STRING 4 /*!< usb standard string type config */
+#define USB_INTERFACE_STRING 5 /*!< usb standard string type interface */
+
+/**
+ * @brief usb configuration attributes
+ */
+#define USB_CONF_REMOTE_WAKEUP 2 /*!< usb configuration attributes remote wakeup */
+#define USB_CONF_SELF_POWERED 1 /*!< usb configuration attributes self powered */
+
+/**
+ * @brief usb standard feature selectors
+ */
+#define USB_FEATURE_EPT_HALT 0 /*!< usb standard feature selectors endpoint halt */
+#define USB_FEATURE_REMOTE_WAKEUP 1 /*!< usb standard feature selectors remote wakeup */
+
+/**
+ * @brief usb device connect state
+ */
+typedef enum
+{
+ USB_CONN_STATE_DEFAULT =1, /*!< usb device connect state default */
+ USB_CONN_STATE_ADDRESSED, /*!< usb device connect state address */
+ USB_CONN_STATE_CONFIGURED, /*!< usb device connect state configured */
+ USB_CONN_STATE_SUSPENDED /*!< usb device connect state suspend */
+}usbd_conn_state;
+
+/**
+ * @brief endpoint 0 state
+ */
+#define USB_EPT0_IDLE 0 /*!< usb endpoint state idle */
+#define USB_EPT0_SETUP 1 /*!< usb endpoint state setup */
+#define USB_EPT0_DATA_IN 2 /*!< usb endpoint state data in */
+#define USB_EPT0_DATA_OUT 3 /*!< usb endpoint state data out */
+#define USB_EPT0_STATUS_IN 4 /*!< usb endpoint state status in */
+#define USB_EPT0_STATUS_OUT 5 /*!< usb endpoint state status out */
+#define USB_EPT0_STALL 6 /*!< usb endpoint state stall */
+
+/**
+ * @brief usb descriptor length
+ */
+#define USB_DEVICE_QUALIFIER_DESC_LEN 0x0A /*!< usb qualifier descriptor length */
+#define USB_DEVICE_DESC_LEN 0x12 /*!< usb device descriptor length */
+#define USB_DEVICE_CFG_DESC_LEN 0x09 /*!< usb configuration descriptor length */
+#define USB_DEVICE_IF_DESC_LEN 0x09 /*!< usb interface descriptor length */
+#define USB_DEVICE_EPT_LEN 0x07 /*!< usb endpoint descriptor length */
+#define USB_DEVICE_OTG_DESC_LEN 0x03 /*!< usb otg descriptor length */
+#define USB_DEVICE_LANGID_STR_DESC_LEN 0x04 /*!< usb lang id string descriptor length */
+#define USB_DEVICE_OTHER_SPEED_DESC_SIZ_LEN 0x09 /*!< usb other speed descriptor length */
+
+/**
+ * @brief usb class code
+ */
+#define USB_CLASS_CODE_AUDIO 0x01 /*!< usb class code audio */
+#define USB_CLASS_CODE_CDC 0x02 /*!< usb class code cdc */
+#define USB_CLASS_CODE_HID 0x03 /*!< usb class code hid */
+#define USB_CLASS_CODE_PRINTER 0x07 /*!< usb class code printer */
+#define USB_CLASS_CODE_MSC 0x08 /*!< usb class code msc */
+#define USB_CLASS_CODE_HUB 0x09 /*!< usb class code hub */
+#define USB_CLASS_CODE_CDCDATA 0x0A /*!< usb class code cdc data */
+#define USB_CLASS_CODE_CCID 0x0B /*!< usb class code ccid */
+#define USB_CLASS_CODE_VIDEO 0x0E /*!< usb class code video */
+#define USB_CLASS_CODE_VENDOR 0xFF /*!< usb class code vendor */
+
+/**
+ * @brief usb endpoint type
+ */
+#define USB_EPT_DESC_CONTROL 0x00 /*!< usb endpoint description type control */
+#define USB_EPT_DESC_ISO 0x01 /*!< usb endpoint description type iso */
+#define USB_EPT_DESC_BULK 0x02 /*!< usb endpoint description type bulk */
+#define USB_EPT_DESC_INTERRUPT 0x03 /*!< usb endpoint description type interrupt */
+
+#define USB_EPT_DESC_NSYNC 0x00 /*!< usb endpoint description nsync */
+#define USB_ETP_DESC_ASYNC 0x04 /*!< usb endpoint description async */
+#define USB_ETP_DESC_ADAPTIVE 0x08 /*!< usb endpoint description adaptive */
+#define USB_ETP_DESC_SYNC 0x0C /*!< usb endpoint description sync */
+
+#define USB_EPT_DESC_DATA_EPT 0x00 /*!< usb endpoint description data */
+#define USB_EPT_DESC_FD_EPT 0x10 /*!< usb endpoint description fd */
+#define USB_EPT_DESC_FDDATA_EPT 0x20 /*!< usb endpoint description fddata */
+
+/**
+ * @brief usb cdc class descriptor define
+ */
+#define USBD_CDC_CS_INTERFACE 0x24
+#define USBD_CDC_CS_ENDPOINT 0x25
+
+/**
+ * @brief usb cdc class sub-type define
+ */
+#define USBD_CDC_SUBTYPE_HEADER 0x00
+#define USBD_CDC_SUBTYPE_CMF 0x01
+#define USBD_CDC_SUBTYPE_ACM 0x02
+#define USBD_CDC_SUBTYPE_UFD 0x06
+
+/**
+ * @brief usb cdc class request code define
+ */
+#define SET_LINE_CODING 0x20
+#define GET_LINE_CODING 0x21
+
+/**
+ * @brief usb cdc class set line coding struct
+ */
+typedef struct
+{
+ uint32_t bitrate; /* line coding baud rate */
+ uint8_t format; /* line coding foramt */
+ uint8_t parity; /* line coding parity */
+ uint8_t data; /* line coding data bit */
+}linecoding_type;
+
+/**
+ * @brief usb hid class descriptor define
+ */
+#define HID_CLASS_DESC_HID 0x21
+#define HID_CLASS_DESC_REPORT 0x22
+#define HID_CLASS_DESC_PHYSICAL 0x23
+
+/**
+ * @brief usb hid class request code define
+ */
+#define HID_REQ_SET_PROTOCOL 0x0B
+#define HID_REQ_GET_PROTOCOL 0x03
+#define HID_REQ_SET_IDLE 0x0A
+#define HID_REQ_GET_IDLE 0x02
+#define HID_REQ_SET_REPORT 0x09
+#define HID_REQ_GET_REPORT 0x01
+#define HID_DESCRIPTOR_TYPE 0x21
+#define HID_REPORT_DESC 0x22
+
+/**
+ * @brief endpoint 0 max size
+ */
+#define USB_MAX_EP0_SIZE 64 /*!< usb endpoint 0 max size */
+
+/**
+ * @brief usb swap address
+ */
+#define SWAPBYTE(addr) (uint16_t)(((uint16_t)(*((uint8_t *)(addr)))) + \
+ (((uint16_t)(*(((uint8_t *)(addr)) + 1))) << 8)) /*!< swap address */
+
+/**
+ * @brief low byte and high byte define
+ */
+#define LBYTE(x) ((uint8_t)(x & 0x00FF)) /*!< low byte define */
+#define HBYTE(x) ((uint8_t)((x & 0xFF00) >>8)) /*!< high byte define*/
+
+/**
+ * @brief usb return status
+ */
+typedef enum
+{
+ USB_OK, /*!< usb status ok */
+ USB_FAIL, /*!< usb status fail */
+ USB_WAIT, /*!< usb status wait */
+ USB_NOT_SUPPORT, /*!< usb status not support */
+ USB_ERROR, /*!< usb status error */
+}usb_sts_type;
+
+
+/**
+ * @brief format of usb setup data
+ */
+typedef struct
+{
+ uint8_t bmRequestType; /*!< characteristics of request */
+ uint8_t bRequest; /*!< specific request */
+ uint16_t wValue; /*!< word-sized field that varies according to request */
+ uint16_t wIndex; /*!< word-sized field that varies according to request
+ typically used to pass an index or offset */
+ uint16_t wLength; /*!< number of bytes to transfer if there is a data stage */
+} usb_setup_type;
+
+/**
+ * @brief format of standard device descriptor
+ */
+typedef struct
+{
+ uint8_t bLength; /*!< size of this descriptor in bytes */
+ uint8_t bDescriptorType; /*!< device descriptor type */
+ uint16_t bcdUSB; /*!< usb specification release number */
+ uint8_t bDeviceClass; /*!< class code (assigned by the usb-if) */
+ uint8_t bDeviceSubClass; /*!< subclass code (assigned by the usb-if) */
+ uint8_t bDeviceProtocol; /*!< protocol code ((assigned by the usb-if)) */
+ uint8_t bMaxPacketSize0; /*!< maximum packet size for endpoint zero */
+ uint16_t idVendor; /*!< verndor id ((assigned by the usb-if)) */
+ uint16_t idProduct; /*!< product id ((assigned by the usb-if)) */
+ uint16_t bcdDevice; /*!< device release number in binary-coded decimal */
+ uint8_t iManufacturer; /*!< index of string descriptor describing manufacturer */
+ uint8_t iProduct; /*!< index of string descriptor describing product */
+ uint8_t iSerialNumber; /*!< index of string descriptor describing serial number */
+ uint8_t bNumConfigurations; /*!< number of possible configurations */
+} usb_device_desc_type;
+
+/**
+ * @brief format of standard configuration descriptor
+ */
+typedef struct
+{
+ uint8_t bLength; /*!< size of this descriptor in bytes */
+ uint8_t bDescriptorType; /*!< configuration descriptor type */
+ uint16_t wTotalLength; /*!< total length of data returned for this configuration */
+ uint8_t bNumInterfaces; /*!< number of interfaces supported by this configuration */
+ uint8_t bConfigurationValue; /*!< value to use as an argument to the SetConfiguration() request */
+ uint8_t iConfiguration; /*!< index of string descriptor describing this configuration */
+ uint8_t bmAttributes; /*!< configuration characteristics
+ D7 reserved
+ D6 self-powered
+ D5 remote wakeup
+ D4~D0 reserved */
+ uint8_t bMaxPower; /*!< maximum power consumption of the usb device from the bus */
+
+
+}usb_configuration_desc_type;
+
+/**
+ * @brief format of standard interface descriptor
+ */
+typedef struct
+{
+ uint8_t bLength; /*!< size of this descriptor in bytes */
+ uint8_t bDescriptorType; /*!< interface descriptor type */
+ uint8_t bInterfaceNumber; /*!< number of this interface */
+ uint8_t bAlternateSetting; /*!< value used to select this alternate setting for the interface */
+ uint8_t bNumEndpoints; /*!< number of endpoints used by this interface */
+ uint8_t bInterfaceClass; /*!< class code (assigned by the usb-if) */
+ uint8_t bInterfaceSubClass; /*!< subclass code (assigned by the usb-if) */
+ uint8_t bInterfaceProtocol; /*!< protocol code (assigned by the usb-if) */
+ uint8_t iInterface; /*!< index of string descriptor describing this interface */
+} usb_interface_desc_type;
+
+/**
+ * @brief format of standard endpoint descriptor
+ */
+typedef struct
+{
+ uint8_t bLength; /*!< size of this descriptor in bytes */
+ uint8_t bDescriptorType; /*!< endpoint descriptor type */
+ uint8_t bEndpointAddress; /*!< the address of the endpoint on the usb device described by this descriptor */
+ uint8_t bmAttributes; /*!< describes the endpoints attributes when it is configured using bConfiguration value */
+ uint16_t wMaxPacketSize; /*!< maximum packet size this endpoint */
+ uint8_t bInterval; /*!< interval for polling endpoint for data transfers */
+} usb_endpoint_desc_type;
+
+/**
+ * @brief format of header
+ */
+typedef struct
+{
+ uint8_t bLength; /*!< size of this descriptor in bytes */
+ uint8_t bDescriptorType; /*!< descriptor type */
+} usb_header_desc_type;
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/bsp/at32/libraries/usbfs_library/inc/usbd_core.h b/bsp/at32/libraries/usbfs_library/inc/usbd_core.h
new file mode 100644
index 0000000000..74f521e17b
--- /dev/null
+++ b/bsp/at32/libraries/usbfs_library/inc/usbd_core.h
@@ -0,0 +1,176 @@
+/**
+ **************************************************************************
+ * @file usbd_core.h
+ * @brief usb device core header file
+ **************************************************************************
+ * Copyright notice & Disclaimer
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USBD_CORE_H
+#define __USBD_CORE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "usb_std.h"
+
+/** @addtogroup USBD_drivers_core
+ * @{
+ */
+
+/** @defgroup USBD_core_exported_types
+ * @{
+ */
+
+#ifdef USE_OTG_DEVICE_MODE
+
+/**
+ * @brief usb device event
+ */
+typedef enum
+{
+ USBD_NOP_EVENT, /*!< usb device nop event */
+ USBD_RESET_EVENT, /*!< usb device reset event */
+ USBD_SUSPEND_EVENT, /*!< usb device suspend event */
+ USBD_WAKEUP_EVENT, /*!< usb device wakeup event */
+ USBD_DISCONNECT_EVNET, /*!< usb device disconnect event */
+ USBD_INISOINCOM_EVENT, /*!< usb device inisoincom event */
+ USBD_OUTISOINCOM_EVENT, /*!< usb device outisoincom event */
+ USBD_ERR_EVENT /*!< usb device error event */
+}usbd_event_type;
+
+/**
+ * @brief usb device descriptor struct
+ */
+typedef struct
+{
+ uint16_t length; /*!< descriptor length */
+ uint8_t *descriptor; /*!< descriptor string */
+}usbd_desc_t;
+
+/**
+ * @brief usb device descriptor handler
+ */
+typedef struct
+{
+ usbd_desc_t *(*get_device_descriptor)(void); /*!< get device descriptor callback */
+ usbd_desc_t *(*get_device_qualifier)(void); /*!< get device qualifier callback */
+ usbd_desc_t *(*get_device_configuration)(void); /*!< get device configuration callback */
+ usbd_desc_t *(*get_device_other_speed)(void); /*!< get device other speed callback */
+ usbd_desc_t *(*get_device_lang_id)(void); /*!< get device lang id callback */
+ usbd_desc_t *(*get_device_manufacturer_string)(void); /*!< get device manufacturer callback */
+ usbd_desc_t *(*get_device_product_string)(void); /*!< get device product callback */
+ usbd_desc_t *(*get_device_serial_string)(void); /*!< get device serial callback */
+ usbd_desc_t *(*get_device_interface_string)(void); /*!< get device interface string callback */
+ usbd_desc_t *(*get_device_config_string)(void); /*!< get device device config callback */
+}usbd_desc_handler;
+
+/**
+ * @brief usb device class handler
+ */
+typedef struct
+{
+ usb_sts_type (*init_handler)(void *udev); /*!< usb class init handler */
+ usb_sts_type (*clear_handler)(void *udev); /*!< usb class clear handler */
+ usb_sts_type (*setup_handler)(void *udev, usb_setup_type *setup); /*!< usb class setup handler */
+ usb_sts_type (*ept0_tx_handler)(void *udev); /*!< usb class endpoint 0 tx complete handler */
+ usb_sts_type (*ept0_rx_handler)(void *udev); /*!< usb class endpoint 0 rx complete handler */
+ usb_sts_type (*in_handler)(void *udev, uint8_t ept_num); /*!< usb class in transfer complete handler */
+ usb_sts_type (*out_handler)(void *udev, uint8_t ept_num); /*!< usb class out transfer complete handler */
+ usb_sts_type (*sof_handler)(void *udev); /*!< usb class sof handler */
+ usb_sts_type (*event_handler)(void *udev, usbd_event_type event); /*!< usb class event handler */
+ void *pdata; /*!< usb class data pointer */
+}usbd_class_handler;
+
+/**
+ * @brief usb device core struct type
+ */
+typedef struct
+{
+ usb_reg_type *usb_reg; /*!< usb register pointer */
+
+ usbd_class_handler *class_handler; /*!< usb device class handler pointer */
+ usbd_desc_handler *desc_handler; /*!< usb device descriptor handler pointer */
+
+ usb_ept_info ept_in[USB_EPT_MAX_NUM]; /*!< usb in endpoint infomation struct */
+ usb_ept_info ept_out[USB_EPT_MAX_NUM]; /*!< usb out endpoint infomation struct */
+
+ usb_setup_type setup; /*!< usb setup type struct */
+ uint8_t setup_buffer[12]; /*!< usb setup request buffer */
+
+ uint8_t ept0_sts; /*!< usb control endpoint 0 state */
+ uint8_t speed; /*!< usb speed */
+ uint16_t ept0_wlength; /*!< usb endpoint 0 transfer length */
+
+ usbd_conn_state conn_state; /*!< usb current connect state */
+ usbd_conn_state old_conn_state; /*!< usb save the previous connect state */
+
+ uint8_t device_addr; /*!< device address */
+ uint8_t remote_wakup; /*!< remote wakeup state */
+ uint8_t default_config; /*!< usb default config state */
+ uint8_t dev_config; /*!< usb device config state */
+ uint32_t config_status; /*!< usb configure status */
+
+ void *pdata;
+}usbd_core_type;
+
+void usbd_core_in_handler(usbd_core_type *udev, uint8_t ept_num);
+void usbd_core_out_handler(usbd_core_type *udev, uint8_t ept_num);
+void usbd_core_setup_handler(usbd_core_type *udev, uint8_t ept_num);
+void usbd_ctrl_unsupport(usbd_core_type *udev);
+void usbd_ctrl_send(usbd_core_type *udev, uint8_t *buffer, uint16_t len);
+void usbd_ctrl_recv(usbd_core_type *udev, uint8_t *buffer, uint16_t len);
+void usbd_ctrl_send_status(usbd_core_type *udev);
+void usbd_ctrl_recv_status(usbd_core_type *udev);
+void usbd_set_stall(usbd_core_type *udev, uint8_t ept_addr);
+void usbd_clear_stall(usbd_core_type *udev, uint8_t ept_addr);
+void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uint16_t maxpacket);
+void usbd_ept_close(usbd_core_type *udev, uint8_t ept_addr);
+void usbd_ept_send(usbd_core_type *udev, uint8_t ept_num, uint8_t *buffer, uint16_t len);
+void usbd_ept_recv(usbd_core_type *udev, uint8_t ept_num, uint8_t *buffer, uint16_t len);
+void usbd_connect(usbd_core_type *udev);
+void usbd_disconnect(usbd_core_type *udev);
+void usbd_set_device_addr(usbd_core_type *udev, uint8_t address);
+uint32_t usbd_get_recv_len(usbd_core_type *udev, uint8_t ept_addr);
+void usb_ept_defaut_init(usbd_core_type *udev);
+usbd_conn_state usbd_connect_state_get(usbd_core_type *udev);
+void usbd_remote_wakeup(usbd_core_type *udev);
+void usbd_enter_suspend(usbd_core_type *udev);
+void usbd_flush_tx_fifo(usbd_core_type *udev, uint8_t ept_num);
+void usbd_fifo_alloc(usbd_core_type *udev);
+usb_sts_type usbd_core_init(usbd_core_type *udev,
+ usb_reg_type *usb_reg,
+ uint8_t core_id);
+#endif
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/at32/libraries/usbfs_library/inc/usbd_int.h b/bsp/at32/libraries/usbfs_library/inc/usbd_int.h
new file mode 100644
index 0000000000..95f645ee59
--- /dev/null
+++ b/bsp/at32/libraries/usbfs_library/inc/usbd_int.h
@@ -0,0 +1,85 @@
+/**
+ **************************************************************************
+ * @file usbd_int.h
+ * @brief usb interrupt header file
+ **************************************************************************
+ * Copyright notice & Disclaimer
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USBD_INT_H
+#define __USBD_INT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* includes ------------------------------------------------------------------*/
+#include "usbd_core.h"
+#include "usb_core.h"
+
+#ifdef USE_OTG_DEVICE_MODE
+
+/** @addtogroup USBD_drivers_int
+ * @{
+ */
+
+/** @defgroup USBD_interrupt_exported_types
+ * @{
+ */
+
+void usbd_irq_handler(otg_core_type *udev);
+void usbd_ept_handler(usbd_core_type *udev);
+void usbd_reset_handler(usbd_core_type *udev);
+void usbd_sof_handler(usbd_core_type *udev);
+void usbd_suspend_handler(usbd_core_type *udev);
+void usbd_wakeup_handler(usbd_core_type *udev);
+void usbd_inept_handler(usbd_core_type *udev);
+void usbd_outept_handler(usbd_core_type *udev);
+void usbd_enumdone_handler(usbd_core_type *udev);
+void usbd_rxflvl_handler(usbd_core_type *udev);
+void usbd_incomisioin_handler(usbd_core_type *udev);
+void usbd_discon_handler(usbd_core_type *udev);
+void usbd_incomisoout_handler(usbd_core_type *udev);
+void usb_write_empty_txfifo(usbd_core_type *udev, uint32_t ept_num);
+
+/* callback for rt-thread */
+void usbd_reset_callback(usbd_core_type *udev);
+void usbd_setup_phase_done_callback(usbd_core_type *udev);
+void usbd_data_in_stage_callback(usbd_core_type *udev, uint32_t ept_num);
+void usbd_sof_callback(usbd_core_type *udev);
+void usbd_data_out_stage_callback(usbd_core_type *udev, uint32_t ept_num);
+void usbd_connectCallback(usbd_core_type *udev);
+void usbd_disconnectCallback(usbd_core_type *udev);
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#endif
diff --git a/bsp/at32/libraries/usbfs_library/inc/usbd_sdr.h b/bsp/at32/libraries/usbfs_library/inc/usbd_sdr.h
new file mode 100644
index 0000000000..a95e67a475
--- /dev/null
+++ b/bsp/at32/libraries/usbfs_library/inc/usbd_sdr.h
@@ -0,0 +1,65 @@
+/**
+ **************************************************************************
+ * @file usb_sdr.h
+ * @brief usb header file
+ **************************************************************************
+ * Copyright notice & Disclaimer
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USB_SDR_H
+#define __USB_SDR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* includes ------------------------------------------------------------------*/
+#include "usb_core.h"
+
+#ifdef USE_OTG_DEVICE_MODE
+
+/** @addtogroup USBD_drivers_standard_request
+ * @{
+ */
+
+/** @defgroup USBD_sdr_exported_functions
+ * @{
+ */
+
+void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf);
+usb_sts_type usbd_device_request(usbd_core_type *udev);
+usb_sts_type usbd_interface_request(usbd_core_type *udev);
+usb_sts_type usbd_endpoint_request(usbd_core_type *udev);
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#endif
diff --git a/bsp/at32/libraries/usbfs_library/inc/usbh_core.h b/bsp/at32/libraries/usbfs_library/inc/usbh_core.h
new file mode 100644
index 0000000000..333dee5a01
--- /dev/null
+++ b/bsp/at32/libraries/usbfs_library/inc/usbh_core.h
@@ -0,0 +1,367 @@
+/**
+ **************************************************************************
+ * @file usbh_core.h
+ * @brief usb host core header file
+ **************************************************************************
+ * Copyright notice & Disclaimer
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USBH_CORE_H
+#define __USBH_CORE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "usb_std.h"
+
+/** @addtogroup USBH_drivers_core
+ * @{
+ */
+
+/** @defgroup USBH_core_exported_types
+ * @{
+ */
+
+#ifdef USE_OTG_HOST_MODE
+
+/**
+ * @brief usb channel flag
+ */
+typedef enum
+{
+ HCH_IDLE, /*!< usb host channel idle */
+ HCH_XFRC, /*!< usb host channel transfer completed */
+ HCH_HALTED, /*!< usb host channel halted */
+ HCH_NAK, /*!< usb host channel nak */
+ HCH_NYET, /*!< usb host channel nyet */
+ HCH_STALL, /*!< usb host channel stall */
+ HCH_XACTERR, /*!< usb host channel transaction error */
+ HCH_BBLERR, /*!< usb host channel babble error */
+ HCH_DATATGLERR /*!< usb host channel data toggle error */
+} hch_sts_type;
+
+/**
+ * @brief usb channel state
+ */
+typedef enum
+{
+ URB_IDLE = 0, /*!< usb request idle state */
+ URB_DONE, /*!< usb request done state */
+ URB_NOTREADY, /*!< usb request not ready state */
+ URB_NYET, /*!< usb request nyet stat e*/
+ URB_ERROR, /*!< usb request error state */
+ URB_STALL /*!< usb request stall state */
+} urb_sts_type;
+
+/**
+ * @brief usb control channel flag
+ */
+typedef enum
+{
+ CTRL_START = 0, /*!< usb control request start */
+ CTRL_XFERC, /*!< usb control request completed */
+ CTRL_HALTED, /*!< usb control request halted */
+ CTRL_NAK, /*!< usb control request nak */
+ CTRL_STALL, /*!< usb control request stall */
+ CTRL_XACTERR, /*!< usb control request transaction error */
+ CTRL_BBLERR, /*!< usb control request babble error */
+ CTRL_DATATGLERR, /*!< usb control request data toggle error */
+ CTRL_FAIL /*!< usb control request failed */
+} ctrl_sts_type;
+
+/**
+ * @brief usb host control state machine
+ */
+typedef enum
+{
+ CONTROL_IDLE, /*!< usb control state idle */
+ CONTROL_SETUP, /*!< usb control state setup */
+ CONTROL_SETUP_WAIT, /*!< usb control state setup wait */
+ CONTROL_DATA_IN, /*!< usb control state data in */
+ CONTROL_DATA_IN_WAIT, /*!< usb control state data in wait */
+ CONTROL_DATA_OUT, /*!< usb control state data out */
+ CONTROL_DATA_OUT_WAIT, /*!< usb control state data out wait */
+ CONTROL_STATUS_IN, /*!< usb control state status in */
+ CONTROL_STATUS_IN_WAIT, /*!< usb control state status in wait */
+ CONTROL_STATUS_OUT, /*!< usb control state out */
+ CONTROL_STATUS_OUT_WAIT, /*!< usb control state out wait */
+ CONTROL_ERROR, /*!< usb control state error */
+ CONTROL_STALL, /*!< usb control state stall */
+ CONTROL_COMPLETE /*!< usb control state complete */
+} ctrl_ept0_sts_type;
+
+/**
+ * @brief usb host enumration state machine
+ */
+typedef enum
+{
+ ENUM_IDLE, /*!< usb host enumration state idle */
+ ENUM_GET_MIN_DESC, /*!< usb host enumration state get descriptor 8 byte*/
+ ENUM_GET_FULL_DESC, /*!< usb host enumration state get descriptor 18 byte*/
+ ENUM_SET_ADDR, /*!< usb host enumration state set address */
+ ENUM_GET_CFG, /*!< usb host enumration state get configuration */
+ ENUM_GET_FULL_CFG, /*!< usb host enumration state get full configuration */
+ ENUM_GET_MFC_STRING, /*!< usb host enumration state get manufacturer string */
+ ENUM_GET_PRODUCT_STRING, /*!< usb host enumration state get product string */
+ ENUM_GET_SERIALNUM_STRING, /*!< usb host enumration state get serial number string */
+ ENUM_SET_CONFIG, /*!< usb host enumration state set config */
+ ENUM_COMPLETE, /*!< usb host enumration state complete */
+} usbh_enum_sts_type;
+
+/**
+ * @brief usb host global state machine
+ */
+typedef enum
+{
+ USBH_IDLE, /*!< usb host global state idle */
+ USBH_PORT_EN, /*!< usb host global state port enable */
+ USBH_ATTACHED, /*!< usb host global state attached */
+ USBH_DISCONNECT, /*!< usb host global state disconnect */
+ USBH_DEV_SPEED, /*!< usb host global state device speed */
+ USBH_ENUMERATION, /*!< usb host global state enumeration */
+ USBH_CLASS_REQUEST, /*!< usb host global state class request */
+ USBH_CLASS, /*!< usb host global state class */
+ USBH_CTRL_XFER, /*!< usb host global state control transfer */
+ USBH_USER_HANDLER, /*!< usb host global state user handler */
+ USBH_SUSPEND, /*!< usb host global state suspend */
+ USBH_SUSPENDED, /*!< usb host have in suspend mode */
+ USBH_WAKEUP, /*!< usb host global state wakeup */
+ USBH_UNSUPPORT, /*!< usb host global unsupport device */
+ USBH_ERROR_STATE, /*!< usb host global state error */
+} usbh_gstate_type;
+
+/**
+ * @brief usb host transfer state
+ */
+typedef enum
+{
+ CMD_IDLE, /*!< usb host transfer state idle */
+ CMD_SEND, /*!< usb host transfer state send */
+ CMD_WAIT /*!< usb host transfer state wait */
+} cmd_sts_type;
+
+/**
+ * @brief usb host channel malloc state
+ */
+#define HCH_OK 0x0000 /*!< usb channel malloc state ok */
+#define HCH_USED 0x8000 /*!< usb channel had used */
+#define HCH_ERROR 0xFFFF /*!< usb channel error */
+#define HCH_USED_MASK 0x7FFF /*!< usb channel use mask */
+
+/**
+ * @brief channel pid
+ */
+#define HCH_PID_DATA0 0 /*!< usb channel pid data 0 */
+#define HCH_PID_DATA2 1 /*!< usb channel pid data 2 */
+#define HCH_PID_DATA1 2 /*!< usb channel pid data 1 */
+#define HCH_PID_SETUP 3 /*!< usb channel pid setup */
+
+/**
+ * @brief channel data transfer direction
+ */
+#define USB_REQUEST_DIR_MASK 0x80 /*!< usb request direction mask */
+#define USB_DIR_H2D USB_REQ_DIR_HTD /*!< usb request direction host to device */
+#define USB_DIR_D2H USB_REQ_DIR_DTH /*!< usb request direction device to host */
+
+/**
+ * @brief request timeout
+ */
+#define DATA_STAGE_TIMEOUT 5000 /*!< usb data stage timeout */
+#define NODATA_STAGE_TIMEOUT 50 /*!< usb no-data stage timeout */
+
+/**
+ * @brief max interface and endpoint
+ */
+#define USBH_MAX_ERROR_COUNT 2 /*!< usb support maximum error */
+#define USBH_MAX_INTERFACE 5 /*!< usb support maximum interface */
+#define USBH_MAX_ENDPOINT 5 /*!< usb support maximum endpoint */
+
+/**
+ * @brief interface descriptor
+ */
+typedef struct
+{
+ usb_interface_desc_type interface; /*!< usb device interface descriptor structure */
+ usb_endpoint_desc_type endpoint[USBH_MAX_ENDPOINT]; /*!< usb device endpoint descriptor structure array */
+} usb_itf_desc_type;
+
+/**
+ * @brief configure descriptor
+ */
+typedef struct
+{
+ usb_configuration_desc_type cfg; /*!< usb device configuration descriptor structure */
+ usb_itf_desc_type interface[USBH_MAX_INTERFACE]; /*!< usb device interface descriptor structure array*/
+} usb_cfg_desc_type;
+
+/**
+ * @brief device descriptor
+ */
+typedef struct
+{
+ uint8_t address; /*!< usb device address */
+ uint8_t speed; /*!< usb device speed */
+ usb_device_desc_type dev_desc; /*!< usb device descriptor */
+ usb_cfg_desc_type cfg_desc; /*!< usb device configuration */
+} usbh_dev_desc_type;
+
+/**
+ * @brief usb host control struct type
+ */
+typedef struct
+{
+ uint8_t hch_in; /*!< in channel number */
+ uint8_t hch_out; /*!< out channel number */
+ uint8_t ept0_size; /*!< endpoint 0 size */
+ uint8_t *buffer; /*!< endpoint 0 transfer buffer */
+ usb_setup_type setup; /*!< control setup type */
+ uint16_t len; /*!< transfer length */
+ uint8_t err_cnt; /*!< error counter */
+ uint32_t timer; /*!< transfer timer */
+ ctrl_sts_type sts; /*!< control transfer status */
+ ctrl_ept0_sts_type state; /*!< endpoint 0 state */
+} usbh_ctrl_type;
+
+/**
+ * @brief host class handler type
+ */
+typedef struct
+{
+ usb_sts_type (*init_handler)(void *uhost); /*!< usb host class init handler */
+ usb_sts_type (*reset_handler)(void *uhost); /*!< usb host class reset handler */
+ usb_sts_type (*request_handler)(void *uhost); /*!< usb host class request handler */
+ usb_sts_type (*process_handler)(void *uhost); /*!< usb host class process handler */
+ void *pdata; /*!< usb host class data */
+} usbh_class_handler_type;
+
+/**
+ * @brief host user handler type
+ */
+typedef struct
+{
+ usb_sts_type (*user_init)(void); /*!< usb host user init handler */
+ usb_sts_type (*user_reset)(void); /*!< usb host user reset handler */
+ usb_sts_type (*user_attached)(void); /*!< usb host user attached handler */
+ usb_sts_type (*user_disconnect)(void); /*!< usb host user disconnect handler */
+ usb_sts_type (*user_speed)(uint8_t speed); /*!< usb host user speed handler */
+ usb_sts_type (*user_mfc_string)(void *); /*!< usb host user manufacturer string handler */
+ usb_sts_type (*user_product_string)(void *); /*!< usb host user product string handler */
+ usb_sts_type (*user_serial_string)(void *); /*!< usb host user serial handler */
+ usb_sts_type (*user_enumeration_done)(void); /*!< usb host user enumeration done handler */
+ usb_sts_type (*user_application)(void); /*!< usb host user application handler */
+ usb_sts_type (*user_active_vbus)(void *uhost, confirm_state state); /*!< usb host user active vbus */
+ usb_sts_type (*user_not_support)(void); /*!< usb host user not support handler */
+} usbh_user_handler_type;
+
+/**
+ * @brief host host core handler type
+ */
+typedef struct
+{
+ usb_reg_type *usb_reg; /*!< usb register pointer */
+
+ uint8_t global_state; /*!< usb host global state machine */
+ uint8_t enum_state; /*!< usb host enumeration state machine */
+ uint8_t req_state; /*!< usb host request state machine */
+
+ usbh_dev_desc_type dev; /*!< usb device descriptor */
+ usbh_ctrl_type ctrl; /*!< usb host control transfer struct */
+
+ usbh_class_handler_type *class_handler; /*!< usb host class handler pointer */
+ usbh_user_handler_type *user_handler; /*!< usb host user handler pointer */
+
+ usb_hch_type hch[USB_HOST_CHANNEL_NUM]; /*!< usb host channel array */
+ uint8_t rx_buffer[USB_MAX_DATA_LENGTH]; /*!< usb host rx buffer */
+
+ uint32_t conn_sts; /*!< connect status */
+ uint32_t port_enable; /*!< port enable status */
+ uint32_t timer; /*!< sof timer */
+
+ uint32_t err_cnt[USB_HOST_CHANNEL_NUM]; /*!< error counter */
+ uint32_t xfer_cnt[USB_HOST_CHANNEL_NUM]; /*!< xfer counter */
+ hch_sts_type hch_state[USB_HOST_CHANNEL_NUM];/*!< channel state */
+ urb_sts_type urb_state[USB_HOST_CHANNEL_NUM];/*!< usb request state */
+ uint16_t channel[USB_HOST_CHANNEL_NUM]; /*!< channel array */
+
+ void *pdata;
+} usbh_core_type;
+
+
+void usbh_free_channel(usbh_core_type *uhost, uint8_t index);
+uint16_t usbh_get_free_channel(usbh_core_type *uhost);
+usb_sts_type usbh_set_toggle(usbh_core_type *uhost, uint8_t hc_num, uint8_t toggle);
+usb_sts_type usbh_in_out_request(usbh_core_type *uhost, uint8_t hc_num);
+usb_sts_type usbh_interrupt_recv(usbh_core_type *uhost, uint8_t hc_num,
+ uint8_t *buffer, uint16_t length);
+usb_sts_type usbh_interrupt_send(usbh_core_type *uhost, uint8_t hc_num,
+ uint8_t *buffer, uint16_t length);
+usb_sts_type usbh_bulk_recv(usbh_core_type *uhost, uint8_t hc_num,
+ uint8_t *buffer, uint16_t length);
+usb_sts_type usbh_bulk_send(usbh_core_type *uhost, uint8_t hc_num,
+ uint8_t *buffer, uint16_t length);
+usb_sts_type usbh_isoc_send(usbh_core_type *uhost, uint8_t hc_num,
+ uint8_t *buffer, uint16_t length);
+usb_sts_type usbh_isoc_recv(usbh_core_type *uhost, uint8_t hc_num,
+ uint8_t *buffer, uint16_t length);
+usb_sts_type usbh_cfg_default_init(usbh_core_type *uhost);
+void usbh_enter_suspend(usbh_core_type *uhost);
+void usbh_resume(usbh_core_type *uhost);
+
+uint16_t usbh_alloc_channel(usbh_core_type *uhost, uint8_t ept_addr);
+urb_sts_type usbh_get_urb_status(usbh_core_type *uhost, uint8_t ch_num);
+usb_sts_type usbh_ctrl_result_check(usbh_core_type *uhost,
+ ctrl_ept0_sts_type next_ctrl_state,
+ uint8_t next_enum_state);
+uint8_t usbh_alloc_address(void);
+void usbh_reset_port(usbh_core_type *uhost);
+usb_sts_type usbh_loop_handler(usbh_core_type *uhost);
+void usbh_ch_disable(usbh_core_type *uhost, uint8_t chn);
+void usbh_hc_open(usbh_core_type *uhost,
+ uint8_t chn,
+ uint8_t ept_num,
+ uint8_t dev_address,
+ uint8_t type,
+ uint16_t maxpacket,
+ uint8_t speed);
+void usbh_active_vbus(usbh_core_type *uhost, confirm_state state);
+
+usb_sts_type usbh_core_init(usbh_core_type *uhost,
+ usb_reg_type *usb_reg,
+ uint8_t core_id);
+
+hch_sts_type usbh_get_status(usbh_core_type *uhost, uint8_t ch_num);
+
+#endif
+
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/at32/libraries/usbfs_library/inc/usbh_ctrl.h b/bsp/at32/libraries/usbfs_library/inc/usbh_ctrl.h
new file mode 100644
index 0000000000..d96a448573
--- /dev/null
+++ b/bsp/at32/libraries/usbfs_library/inc/usbh_ctrl.h
@@ -0,0 +1,98 @@
+/**
+ **************************************************************************
+ * @file usbh_ctrl.h
+ * @brief usb header file
+ **************************************************************************
+ * Copyright notice & Disclaimer
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USBH_CTRL_H
+#define __USBH_CTRL_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+
+/** @addtogroup USBH_drivers_control
+ * @{
+ */
+
+/** @defgroup USBH_ctrl_exported_types
+ * @{
+ */
+
+usb_sts_type usbh_ctrl_send_setup(usbh_core_type *uhost, uint8_t *buffer, uint8_t hc_num);
+usb_sts_type usbh_ctrl_recv_data(usbh_core_type *uhost, uint8_t *buffer,
+ uint16_t length, uint16_t hc_num);
+usb_sts_type usbh_ctrl_send_data(usbh_core_type *uhost, uint8_t *buffer,
+ uint16_t length, uint16_t hc_num);
+usb_sts_type usbh_ctrl_setup_handler(usbh_core_type *uhost);
+usb_sts_type usbh_ctrl_setup_wait_handler(usbh_core_type *uhost, uint32_t *timeout);
+usb_sts_type usbh_ctrl_data_in_handler(usbh_core_type *uhost);
+usb_sts_type usbh_ctrl_data_in_wait_handler(usbh_core_type *uhost, uint32_t timeout);
+usb_sts_type usbh_ctrl_data_out_handler(usbh_core_type *uhost);
+usb_sts_type usbh_ctrl_data_out_wait_handler(usbh_core_type *uhost, uint32_t timeout);
+usb_sts_type usbh_ctrl_status_in_handler(usbh_core_type *uhost);
+usb_sts_type usbh_ctrl_status_in_wait_handler(usbh_core_type *uhost, uint32_t timeout);
+usb_sts_type usbh_ctrl_status_out_handler(usbh_core_type *uhost);
+usb_sts_type usbh_ctrl_status_out_wait_handler(usbh_core_type *uhost, uint32_t timeout);
+usb_sts_type usbh_ctrl_error_handler(usbh_core_type *uhost);
+usb_sts_type usbh_ctrl_stall_handler(usbh_core_type *uhost);
+usb_sts_type usbh_ctrl_complete_handler(usbh_core_type *uhost);
+usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost);
+usb_sts_type usbh_ctrl_request(usbh_core_type *uhost, uint8_t *buffer, uint16_t length);
+usb_sts_type usbh_get_descriptor(usbh_core_type *uhost, uint16_t length,
+ uint8_t req_type, uint16_t wvalue,
+ uint8_t *buffer);
+void usbh_parse_dev_desc(usbh_core_type *uhost, uint8_t *buffer, uint16_t length);
+usb_header_desc_type *usbh_get_next_header(uint8_t *buf, uint16_t *index_len);
+void usbh_parse_interface_desc(usb_interface_desc_type *intf, uint8_t *buf);
+void usbh_parse_endpoint_desc(usb_endpoint_desc_type *ept_desc, uint8_t *buf);
+usb_sts_type usbh_parse_configure_desc(usbh_core_type *uhost,
+ uint8_t *buffer, uint16_t length);
+uint8_t usbh_find_interface(usbh_core_type *uhost, uint8_t class_code, uint8_t sub_class, uint8_t protocol);
+void usbh_parse_string_desc(uint8_t *src, uint8_t *dest, uint16_t length);
+usb_sts_type usbh_get_device_descriptor(usbh_core_type *uhost, uint16_t length);
+usb_sts_type usbh_get_configure_descriptor(usbh_core_type *uhost, uint16_t length);
+usb_sts_type usbh_get_sting_descriptor(usbh_core_type *uhost, uint8_t string_id,
+ uint8_t *buffer, uint16_t length);
+usb_sts_type usbh_set_configuration(usbh_core_type *uhost, uint16_t config);
+usb_sts_type usbh_set_address(usbh_core_type *uhost, uint8_t address);
+usb_sts_type usbh_set_interface(usbh_core_type *uhost, uint8_t ept_num, uint8_t altsetting);
+usb_sts_type usbh_set_feature(usbh_core_type *uhost, uint8_t feature, uint16_t index);
+usb_sts_type usbh_clear_dev_feature(usbh_core_type *uhost, uint8_t feature, uint16_t index);
+usb_sts_type usbh_clear_ept_feature(usbh_core_type *uhost, uint8_t ept_num, uint8_t hc_num);
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/at32/libraries/usbfs_library/inc/usbh_int.h b/bsp/at32/libraries/usbfs_library/inc/usbh_int.h
new file mode 100644
index 0000000000..fac3c575e5
--- /dev/null
+++ b/bsp/at32/libraries/usbfs_library/inc/usbh_int.h
@@ -0,0 +1,71 @@
+/**
+ **************************************************************************
+ * @file usbh_int.h
+ * @brief usb header file
+ **************************************************************************
+ * Copyright notice & Disclaimer
+ *
+ * The software Board Support Package (BSP) that is made available to
+ * download from Artery official website is the copyrighted work of Artery.
+ * Artery authorizes customers to use, copy, and distribute the BSP
+ * software and its related documentation for the purpose of design and
+ * development in conjunction with Artery microcontrollers. Use of the
+ * software is governed by this copyright notice and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
+ * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
+ * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
+ * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
+ * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
+ *
+ **************************************************************************
+ */
+
+/* define to prevent recursive inclusion -------------------------------------*/
+#ifndef __USBH_INT_H
+#define __USBH_INT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* includes ------------------------------------------------------------------*/
+#include "usbh_core.h"
+#include "usb_core.h"
+
+/** @addtogroup USBH_drivers_int
+ * @{
+ */
+
+/** @defgroup USBH_interrupt_exported_types
+ * @{
+ */
+
+void usbh_irq_handler(otg_core_type *hdev);
+void usbh_hch_handler(usbh_core_type *uhost);
+void usbh_port_handler(usbh_core_type *uhost);
+void usbh_disconnect_handler(usbh_core_type *uhost);
+void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn);
+void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn);
+void usbh_rx_qlvl_handler(usbh_core_type *uhost);
+void usbh_wakeup_handler(usbh_core_type *uhost);
+void usbh_sof_handler(usbh_core_type *uhost);
+void usbh_connect_callback(usbh_core_type *uhost);
+void usbh_disconnect_callback(usbh_core_type *uhost);
+void usbd_notify_urbchange_callback(usbh_core_type *uhost, uint8_t chnum, urb_sts_type sts);
+
+/**
+ * @}
+ */
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+