Download STM32Cube USB device library
Transcript
USB OTG Hardware Abstraction Layer UM1734 4.2 USB driver programming manual 4.2.1 Configuring USB driver structure Device initialization The device is initialized using the following function contained in stm32fxxx_hal_pcd.c file: HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd) Endpoint configuration Once the USB core is initialized, the upper layer can call the low level driver to open or close the active endpoint and start transferring data. The following two APIs can be used: HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type) HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) ep_addr, ep_mps and ep_type are respectively the endpoint address, the maximum data transfer and transfer type. Device core structure The main structure used in the device library is the device handle. Its type is “USBD_HandleTypedef” (see Figure 4 on page 13). The USB Global device structure contains all the variables and structures used to keep all the information related to devices in real-time, as well as store the control transfer state machine and the endpoint information and status. In this structure, dev_config holds the current USB device configuration and ep0_state controls the state machine with the following states: /* EP0 State */ #define USBD_EP0_IDLE 0 #define USBD_EP0_SETUP 1 #define USBD_EP0_DATA_IN 2 #define USBD_EP0_DATA_OUT 3 #define USBD_EP0_STATUS_IN 4 #define USBD_EP0_STATUS_OUT 5 #define USBD_EP0_STALL 6 In this structure, dev_state defines the connection, configuration and power status: /* Device Status */ 12/59 #define USBD_DEFAULT 1 #define USBD_ADDRESSED 2 #define USBD_CONFIGURED 3 #define USBD_SUSPENDED 4 DocID025934 Rev 3