001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:13413ea9a877 1 /**
ganlikun 0:13413ea9a877 2 ******************************************************************************
ganlikun 0:13413ea9a877 3 * @file stm32f4xx_ll_usb.h
ganlikun 0:13413ea9a877 4 * @author MCD Application Team
ganlikun 0:13413ea9a877 5 * @version V1.7.1
ganlikun 0:13413ea9a877 6 * @date 14-April-2017
ganlikun 0:13413ea9a877 7 * @brief Header file of USB Core HAL module.
ganlikun 0:13413ea9a877 8 ******************************************************************************
ganlikun 0:13413ea9a877 9 * @attention
ganlikun 0:13413ea9a877 10 *
ganlikun 0:13413ea9a877 11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
ganlikun 0:13413ea9a877 12 *
ganlikun 0:13413ea9a877 13 * Redistribution and use in source and binary forms, with or without modification,
ganlikun 0:13413ea9a877 14 * are permitted provided that the following conditions are met:
ganlikun 0:13413ea9a877 15 * 1. Redistributions of source code must retain the above copyright notice,
ganlikun 0:13413ea9a877 16 * this list of conditions and the following disclaimer.
ganlikun 0:13413ea9a877 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
ganlikun 0:13413ea9a877 18 * this list of conditions and the following disclaimer in the documentation
ganlikun 0:13413ea9a877 19 * and/or other materials provided with the distribution.
ganlikun 0:13413ea9a877 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
ganlikun 0:13413ea9a877 21 * may be used to endorse or promote products derived from this software
ganlikun 0:13413ea9a877 22 * without specific prior written permission.
ganlikun 0:13413ea9a877 23 *
ganlikun 0:13413ea9a877 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:13413ea9a877 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:13413ea9a877 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ganlikun 0:13413ea9a877 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
ganlikun 0:13413ea9a877 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ganlikun 0:13413ea9a877 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
ganlikun 0:13413ea9a877 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ganlikun 0:13413ea9a877 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ganlikun 0:13413ea9a877 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ganlikun 0:13413ea9a877 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:13413ea9a877 34 *
ganlikun 0:13413ea9a877 35 ******************************************************************************
ganlikun 0:13413ea9a877 36 */
ganlikun 0:13413ea9a877 37
ganlikun 0:13413ea9a877 38 /* Define to prevent recursive inclusion -------------------------------------*/
ganlikun 0:13413ea9a877 39 #ifndef __STM32F4xx_LL_USB_H
ganlikun 0:13413ea9a877 40 #define __STM32F4xx_LL_USB_H
ganlikun 0:13413ea9a877 41
ganlikun 0:13413ea9a877 42 #ifdef __cplusplus
ganlikun 0:13413ea9a877 43 extern "C" {
ganlikun 0:13413ea9a877 44 #endif
ganlikun 0:13413ea9a877 45 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || \
ganlikun 0:13413ea9a877 46 defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \
ganlikun 0:13413ea9a877 47 defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) || \
ganlikun 0:13413ea9a877 48 defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
ganlikun 0:13413ea9a877 49 defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx)
ganlikun 0:13413ea9a877 50 /* Includes ------------------------------------------------------------------*/
ganlikun 0:13413ea9a877 51 #include "stm32f4xx_hal_def.h"
ganlikun 0:13413ea9a877 52
ganlikun 0:13413ea9a877 53 /** @addtogroup STM32F4xx_HAL
ganlikun 0:13413ea9a877 54 * @{
ganlikun 0:13413ea9a877 55 */
ganlikun 0:13413ea9a877 56
ganlikun 0:13413ea9a877 57 /** @addtogroup USB_Core
ganlikun 0:13413ea9a877 58 * @{
ganlikun 0:13413ea9a877 59 */
ganlikun 0:13413ea9a877 60
ganlikun 0:13413ea9a877 61 /* Exported types ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 62
ganlikun 0:13413ea9a877 63 /**
ganlikun 0:13413ea9a877 64 * @brief USB Mode definition
ganlikun 0:13413ea9a877 65 */
ganlikun 0:13413ea9a877 66 typedef enum
ganlikun 0:13413ea9a877 67 {
ganlikun 0:13413ea9a877 68 USB_OTG_DEVICE_MODE = 0U,
ganlikun 0:13413ea9a877 69 USB_OTG_HOST_MODE = 1U,
ganlikun 0:13413ea9a877 70 USB_OTG_DRD_MODE = 2U
ganlikun 0:13413ea9a877 71
ganlikun 0:13413ea9a877 72 }USB_OTG_ModeTypeDef;
ganlikun 0:13413ea9a877 73
ganlikun 0:13413ea9a877 74 /**
ganlikun 0:13413ea9a877 75 * @brief URB States definition
ganlikun 0:13413ea9a877 76 */
ganlikun 0:13413ea9a877 77 typedef enum {
ganlikun 0:13413ea9a877 78 URB_IDLE = 0U,
ganlikun 0:13413ea9a877 79 URB_DONE,
ganlikun 0:13413ea9a877 80 URB_NOTREADY,
ganlikun 0:13413ea9a877 81 URB_NYET,
ganlikun 0:13413ea9a877 82 URB_ERROR,
ganlikun 0:13413ea9a877 83 URB_STALL
ganlikun 0:13413ea9a877 84
ganlikun 0:13413ea9a877 85 }USB_OTG_URBStateTypeDef;
ganlikun 0:13413ea9a877 86
ganlikun 0:13413ea9a877 87 /**
ganlikun 0:13413ea9a877 88 * @brief Host channel States definition
ganlikun 0:13413ea9a877 89 */
ganlikun 0:13413ea9a877 90 typedef enum {
ganlikun 0:13413ea9a877 91 HC_IDLE = 0U,
ganlikun 0:13413ea9a877 92 HC_XFRC,
ganlikun 0:13413ea9a877 93 HC_HALTED,
ganlikun 0:13413ea9a877 94 HC_NAK,
ganlikun 0:13413ea9a877 95 HC_NYET,
ganlikun 0:13413ea9a877 96 HC_STALL,
ganlikun 0:13413ea9a877 97 HC_XACTERR,
ganlikun 0:13413ea9a877 98 HC_BBLERR,
ganlikun 0:13413ea9a877 99 HC_DATATGLERR
ganlikun 0:13413ea9a877 100
ganlikun 0:13413ea9a877 101 }USB_OTG_HCStateTypeDef;
ganlikun 0:13413ea9a877 102
ganlikun 0:13413ea9a877 103 /**
ganlikun 0:13413ea9a877 104 * @brief PCD Initialization Structure definition
ganlikun 0:13413ea9a877 105 */
ganlikun 0:13413ea9a877 106 typedef struct
ganlikun 0:13413ea9a877 107 {
ganlikun 0:13413ea9a877 108 uint32_t dev_endpoints; /*!< Device Endpoints number.
ganlikun 0:13413ea9a877 109 This parameter depends on the used USB core.
ganlikun 0:13413ea9a877 110 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
ganlikun 0:13413ea9a877 111
ganlikun 0:13413ea9a877 112 uint32_t Host_channels; /*!< Host Channels number.
ganlikun 0:13413ea9a877 113 This parameter Depends on the used USB core.
ganlikun 0:13413ea9a877 114 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
ganlikun 0:13413ea9a877 115
ganlikun 0:13413ea9a877 116 uint32_t speed; /*!< USB Core speed.
ganlikun 0:13413ea9a877 117 This parameter can be any value of @ref USB_Core_Speed_ */
ganlikun 0:13413ea9a877 118
ganlikun 0:13413ea9a877 119 uint32_t dma_enable; /*!< Enable or disable of the USB embedded DMA. */
ganlikun 0:13413ea9a877 120
ganlikun 0:13413ea9a877 121 uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size.
ganlikun 0:13413ea9a877 122 This parameter can be any value of @ref USB_EP0_MPS_ */
ganlikun 0:13413ea9a877 123
ganlikun 0:13413ea9a877 124 uint32_t phy_itface; /*!< Select the used PHY interface.
ganlikun 0:13413ea9a877 125 This parameter can be any value of @ref USB_Core_PHY_ */
ganlikun 0:13413ea9a877 126
ganlikun 0:13413ea9a877 127 uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */
ganlikun 0:13413ea9a877 128
ganlikun 0:13413ea9a877 129 uint32_t low_power_enable; /*!< Enable or disable the low power mode. */
ganlikun 0:13413ea9a877 130
ganlikun 0:13413ea9a877 131 uint32_t lpm_enable; /*!< Enable or disable Link Power Management. */
ganlikun 0:13413ea9a877 132
ganlikun 0:13413ea9a877 133 uint32_t battery_charging_enable; /*!< Enable or disable Battery charging. */
ganlikun 0:13413ea9a877 134
ganlikun 0:13413ea9a877 135 uint32_t vbus_sensing_enable; /*!< Enable or disable the VBUS Sensing feature. */
ganlikun 0:13413ea9a877 136
ganlikun 0:13413ea9a877 137 uint32_t use_dedicated_ep1; /*!< Enable or disable the use of the dedicated EP1 interrupt. */
ganlikun 0:13413ea9a877 138
ganlikun 0:13413ea9a877 139 uint32_t use_external_vbus; /*!< Enable or disable the use of the external VBUS. */
ganlikun 0:13413ea9a877 140
ganlikun 0:13413ea9a877 141 }USB_OTG_CfgTypeDef;
ganlikun 0:13413ea9a877 142
ganlikun 0:13413ea9a877 143 /**
ganlikun 0:13413ea9a877 144 * @brief OTG End Point Initialization Structure definition
ganlikun 0:13413ea9a877 145 */
ganlikun 0:13413ea9a877 146 typedef struct
ganlikun 0:13413ea9a877 147 {
ganlikun 0:13413ea9a877 148 uint8_t num; /*!< Endpoint number
ganlikun 0:13413ea9a877 149 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
ganlikun 0:13413ea9a877 150
ganlikun 0:13413ea9a877 151 uint8_t is_in; /*!< Endpoint direction
ganlikun 0:13413ea9a877 152 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
ganlikun 0:13413ea9a877 153
ganlikun 0:13413ea9a877 154 uint8_t is_stall; /*!< Endpoint stall condition
ganlikun 0:13413ea9a877 155 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
ganlikun 0:13413ea9a877 156
ganlikun 0:13413ea9a877 157 uint8_t type; /*!< Endpoint type
ganlikun 0:13413ea9a877 158 This parameter can be any value of @ref USB_EP_Type_ */
ganlikun 0:13413ea9a877 159
ganlikun 0:13413ea9a877 160 uint8_t data_pid_start; /*!< Initial data PID
ganlikun 0:13413ea9a877 161 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
ganlikun 0:13413ea9a877 162
ganlikun 0:13413ea9a877 163 uint8_t even_odd_frame; /*!< IFrame parity
ganlikun 0:13413ea9a877 164 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
ganlikun 0:13413ea9a877 165
ganlikun 0:13413ea9a877 166 uint16_t tx_fifo_num; /*!< Transmission FIFO number
ganlikun 0:13413ea9a877 167 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
ganlikun 0:13413ea9a877 168
ganlikun 0:13413ea9a877 169 uint32_t maxpacket; /*!< Endpoint Max packet size
ganlikun 0:13413ea9a877 170 This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
ganlikun 0:13413ea9a877 171
ganlikun 0:13413ea9a877 172 uint8_t *xfer_buff; /*!< Pointer to transfer buffer */
ganlikun 0:13413ea9a877 173
ganlikun 0:13413ea9a877 174 uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address */
ganlikun 0:13413ea9a877 175
ganlikun 0:13413ea9a877 176 uint32_t xfer_len; /*!< Current transfer length */
ganlikun 0:13413ea9a877 177
ganlikun 0:13413ea9a877 178 uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */
ganlikun 0:13413ea9a877 179
ganlikun 0:13413ea9a877 180 }USB_OTG_EPTypeDef;
ganlikun 0:13413ea9a877 181
ganlikun 0:13413ea9a877 182 /**
ganlikun 0:13413ea9a877 183 * @brief OTG HC Initialization Structure definition
ganlikun 0:13413ea9a877 184 */
ganlikun 0:13413ea9a877 185 typedef struct
ganlikun 0:13413ea9a877 186 {
ganlikun 0:13413ea9a877 187 uint8_t dev_addr ; /*!< USB device address.
ganlikun 0:13413ea9a877 188 This parameter must be a number between Min_Data = 1 and Max_Data = 255 */
ganlikun 0:13413ea9a877 189
ganlikun 0:13413ea9a877 190 uint8_t ch_num; /*!< Host channel number.
ganlikun 0:13413ea9a877 191 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
ganlikun 0:13413ea9a877 192
ganlikun 0:13413ea9a877 193 uint8_t ep_num; /*!< Endpoint number.
ganlikun 0:13413ea9a877 194 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
ganlikun 0:13413ea9a877 195
ganlikun 0:13413ea9a877 196 uint8_t ep_is_in; /*!< Endpoint direction
ganlikun 0:13413ea9a877 197 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
ganlikun 0:13413ea9a877 198
ganlikun 0:13413ea9a877 199 uint8_t speed; /*!< USB Host speed.
ganlikun 0:13413ea9a877 200 This parameter can be any value of @ref USB_Core_Speed_ */
ganlikun 0:13413ea9a877 201
ganlikun 0:13413ea9a877 202 uint8_t do_ping; /*!< Enable or disable the use of the PING protocol for HS mode. */
ganlikun 0:13413ea9a877 203
ganlikun 0:13413ea9a877 204 uint8_t process_ping; /*!< Execute the PING protocol for HS mode. */
ganlikun 0:13413ea9a877 205
ganlikun 0:13413ea9a877 206 uint8_t ep_type; /*!< Endpoint Type.
ganlikun 0:13413ea9a877 207 This parameter can be any value of @ref USB_EP_Type_ */
ganlikun 0:13413ea9a877 208
ganlikun 0:13413ea9a877 209 uint16_t max_packet; /*!< Endpoint Max packet size.
ganlikun 0:13413ea9a877 210 This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
ganlikun 0:13413ea9a877 211
ganlikun 0:13413ea9a877 212 uint8_t data_pid; /*!< Initial data PID.
ganlikun 0:13413ea9a877 213 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
ganlikun 0:13413ea9a877 214
ganlikun 0:13413ea9a877 215 uint8_t *xfer_buff; /*!< Pointer to transfer buffer. */
ganlikun 0:13413ea9a877 216
ganlikun 0:13413ea9a877 217 uint32_t xfer_len; /*!< Current transfer length. */
ganlikun 0:13413ea9a877 218
ganlikun 0:13413ea9a877 219 uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer. */
ganlikun 0:13413ea9a877 220
ganlikun 0:13413ea9a877 221 uint8_t toggle_in; /*!< IN transfer current toggle flag.
ganlikun 0:13413ea9a877 222 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
ganlikun 0:13413ea9a877 223
ganlikun 0:13413ea9a877 224 uint8_t toggle_out; /*!< OUT transfer current toggle flag
ganlikun 0:13413ea9a877 225 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
ganlikun 0:13413ea9a877 226
ganlikun 0:13413ea9a877 227 uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address. */
ganlikun 0:13413ea9a877 228
ganlikun 0:13413ea9a877 229 uint32_t ErrCnt; /*!< Host channel error count.*/
ganlikun 0:13413ea9a877 230
ganlikun 0:13413ea9a877 231 USB_OTG_URBStateTypeDef urb_state; /*!< URB state.
ganlikun 0:13413ea9a877 232 This parameter can be any value of @ref USB_OTG_URBStateTypeDef */
ganlikun 0:13413ea9a877 233
ganlikun 0:13413ea9a877 234 USB_OTG_HCStateTypeDef state; /*!< Host Channel state.
ganlikun 0:13413ea9a877 235 This parameter can be any value of @ref USB_OTG_HCStateTypeDef */
ganlikun 0:13413ea9a877 236
ganlikun 0:13413ea9a877 237 }USB_OTG_HCTypeDef;
ganlikun 0:13413ea9a877 238
ganlikun 0:13413ea9a877 239 /* Exported constants --------------------------------------------------------*/
ganlikun 0:13413ea9a877 240
ganlikun 0:13413ea9a877 241 /** @defgroup PCD_Exported_Constants PCD Exported Constants
ganlikun 0:13413ea9a877 242 * @{
ganlikun 0:13413ea9a877 243 */
ganlikun 0:13413ea9a877 244
ganlikun 0:13413ea9a877 245 /** @defgroup USB_Core_Mode_ USB Core Mode
ganlikun 0:13413ea9a877 246 * @{
ganlikun 0:13413ea9a877 247 */
ganlikun 0:13413ea9a877 248 #define USB_OTG_MODE_DEVICE 0U
ganlikun 0:13413ea9a877 249 #define USB_OTG_MODE_HOST 1U
ganlikun 0:13413ea9a877 250 #define USB_OTG_MODE_DRD 2U
ganlikun 0:13413ea9a877 251 /**
ganlikun 0:13413ea9a877 252 * @}
ganlikun 0:13413ea9a877 253 */
ganlikun 0:13413ea9a877 254
ganlikun 0:13413ea9a877 255 /** @defgroup USB_Core_Speed_ USB Core Speed
ganlikun 0:13413ea9a877 256 * @{
ganlikun 0:13413ea9a877 257 */
ganlikun 0:13413ea9a877 258 #define USB_OTG_SPEED_HIGH 0U
ganlikun 0:13413ea9a877 259 #define USB_OTG_SPEED_HIGH_IN_FULL 1U
ganlikun 0:13413ea9a877 260 #define USB_OTG_SPEED_LOW 2U
ganlikun 0:13413ea9a877 261 #define USB_OTG_SPEED_FULL 3U
ganlikun 0:13413ea9a877 262 /**
ganlikun 0:13413ea9a877 263 * @}
ganlikun 0:13413ea9a877 264 */
ganlikun 0:13413ea9a877 265
ganlikun 0:13413ea9a877 266 /** @defgroup USB_Core_PHY_ USB Core PHY
ganlikun 0:13413ea9a877 267 * @{
ganlikun 0:13413ea9a877 268 */
ganlikun 0:13413ea9a877 269 #define USB_OTG_ULPI_PHY 1U
ganlikun 0:13413ea9a877 270 #define USB_OTG_EMBEDDED_PHY 2U
ganlikun 0:13413ea9a877 271 /**
ganlikun 0:13413ea9a877 272 * @}
ganlikun 0:13413ea9a877 273 */
ganlikun 0:13413ea9a877 274
ganlikun 0:13413ea9a877 275 /** @defgroup USB_Core_MPS_ USB Core MPS
ganlikun 0:13413ea9a877 276 * @{
ganlikun 0:13413ea9a877 277 */
ganlikun 0:13413ea9a877 278 #define USB_OTG_HS_MAX_PACKET_SIZE 512U
ganlikun 0:13413ea9a877 279 #define USB_OTG_FS_MAX_PACKET_SIZE 64U
ganlikun 0:13413ea9a877 280 #define USB_OTG_MAX_EP0_SIZE 64U
ganlikun 0:13413ea9a877 281 /**
ganlikun 0:13413ea9a877 282 * @}
ganlikun 0:13413ea9a877 283 */
ganlikun 0:13413ea9a877 284
ganlikun 0:13413ea9a877 285 /** @defgroup USB_Core_Phy_Frequency_ USB Core Phy Frequency
ganlikun 0:13413ea9a877 286 * @{
ganlikun 0:13413ea9a877 287 */
ganlikun 0:13413ea9a877 288 #define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ (0U << 1U)
ganlikun 0:13413ea9a877 289 #define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ (1U << 1U)
ganlikun 0:13413ea9a877 290 #define DSTS_ENUMSPD_LS_PHY_6MHZ (2U << 1U)
ganlikun 0:13413ea9a877 291 #define DSTS_ENUMSPD_FS_PHY_48MHZ (3U << 1U)
ganlikun 0:13413ea9a877 292 /**
ganlikun 0:13413ea9a877 293 * @}
ganlikun 0:13413ea9a877 294 */
ganlikun 0:13413ea9a877 295
ganlikun 0:13413ea9a877 296 /** @defgroup USB_CORE_Frame_Interval_ USB CORE Frame Interval
ganlikun 0:13413ea9a877 297 * @{
ganlikun 0:13413ea9a877 298 */
ganlikun 0:13413ea9a877 299 #define DCFG_FRAME_INTERVAL_80 0U
ganlikun 0:13413ea9a877 300 #define DCFG_FRAME_INTERVAL_85 1U
ganlikun 0:13413ea9a877 301 #define DCFG_FRAME_INTERVAL_90 2U
ganlikun 0:13413ea9a877 302 #define DCFG_FRAME_INTERVAL_95 3U
ganlikun 0:13413ea9a877 303 /**
ganlikun 0:13413ea9a877 304 * @}
ganlikun 0:13413ea9a877 305 */
ganlikun 0:13413ea9a877 306
ganlikun 0:13413ea9a877 307 /** @defgroup USB_EP0_MPS_ USB EP0 MPS
ganlikun 0:13413ea9a877 308 * @{
ganlikun 0:13413ea9a877 309 */
ganlikun 0:13413ea9a877 310 #define DEP0CTL_MPS_64 0U
ganlikun 0:13413ea9a877 311 #define DEP0CTL_MPS_32 1U
ganlikun 0:13413ea9a877 312 #define DEP0CTL_MPS_16 2U
ganlikun 0:13413ea9a877 313 #define DEP0CTL_MPS_8 3U
ganlikun 0:13413ea9a877 314 /**
ganlikun 0:13413ea9a877 315 * @}
ganlikun 0:13413ea9a877 316 */
ganlikun 0:13413ea9a877 317
ganlikun 0:13413ea9a877 318 /** @defgroup USB_EP_Speed_ USB EP Speed
ganlikun 0:13413ea9a877 319 * @{
ganlikun 0:13413ea9a877 320 */
ganlikun 0:13413ea9a877 321 #define EP_SPEED_LOW 0U
ganlikun 0:13413ea9a877 322 #define EP_SPEED_FULL 1U
ganlikun 0:13413ea9a877 323 #define EP_SPEED_HIGH 2U
ganlikun 0:13413ea9a877 324 /**
ganlikun 0:13413ea9a877 325 * @}
ganlikun 0:13413ea9a877 326 */
ganlikun 0:13413ea9a877 327
ganlikun 0:13413ea9a877 328 /** @defgroup USB_EP_Type_ USB EP Type
ganlikun 0:13413ea9a877 329 * @{
ganlikun 0:13413ea9a877 330 */
ganlikun 0:13413ea9a877 331 #define EP_TYPE_CTRL 0U
ganlikun 0:13413ea9a877 332 #define EP_TYPE_ISOC 1U
ganlikun 0:13413ea9a877 333 #define EP_TYPE_BULK 2U
ganlikun 0:13413ea9a877 334 #define EP_TYPE_INTR 3U
ganlikun 0:13413ea9a877 335 #define EP_TYPE_MSK 3U
ganlikun 0:13413ea9a877 336 /**
ganlikun 0:13413ea9a877 337 * @}
ganlikun 0:13413ea9a877 338 */
ganlikun 0:13413ea9a877 339
ganlikun 0:13413ea9a877 340 /** @defgroup USB_STS_Defines_ USB STS Defines
ganlikun 0:13413ea9a877 341 * @{
ganlikun 0:13413ea9a877 342 */
ganlikun 0:13413ea9a877 343 #define STS_GOUT_NAK 1U
ganlikun 0:13413ea9a877 344 #define STS_DATA_UPDT 2U
ganlikun 0:13413ea9a877 345 #define STS_XFER_COMP 3U
ganlikun 0:13413ea9a877 346 #define STS_SETUP_COMP 4U
ganlikun 0:13413ea9a877 347 #define STS_SETUP_UPDT 6U
ganlikun 0:13413ea9a877 348 /**
ganlikun 0:13413ea9a877 349 * @}
ganlikun 0:13413ea9a877 350 */
ganlikun 0:13413ea9a877 351
ganlikun 0:13413ea9a877 352 /** @defgroup HCFG_SPEED_Defines_ HCFG SPEED Defines
ganlikun 0:13413ea9a877 353 * @{
ganlikun 0:13413ea9a877 354 */
ganlikun 0:13413ea9a877 355 #define HCFG_30_60_MHZ 0U
ganlikun 0:13413ea9a877 356 #define HCFG_48_MHZ 1U
ganlikun 0:13413ea9a877 357 #define HCFG_6_MHZ 2U
ganlikun 0:13413ea9a877 358 /**
ganlikun 0:13413ea9a877 359 * @}
ganlikun 0:13413ea9a877 360 */
ganlikun 0:13413ea9a877 361
ganlikun 0:13413ea9a877 362 /** @defgroup HPRT0_PRTSPD_SPEED_Defines_ HPRT0 PRTSPD SPEED Defines
ganlikun 0:13413ea9a877 363 * @{
ganlikun 0:13413ea9a877 364 */
ganlikun 0:13413ea9a877 365 #define HPRT0_PRTSPD_HIGH_SPEED 0U
ganlikun 0:13413ea9a877 366 #define HPRT0_PRTSPD_FULL_SPEED 1U
ganlikun 0:13413ea9a877 367 #define HPRT0_PRTSPD_LOW_SPEED 2U
ganlikun 0:13413ea9a877 368 /**
ganlikun 0:13413ea9a877 369 * @}
ganlikun 0:13413ea9a877 370 */
ganlikun 0:13413ea9a877 371
ganlikun 0:13413ea9a877 372 #define HCCHAR_CTRL 0U
ganlikun 0:13413ea9a877 373 #define HCCHAR_ISOC 1U
ganlikun 0:13413ea9a877 374 #define HCCHAR_BULK 2U
ganlikun 0:13413ea9a877 375 #define HCCHAR_INTR 3U
ganlikun 0:13413ea9a877 376
ganlikun 0:13413ea9a877 377 #define HC_PID_DATA0 0U
ganlikun 0:13413ea9a877 378 #define HC_PID_DATA2 1U
ganlikun 0:13413ea9a877 379 #define HC_PID_DATA1 2U
ganlikun 0:13413ea9a877 380 #define HC_PID_SETUP 3U
ganlikun 0:13413ea9a877 381
ganlikun 0:13413ea9a877 382 #define GRXSTS_PKTSTS_IN 2U
ganlikun 0:13413ea9a877 383 #define GRXSTS_PKTSTS_IN_XFER_COMP 3U
ganlikun 0:13413ea9a877 384 #define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5U
ganlikun 0:13413ea9a877 385 #define GRXSTS_PKTSTS_CH_HALTED 7U
ganlikun 0:13413ea9a877 386
ganlikun 0:13413ea9a877 387 #define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_PCGCCTL_BASE)
ganlikun 0:13413ea9a877 388 #define USBx_HPRT0 *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_HOST_PORT_BASE)
ganlikun 0:13413ea9a877 389
ganlikun 0:13413ea9a877 390 #define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)((uint32_t )USBx + USB_OTG_DEVICE_BASE))
ganlikun 0:13413ea9a877 391 #define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)((uint32_t)USBx + USB_OTG_IN_ENDPOINT_BASE + (i)*USB_OTG_EP_REG_SIZE))
ganlikun 0:13413ea9a877 392 #define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)((uint32_t)USBx + USB_OTG_OUT_ENDPOINT_BASE + (i)*USB_OTG_EP_REG_SIZE))
ganlikun 0:13413ea9a877 393 #define USBx_DFIFO(i) *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_FIFO_BASE + (i) * USB_OTG_FIFO_SIZE)
ganlikun 0:13413ea9a877 394
ganlikun 0:13413ea9a877 395 #define USBx_HOST ((USB_OTG_HostTypeDef *)((uint32_t )USBx + USB_OTG_HOST_BASE))
ganlikun 0:13413ea9a877 396 #define USBx_HC(i) ((USB_OTG_HostChannelTypeDef *)((uint32_t)USBx + USB_OTG_HOST_CHANNEL_BASE + (i)*USB_OTG_HOST_CHANNEL_SIZE))
ganlikun 0:13413ea9a877 397 /**
ganlikun 0:13413ea9a877 398 * @}
ganlikun 0:13413ea9a877 399 */
ganlikun 0:13413ea9a877 400 /* Exported macro ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 401 #define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK &= ~(__INTERRUPT__))
ganlikun 0:13413ea9a877 402 #define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK |= (__INTERRUPT__))
ganlikun 0:13413ea9a877 403
ganlikun 0:13413ea9a877 404 #define CLEAR_IN_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_INEP(__EPNUM__)->DIEPINT = (__INTERRUPT__))
ganlikun 0:13413ea9a877 405 #define CLEAR_OUT_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_OUTEP(__EPNUM__)->DOEPINT = (__INTERRUPT__))
ganlikun 0:13413ea9a877 406
ganlikun 0:13413ea9a877 407 /* Exported functions --------------------------------------------------------*/
ganlikun 0:13413ea9a877 408 HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef Init);
ganlikun 0:13413ea9a877 409 HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef Init);
ganlikun 0:13413ea9a877 410 HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 411 HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 412 HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx , USB_OTG_ModeTypeDef mode);
ganlikun 0:13413ea9a877 413 HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx , uint8_t speed);
ganlikun 0:13413ea9a877 414 HAL_StatusTypeDef USB_FlushRxFifo (USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 415 HAL_StatusTypeDef USB_FlushTxFifo (USB_OTG_GlobalTypeDef *USBx, uint32_t num );
ganlikun 0:13413ea9a877 416 HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
ganlikun 0:13413ea9a877 417 HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
ganlikun 0:13413ea9a877 418 HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
ganlikun 0:13413ea9a877 419 HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
ganlikun 0:13413ea9a877 420 HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep, uint8_t dma);
ganlikun 0:13413ea9a877 421 HAL_StatusTypeDef USB_EP0StartXfer(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep, uint8_t dma);
ganlikun 0:13413ea9a877 422 HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len, uint8_t dma);
ganlikun 0:13413ea9a877 423 void * USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len);
ganlikun 0:13413ea9a877 424 HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep);
ganlikun 0:13413ea9a877 425 HAL_StatusTypeDef USB_EPClearStall(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep);
ganlikun 0:13413ea9a877 426 HAL_StatusTypeDef USB_SetDevAddress (USB_OTG_GlobalTypeDef *USBx, uint8_t address);
ganlikun 0:13413ea9a877 427 HAL_StatusTypeDef USB_DevConnect (USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 428 HAL_StatusTypeDef USB_DevDisconnect (USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 429 HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 430 HAL_StatusTypeDef USB_ActivateSetup (USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 431 HAL_StatusTypeDef USB_EP0_OutStart(USB_OTG_GlobalTypeDef *USBx, uint8_t dma, uint8_t *psetup);
ganlikun 0:13413ea9a877 432 uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 433 uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 434 uint32_t USB_ReadInterrupts (USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 435 uint32_t USB_ReadDevAllOutEpInterrupt (USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 436 uint32_t USB_ReadDevOutEPInterrupt (USB_OTG_GlobalTypeDef *USBx , uint8_t epnum);
ganlikun 0:13413ea9a877 437 uint32_t USB_ReadDevAllInEpInterrupt (USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 438 uint32_t USB_ReadDevInEPInterrupt (USB_OTG_GlobalTypeDef *USBx , uint8_t epnum);
ganlikun 0:13413ea9a877 439 void USB_ClearInterrupts (USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt);
ganlikun 0:13413ea9a877 440
ganlikun 0:13413ea9a877 441 HAL_StatusTypeDef USB_HostInit (USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
ganlikun 0:13413ea9a877 442 HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx , uint8_t freq);
ganlikun 0:13413ea9a877 443 HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 444 HAL_StatusTypeDef USB_DriveVbus (USB_OTG_GlobalTypeDef *USBx, uint8_t state);
ganlikun 0:13413ea9a877 445 uint32_t USB_GetHostSpeed (USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 446 uint32_t USB_GetCurrentFrame (USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 447 HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx,
ganlikun 0:13413ea9a877 448 uint8_t ch_num,
ganlikun 0:13413ea9a877 449 uint8_t epnum,
ganlikun 0:13413ea9a877 450 uint8_t dev_address,
ganlikun 0:13413ea9a877 451 uint8_t speed,
ganlikun 0:13413ea9a877 452 uint8_t ep_type,
ganlikun 0:13413ea9a877 453 uint16_t mps);
ganlikun 0:13413ea9a877 454 HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDef *hc, uint8_t dma);
ganlikun 0:13413ea9a877 455 uint32_t USB_HC_ReadInterrupt (USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 456 HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx , uint8_t hc_num);
ganlikun 0:13413ea9a877 457 HAL_StatusTypeDef USB_DoPing(USB_OTG_GlobalTypeDef *USBx , uint8_t ch_num);
ganlikun 0:13413ea9a877 458 HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx);
ganlikun 0:13413ea9a877 459
ganlikun 0:13413ea9a877 460 /**
ganlikun 0:13413ea9a877 461 * @}
ganlikun 0:13413ea9a877 462 */
ganlikun 0:13413ea9a877 463
ganlikun 0:13413ea9a877 464 /**
ganlikun 0:13413ea9a877 465 * @}
ganlikun 0:13413ea9a877 466 */
ganlikun 0:13413ea9a877 467 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx ||
ganlikun 0:13413ea9a877 468 STM32F401xC || STM32F401xE || STM32F411xE || STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Rx ||
ganlikun 0:13413ea9a877 469 STM32F412Vx || STM32F412Cx || STM32F413xx || STM32F423xx */
ganlikun 0:13413ea9a877 470 #ifdef __cplusplus
ganlikun 0:13413ea9a877 471 }
ganlikun 0:13413ea9a877 472 #endif
ganlikun 0:13413ea9a877 473
ganlikun 0:13413ea9a877 474
ganlikun 0:13413ea9a877 475 #endif /* __STM32F4xx_LL_USB_H */
ganlikun 0:13413ea9a877 476
ganlikun 0:13413ea9a877 477 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ganlikun 0:13413ea9a877 478