Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /** |
| 2 | ****************************************************************************** |
||
| 3 | * @file stm32f1xx_ll_usb.h |
||
| 4 | * @author MCD Application Team |
||
| 5 | * @brief Header file of USB Low Layer HAL module. |
||
| 6 | ****************************************************************************** |
||
| 7 | * @attention |
||
| 8 | * |
||
| 9 | mjames | 9 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
| 10 | * All rights reserved.</center></h2> |
||
| 2 | mjames | 11 | * |
| 9 | mjames | 12 | * This software component is licensed by ST under BSD 3-Clause license, |
| 13 | * the "License"; You may not use this file except in compliance with the |
||
| 14 | * License. You may obtain a copy of the License at: |
||
| 15 | * opensource.org/licenses/BSD-3-Clause |
||
| 2 | mjames | 16 | * |
| 17 | ****************************************************************************** |
||
| 18 | */ |
||
| 19 | |||
| 20 | /* Define to prevent recursive inclusion -------------------------------------*/ |
||
| 9 | mjames | 21 | #ifndef STM32F1xx_LL_USB_H |
| 22 | #define STM32F1xx_LL_USB_H |
||
| 2 | mjames | 23 | |
| 24 | #ifdef __cplusplus |
||
| 9 | mjames | 25 | extern "C" { |
| 2 | mjames | 26 | #endif |
| 27 | |||
| 28 | /* Includes ------------------------------------------------------------------*/ |
||
| 29 | #include "stm32f1xx_hal_def.h" |
||
| 30 | |||
| 9 | mjames | 31 | #if defined (USB) || defined (USB_OTG_FS) |
| 2 | mjames | 32 | /** @addtogroup STM32F1xx_HAL_Driver |
| 33 | * @{ |
||
| 34 | */ |
||
| 35 | |||
| 36 | /** @addtogroup USB_LL |
||
| 37 | * @{ |
||
| 38 | */ |
||
| 39 | |||
| 40 | /* Exported types ------------------------------------------------------------*/ |
||
| 9 | mjames | 41 | |
| 42 | /** |
||
| 43 | * @brief USB Mode definition |
||
| 2 | mjames | 44 | */ |
| 9 | mjames | 45 | #if defined (USB_OTG_FS) |
| 46 | |||
| 47 | typedef enum |
||
| 2 | mjames | 48 | { |
| 9 | mjames | 49 | USB_DEVICE_MODE = 0, |
| 50 | USB_HOST_MODE = 1, |
||
| 51 | USB_DRD_MODE = 2 |
||
| 52 | } USB_ModeTypeDef; |
||
| 2 | mjames | 53 | |
| 54 | /** |
||
| 55 | * @brief URB States definition |
||
| 56 | */ |
||
| 9 | mjames | 57 | typedef enum |
| 58 | { |
||
| 2 | mjames | 59 | URB_IDLE = 0, |
| 60 | URB_DONE, |
||
| 61 | URB_NOTREADY, |
||
| 62 | URB_NYET, |
||
| 63 | URB_ERROR, |
||
| 64 | URB_STALL |
||
| 9 | mjames | 65 | } USB_OTG_URBStateTypeDef; |
| 2 | mjames | 66 | |
| 9 | mjames | 67 | /** |
| 2 | mjames | 68 | * @brief Host channel States definition |
| 69 | */ |
||
| 9 | mjames | 70 | typedef enum |
| 71 | { |
||
| 2 | mjames | 72 | HC_IDLE = 0, |
| 73 | HC_XFRC, |
||
| 74 | HC_HALTED, |
||
| 75 | HC_NAK, |
||
| 76 | HC_NYET, |
||
| 77 | HC_STALL, |
||
| 9 | mjames | 78 | HC_XACTERR, |
| 79 | HC_BBLERR, |
||
| 2 | mjames | 80 | HC_DATATGLERR |
| 9 | mjames | 81 | } USB_OTG_HCStateTypeDef; |
| 2 | mjames | 82 | |
| 9 | mjames | 83 | /** |
| 84 | * @brief USB Instance Initialization Structure definition |
||
| 2 | mjames | 85 | */ |
| 86 | typedef struct |
||
| 87 | { |
||
| 9 | mjames | 88 | uint32_t dev_endpoints; /*!< Device Endpoints number. |
| 89 | This parameter depends on the used USB core. |
||
| 90 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ |
||
| 2 | mjames | 91 | |
| 9 | mjames | 92 | uint32_t Host_channels; /*!< Host Channels number. |
| 93 | This parameter Depends on the used USB core. |
||
| 94 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ |
||
| 95 | |||
| 96 | uint32_t speed; /*!< USB Core speed. |
||
| 97 | This parameter can be any value of @ref USB_Core_Speed */ |
||
| 98 | |||
| 99 | uint32_t dma_enable; /*!< Enable or disable of the USB embedded DMA used only for OTG HS. */ |
||
| 100 | |||
| 101 | uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. */ |
||
| 102 | |||
| 103 | uint32_t phy_itface; /*!< Select the used PHY interface. |
||
| 104 | This parameter can be any value of @ref USB_Core_PHY */ |
||
| 105 | |||
| 106 | uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */ |
||
| 107 | |||
| 108 | uint32_t low_power_enable; /*!< Enable or disable the low power mode. */ |
||
| 109 | |||
| 110 | uint32_t lpm_enable; /*!< Enable or disable Link Power Management. */ |
||
| 111 | |||
| 112 | uint32_t battery_charging_enable; /*!< Enable or disable Battery charging. */ |
||
| 113 | |||
| 114 | uint32_t vbus_sensing_enable; /*!< Enable or disable the VBUS Sensing feature. */ |
||
| 115 | |||
| 116 | uint32_t use_dedicated_ep1; /*!< Enable or disable the use of the dedicated EP1 interrupt. */ |
||
| 117 | |||
| 118 | uint32_t use_external_vbus; /*!< Enable or disable the use of the external VBUS. */ |
||
| 119 | |||
| 120 | } USB_OTG_CfgTypeDef; |
||
| 121 | |||
| 2 | mjames | 122 | typedef struct |
| 123 | { |
||
| 9 | mjames | 124 | uint8_t num; /*!< Endpoint number |
| 125 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ |
||
| 2 | mjames | 126 | |
| 9 | mjames | 127 | uint8_t is_in; /*!< Endpoint direction |
| 128 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 129 | |||
| 130 | uint8_t is_stall; /*!< Endpoint stall condition |
||
| 131 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 132 | |||
| 133 | uint8_t type; /*!< Endpoint type |
||
| 134 | This parameter can be any value of @ref USB_EP_Type_ */ |
||
| 135 | |||
| 136 | uint8_t data_pid_start; /*!< Initial data PID |
||
| 137 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 138 | |||
| 139 | uint8_t even_odd_frame; /*!< IFrame parity |
||
| 140 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 141 | |||
| 142 | uint16_t tx_fifo_num; /*!< Transmission FIFO number |
||
| 143 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ |
||
| 144 | |||
| 145 | uint32_t maxpacket; /*!< Endpoint Max packet size |
||
| 146 | This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */ |
||
| 147 | |||
| 148 | uint8_t *xfer_buff; /*!< Pointer to transfer buffer */ |
||
| 149 | |||
| 150 | uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address */ |
||
| 151 | |||
| 152 | uint32_t xfer_len; /*!< Current transfer length */ |
||
| 153 | |||
| 154 | uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */ |
||
| 155 | } USB_OTG_EPTypeDef; |
||
| 156 | |||
| 2 | mjames | 157 | typedef struct |
| 158 | { |
||
| 9 | mjames | 159 | uint8_t dev_addr; /*!< USB device address. |
| 160 | This parameter must be a number between Min_Data = 1 and Max_Data = 255 */ |
||
| 2 | mjames | 161 | |
| 9 | mjames | 162 | uint8_t ch_num; /*!< Host channel number. |
| 163 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ |
||
| 164 | |||
| 165 | uint8_t ep_num; /*!< Endpoint number. |
||
| 166 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ |
||
| 167 | |||
| 168 | uint8_t ep_is_in; /*!< Endpoint direction |
||
| 169 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 170 | |||
| 171 | uint8_t speed; /*!< USB Host speed. |
||
| 172 | This parameter can be any value of @ref USB_Core_Speed_ */ |
||
| 173 | |||
| 174 | uint8_t do_ping; /*!< Enable or disable the use of the PING protocol for HS mode. */ |
||
| 175 | |||
| 176 | uint8_t process_ping; /*!< Execute the PING protocol for HS mode. */ |
||
| 177 | |||
| 178 | uint8_t ep_type; /*!< Endpoint Type. |
||
| 179 | This parameter can be any value of @ref USB_EP_Type_ */ |
||
| 180 | |||
| 181 | uint16_t max_packet; /*!< Endpoint Max packet size. |
||
| 182 | This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */ |
||
| 183 | |||
| 184 | uint8_t data_pid; /*!< Initial data PID. |
||
| 185 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 186 | |||
| 187 | uint8_t *xfer_buff; /*!< Pointer to transfer buffer. */ |
||
| 188 | |||
| 189 | uint32_t xfer_len; /*!< Current transfer length. */ |
||
| 190 | |||
| 191 | uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer. */ |
||
| 192 | |||
| 193 | uint8_t toggle_in; /*!< IN transfer current toggle flag. |
||
| 194 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 195 | |||
| 196 | uint8_t toggle_out; /*!< OUT transfer current toggle flag |
||
| 197 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 198 | |||
| 199 | uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address. */ |
||
| 200 | |||
| 201 | uint32_t ErrCnt; /*!< Host channel error count. */ |
||
| 202 | |||
| 203 | USB_OTG_URBStateTypeDef urb_state; /*!< URB state. |
||
| 204 | This parameter can be any value of @ref USB_OTG_URBStateTypeDef */ |
||
| 205 | |||
| 206 | USB_OTG_HCStateTypeDef state; /*!< Host Channel state. |
||
| 207 | This parameter can be any value of @ref USB_OTG_HCStateTypeDef */ |
||
| 208 | } USB_OTG_HCTypeDef; |
||
| 209 | #endif /* defined (USB_OTG_FS) */ |
||
| 210 | |||
| 2 | mjames | 211 | #if defined (USB) |
| 9 | mjames | 212 | |
| 213 | typedef enum |
||
| 214 | { |
||
| 215 | USB_DEVICE_MODE = 0 |
||
| 216 | } USB_ModeTypeDef; |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @brief USB Initialization Structure definition |
||
| 2 | mjames | 220 | */ |
| 221 | typedef struct |
||
| 222 | { |
||
| 9 | mjames | 223 | uint32_t dev_endpoints; /*!< Device Endpoints number. |
| 224 | This parameter depends on the used USB core. |
||
| 225 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ |
||
| 226 | |||
| 227 | uint32_t speed; /*!< USB Core speed. |
||
| 228 | This parameter can be any value of @ref USB_Core_Speed */ |
||
| 229 | |||
| 230 | uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. */ |
||
| 231 | |||
| 232 | uint32_t phy_itface; /*!< Select the used PHY interface. |
||
| 233 | This parameter can be any value of @ref USB_Core_PHY */ |
||
| 234 | |||
| 235 | uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */ |
||
| 236 | |||
| 237 | uint32_t low_power_enable; /*!< Enable or disable Low Power mode */ |
||
| 238 | |||
| 239 | uint32_t lpm_enable; /*!< Enable or disable Battery charging. */ |
||
| 240 | |||
| 241 | uint32_t battery_charging_enable; /*!< Enable or disable Battery charging. */ |
||
| 2 | mjames | 242 | } USB_CfgTypeDef; |
| 243 | |||
| 244 | typedef struct |
||
| 245 | { |
||
| 9 | mjames | 246 | uint8_t num; /*!< Endpoint number |
| 247 | This parameter must be a number between Min_Data = 1 and Max_Data = 15 */ |
||
| 248 | |||
| 249 | uint8_t is_in; /*!< Endpoint direction |
||
| 250 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 251 | |||
| 252 | uint8_t is_stall; /*!< Endpoint stall condition |
||
| 253 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 254 | |||
| 255 | uint8_t type; /*!< Endpoint type |
||
| 256 | This parameter can be any value of @ref USB_EP_Type */ |
||
| 257 | |||
| 258 | uint8_t data_pid_start; /*!< Initial data PID |
||
| 259 | This parameter must be a number between Min_Data = 0 and Max_Data = 1 */ |
||
| 260 | |||
| 261 | uint16_t pmaadress; /*!< PMA Address |
||
| 262 | This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ |
||
| 263 | |||
| 264 | uint16_t pmaaddr0; /*!< PMA Address0 |
||
| 265 | This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ |
||
| 266 | |||
| 2 | mjames | 267 | uint16_t pmaaddr1; /*!< PMA Address1 |
| 9 | mjames | 268 | This parameter can be any value between Min_addr = 0 and Max_addr = 1K */ |
| 269 | |||
| 2 | mjames | 270 | uint8_t doublebuffer; /*!< Double buffer enable |
| 9 | mjames | 271 | This parameter can be 0 or 1 */ |
| 2 | mjames | 272 | |
| 9 | mjames | 273 | uint16_t tx_fifo_num; /*!< This parameter is not required by USB Device FS peripheral, it is used |
| 274 | only by USB OTG FS peripheral |
||
| 275 | This parameter is added to ensure compatibility across USB peripherals */ |
||
| 276 | |||
| 277 | uint32_t maxpacket; /*!< Endpoint Max packet size |
||
| 278 | This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */ |
||
| 279 | |||
| 280 | uint8_t *xfer_buff; /*!< Pointer to transfer buffer */ |
||
| 281 | |||
| 282 | uint32_t xfer_len; /*!< Current transfer length */ |
||
| 283 | |||
| 284 | uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */ |
||
| 285 | |||
| 286 | uint32_t xfer_len_db; /*!< double buffer transfer length used with bulk double buffer in */ |
||
| 287 | |||
| 288 | uint8_t xfer_fill_db; /*!< double buffer Need to Fill new buffer used with bulk_in */ |
||
| 289 | |||
| 2 | mjames | 290 | } USB_EPTypeDef; |
| 9 | mjames | 291 | #endif /* defined (USB) */ |
| 292 | |||
| 293 | /* Exported constants --------------------------------------------------------*/ |
||
| 294 | |||
| 295 | /** @defgroup PCD_Exported_Constants PCD Exported Constants |
||
| 296 | * @{ |
||
| 297 | */ |
||
| 298 | |||
| 299 | #if defined (USB_OTG_FS) |
||
| 300 | /** @defgroup USB_OTG_CORE VERSION ID |
||
| 301 | * @{ |
||
| 302 | */ |
||
| 303 | #define USB_OTG_CORE_ID_300A 0x4F54300AU |
||
| 304 | #define USB_OTG_CORE_ID_310A 0x4F54310AU |
||
| 2 | mjames | 305 | /** |
| 306 | * @} |
||
| 307 | */ |
||
| 308 | |||
| 9 | mjames | 309 | /** @defgroup USB_Core_Mode_ USB Core Mode |
| 2 | mjames | 310 | * @{ |
| 311 | */ |
||
| 9 | mjames | 312 | #define USB_OTG_MODE_DEVICE 0U |
| 313 | #define USB_OTG_MODE_HOST 1U |
||
| 314 | #define USB_OTG_MODE_DRD 2U |
||
| 315 | /** |
||
| 316 | * @} |
||
| 317 | */ |
||
| 318 | |||
| 319 | /** @defgroup USB_LL Device Speed |
||
| 2 | mjames | 320 | * @{ |
| 321 | */ |
||
| 9 | mjames | 322 | #define USBD_FS_SPEED 2U |
| 323 | #define USBH_FSLS_SPEED 1U |
||
| 2 | mjames | 324 | /** |
| 325 | * @} |
||
| 326 | */ |
||
| 327 | |||
| 328 | /** @defgroup USB_LL_Core_Speed USB Low Layer Core Speed |
||
| 329 | * @{ |
||
| 330 | */ |
||
| 9 | mjames | 331 | #define USB_OTG_SPEED_FULL 3U |
| 2 | mjames | 332 | /** |
| 333 | * @} |
||
| 334 | */ |
||
| 335 | |||
| 336 | /** @defgroup USB_LL_Core_PHY USB Low Layer Core PHY |
||
| 337 | * @{ |
||
| 338 | */ |
||
| 9 | mjames | 339 | #define USB_OTG_ULPI_PHY 1U |
| 340 | #define USB_OTG_EMBEDDED_PHY 2U |
||
| 2 | mjames | 341 | /** |
| 342 | * @} |
||
| 343 | */ |
||
| 344 | |||
| 9 | mjames | 345 | /** @defgroup USB_LL_Turnaround_Timeout Turnaround Timeout Value |
| 346 | * @{ |
||
| 347 | */ |
||
| 348 | #ifndef USBD_FS_TRDT_VALUE |
||
| 349 | #define USBD_FS_TRDT_VALUE 5U |
||
| 350 | #define USBD_DEFAULT_TRDT_VALUE 9U |
||
| 351 | #endif /* USBD_HS_TRDT_VALUE */ |
||
| 352 | /** |
||
| 353 | * @} |
||
| 354 | */ |
||
| 355 | |||
| 2 | mjames | 356 | /** @defgroup USB_LL_Core_MPS USB Low Layer Core MPS |
| 357 | * @{ |
||
| 358 | */ |
||
| 9 | mjames | 359 | #define USB_OTG_FS_MAX_PACKET_SIZE 64U |
| 360 | #define USB_OTG_MAX_EP0_SIZE 64U |
||
| 2 | mjames | 361 | /** |
| 362 | * @} |
||
| 363 | */ |
||
| 364 | |||
| 365 | /** @defgroup USB_LL_Core_PHY_Frequency USB Low Layer Core PHY Frequency |
||
| 366 | * @{ |
||
| 367 | */ |
||
| 9 | mjames | 368 | #define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ (0U << 1) |
| 369 | #define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ (1U << 1) |
||
| 370 | #define DSTS_ENUMSPD_FS_PHY_48MHZ (3U << 1) |
||
| 2 | mjames | 371 | /** |
| 372 | * @} |
||
| 373 | */ |
||
| 374 | |||
| 375 | /** @defgroup USB_LL_CORE_Frame_Interval USB Low Layer Core Frame Interval |
||
| 376 | * @{ |
||
| 377 | */ |
||
| 9 | mjames | 378 | #define DCFG_FRAME_INTERVAL_80 0U |
| 379 | #define DCFG_FRAME_INTERVAL_85 1U |
||
| 380 | #define DCFG_FRAME_INTERVAL_90 2U |
||
| 381 | #define DCFG_FRAME_INTERVAL_95 3U |
||
| 2 | mjames | 382 | /** |
| 383 | * @} |
||
| 384 | */ |
||
| 385 | |||
| 386 | /** @defgroup USB_LL_EP0_MPS USB Low Layer EP0 MPS |
||
| 387 | * @{ |
||
| 388 | */ |
||
| 9 | mjames | 389 | #define EP_MPS_64 0U |
| 390 | #define EP_MPS_32 1U |
||
| 391 | #define EP_MPS_16 2U |
||
| 392 | #define EP_MPS_8 3U |
||
| 2 | mjames | 393 | /** |
| 394 | * @} |
||
| 395 | */ |
||
| 396 | |||
| 397 | /** @defgroup USB_LL_EP_Speed USB Low Layer EP Speed |
||
| 398 | * @{ |
||
| 399 | */ |
||
| 9 | mjames | 400 | #define EP_SPEED_LOW 0U |
| 401 | #define EP_SPEED_FULL 1U |
||
| 402 | #define EP_SPEED_HIGH 2U |
||
| 2 | mjames | 403 | /** |
| 404 | * @} |
||
| 405 | */ |
||
| 406 | |||
| 407 | /** @defgroup USB_LL_EP_Type USB Low Layer EP Type |
||
| 408 | * @{ |
||
| 409 | */ |
||
| 9 | mjames | 410 | #define EP_TYPE_CTRL 0U |
| 411 | #define EP_TYPE_ISOC 1U |
||
| 412 | #define EP_TYPE_BULK 2U |
||
| 413 | #define EP_TYPE_INTR 3U |
||
| 414 | #define EP_TYPE_MSK 3U |
||
| 2 | mjames | 415 | /** |
| 416 | * @} |
||
| 417 | */ |
||
| 418 | |||
| 419 | /** @defgroup USB_LL_STS_Defines USB Low Layer STS Defines |
||
| 420 | * @{ |
||
| 421 | */ |
||
| 9 | mjames | 422 | #define STS_GOUT_NAK 1U |
| 423 | #define STS_DATA_UPDT 2U |
||
| 424 | #define STS_XFER_COMP 3U |
||
| 425 | #define STS_SETUP_COMP 4U |
||
| 426 | #define STS_SETUP_UPDT 6U |
||
| 2 | mjames | 427 | /** |
| 428 | * @} |
||
| 429 | */ |
||
| 430 | |||
| 431 | /** @defgroup USB_LL_HCFG_SPEED_Defines USB Low Layer HCFG Speed Defines |
||
| 432 | * @{ |
||
| 433 | */ |
||
| 9 | mjames | 434 | #define HCFG_30_60_MHZ 0U |
| 435 | #define HCFG_48_MHZ 1U |
||
| 436 | #define HCFG_6_MHZ 2U |
||
| 2 | mjames | 437 | /** |
| 438 | * @} |
||
| 439 | */ |
||
| 440 | |||
| 441 | /** @defgroup USB_LL_HPRT0_PRTSPD_SPEED_Defines USB Low Layer HPRT0 PRTSPD Speed Defines |
||
| 442 | * @{ |
||
| 443 | */ |
||
| 9 | mjames | 444 | #define HPRT0_PRTSPD_HIGH_SPEED 0U |
| 445 | #define HPRT0_PRTSPD_FULL_SPEED 1U |
||
| 446 | #define HPRT0_PRTSPD_LOW_SPEED 2U |
||
| 2 | mjames | 447 | /** |
| 448 | * @} |
||
| 449 | */ |
||
| 450 | |||
| 9 | mjames | 451 | #define HCCHAR_CTRL 0U |
| 452 | #define HCCHAR_ISOC 1U |
||
| 453 | #define HCCHAR_BULK 2U |
||
| 454 | #define HCCHAR_INTR 3U |
||
| 2 | mjames | 455 | |
| 9 | mjames | 456 | #define HC_PID_DATA0 0U |
| 457 | #define HC_PID_DATA2 1U |
||
| 458 | #define HC_PID_DATA1 2U |
||
| 459 | #define HC_PID_SETUP 3U |
||
| 2 | mjames | 460 | |
| 9 | mjames | 461 | #define GRXSTS_PKTSTS_IN 2U |
| 462 | #define GRXSTS_PKTSTS_IN_XFER_COMP 3U |
||
| 463 | #define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5U |
||
| 464 | #define GRXSTS_PKTSTS_CH_HALTED 7U |
||
| 2 | mjames | 465 | |
| 9 | mjames | 466 | #define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_PCGCCTL_BASE) |
| 467 | #define USBx_HPRT0 *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_HOST_PORT_BASE) |
||
| 2 | mjames | 468 | |
| 9 | mjames | 469 | #define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)(USBx_BASE + USB_OTG_DEVICE_BASE)) |
| 470 | #define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)(USBx_BASE + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE))) |
||
| 471 | #define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)(USBx_BASE + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE))) |
||
| 472 | #define USBx_DFIFO(i) *(__IO uint32_t *)(USBx_BASE + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE)) |
||
| 2 | mjames | 473 | |
| 9 | mjames | 474 | #define USBx_HOST ((USB_OTG_HostTypeDef *)(USBx_BASE + USB_OTG_HOST_BASE)) |
| 475 | #define USBx_HC(i) ((USB_OTG_HostChannelTypeDef *)(USBx_BASE + USB_OTG_HOST_CHANNEL_BASE + ((i) * USB_OTG_HOST_CHANNEL_SIZE))) |
||
| 476 | #endif /* defined (USB_OTG_FS) */ |
||
| 2 | mjames | 477 | |
| 9 | mjames | 478 | #if defined (USB) |
| 2 | mjames | 479 | /** @defgroup USB_LL_EP0_MPS USB Low Layer EP0 MPS |
| 480 | * @{ |
||
| 481 | */ |
||
| 9 | mjames | 482 | #define EP_MPS_64 0U |
| 483 | #define EP_MPS_32 1U |
||
| 484 | #define EP_MPS_16 2U |
||
| 485 | #define EP_MPS_8 3U |
||
| 2 | mjames | 486 | /** |
| 487 | * @} |
||
| 9 | mjames | 488 | */ |
| 2 | mjames | 489 | |
| 490 | /** @defgroup USB_LL_EP_Type USB Low Layer EP Type |
||
| 491 | * @{ |
||
| 492 | */ |
||
| 9 | mjames | 493 | #define EP_TYPE_CTRL 0U |
| 494 | #define EP_TYPE_ISOC 1U |
||
| 495 | #define EP_TYPE_BULK 2U |
||
| 496 | #define EP_TYPE_INTR 3U |
||
| 497 | #define EP_TYPE_MSK 3U |
||
| 2 | mjames | 498 | /** |
| 499 | * @} |
||
| 9 | mjames | 500 | */ |
| 2 | mjames | 501 | |
| 9 | mjames | 502 | /** @defgroup USB_LL Device Speed |
| 503 | * @{ |
||
| 504 | */ |
||
| 505 | #define USBD_FS_SPEED 2U |
||
| 2 | mjames | 506 | /** |
| 507 | * @} |
||
| 508 | */ |
||
| 509 | |||
| 9 | mjames | 510 | #define BTABLE_ADDRESS 0x000U |
| 511 | #define PMA_ACCESS 2U |
||
| 512 | #endif /* defined (USB) */ |
||
| 513 | #if defined (USB_OTG_FS) |
||
| 514 | #define EP_ADDR_MSK 0xFU |
||
| 515 | #endif /* defined (USB_OTG_FS) */ |
||
| 516 | #if defined (USB) |
||
| 517 | #define EP_ADDR_MSK 0x7U |
||
| 518 | #endif /* defined (USB) */ |
||
| 519 | /** |
||
| 520 | * @} |
||
| 521 | */ |
||
| 522 | |||
| 523 | /* Exported macro ------------------------------------------------------------*/ |
||
| 2 | mjames | 524 | /** @defgroup USB_LL_Exported_Macros USB Low Layer Exported Macros |
| 525 | * @{ |
||
| 526 | */ |
||
| 527 | #if defined (USB_OTG_FS) |
||
| 528 | #define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK &= ~(__INTERRUPT__)) |
||
| 529 | #define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK |= (__INTERRUPT__)) |
||
| 530 | |||
| 531 | #define CLEAR_IN_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_INEP(__EPNUM__)->DIEPINT = (__INTERRUPT__)) |
||
| 532 | #define CLEAR_OUT_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_OUTEP(__EPNUM__)->DOEPINT = (__INTERRUPT__)) |
||
| 9 | mjames | 533 | #endif /* defined (USB_OTG_FS) */ |
| 2 | mjames | 534 | /** |
| 535 | * @} |
||
| 536 | */ |
||
| 537 | |||
| 538 | /* Exported functions --------------------------------------------------------*/ |
||
| 539 | /** @addtogroup USB_LL_Exported_Functions USB Low Layer Exported Functions |
||
| 540 | * @{ |
||
| 541 | */ |
||
| 542 | #if defined (USB_OTG_FS) |
||
| 9 | mjames | 543 | HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg); |
| 544 | HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg); |
||
| 2 | mjames | 545 | HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx); |
| 546 | HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx); |
||
| 9 | mjames | 547 | HAL_StatusTypeDef USB_SetTurnaroundTime(USB_OTG_GlobalTypeDef *USBx, uint32_t hclk, uint8_t speed); |
| 548 | HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_ModeTypeDef mode); |
||
| 549 | HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx, uint8_t speed); |
||
| 550 | HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx); |
||
| 551 | HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num); |
||
| 2 | mjames | 552 | HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); |
| 553 | HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); |
||
| 9 | mjames | 554 | HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); |
| 555 | HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); |
||
| 556 | HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); |
||
| 557 | HAL_StatusTypeDef USB_EP0StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); |
||
| 558 | HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, |
||
| 559 | uint8_t ch_ep_num, uint16_t len); |
||
| 560 | |||
| 561 | void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len); |
||
| 562 | HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); |
||
| 563 | HAL_StatusTypeDef USB_EPClearStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep); |
||
| 564 | HAL_StatusTypeDef USB_SetDevAddress(USB_OTG_GlobalTypeDef *USBx, uint8_t address); |
||
| 565 | HAL_StatusTypeDef USB_DevConnect(USB_OTG_GlobalTypeDef *USBx); |
||
| 566 | HAL_StatusTypeDef USB_DevDisconnect(USB_OTG_GlobalTypeDef *USBx); |
||
| 2 | mjames | 567 | HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx); |
| 9 | mjames | 568 | HAL_StatusTypeDef USB_ActivateSetup(USB_OTG_GlobalTypeDef *USBx); |
| 2 | mjames | 569 | HAL_StatusTypeDef USB_EP0_OutStart(USB_OTG_GlobalTypeDef *USBx, uint8_t *psetup); |
| 570 | uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx); |
||
| 571 | uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx); |
||
| 9 | mjames | 572 | uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef *USBx); |
| 573 | uint32_t USB_ReadDevAllOutEpInterrupt(USB_OTG_GlobalTypeDef *USBx); |
||
| 574 | uint32_t USB_ReadDevOutEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum); |
||
| 575 | uint32_t USB_ReadDevAllInEpInterrupt(USB_OTG_GlobalTypeDef *USBx); |
||
| 576 | uint32_t USB_ReadDevInEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum); |
||
| 577 | void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt); |
||
| 2 | mjames | 578 | |
| 9 | mjames | 579 | HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg); |
| 580 | HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx, uint8_t freq); |
||
| 2 | mjames | 581 | HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx); |
| 9 | mjames | 582 | HAL_StatusTypeDef USB_DriveVbus(USB_OTG_GlobalTypeDef *USBx, uint8_t state); |
| 583 | uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef *USBx); |
||
| 584 | uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef *USBx); |
||
| 585 | HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num, |
||
| 586 | uint8_t epnum, uint8_t dev_address, uint8_t speed, |
||
| 587 | uint8_t ep_type, uint16_t mps); |
||
| 588 | HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, |
||
| 589 | USB_OTG_HCTypeDef *hc); |
||
| 590 | |||
| 591 | uint32_t USB_HC_ReadInterrupt(USB_OTG_GlobalTypeDef *USBx); |
||
| 592 | HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num); |
||
| 593 | HAL_StatusTypeDef USB_DoPing(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num); |
||
| 2 | mjames | 594 | HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx); |
| 595 | HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx); |
||
| 596 | HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx); |
||
| 9 | mjames | 597 | #endif /* defined (USB_OTG_FS) */ |
| 2 | mjames | 598 | |
| 599 | #if defined (USB) |
||
| 9 | mjames | 600 | HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg); |
| 601 | HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg); |
||
| 2 | mjames | 602 | HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx); |
| 603 | HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx); |
||
| 9 | mjames | 604 | HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode); |
| 605 | HAL_StatusTypeDef USB_SetDevSpeed(USB_TypeDef *USBx, uint8_t speed); |
||
| 606 | HAL_StatusTypeDef USB_FlushRxFifo(USB_TypeDef *USBx); |
||
| 607 | HAL_StatusTypeDef USB_FlushTxFifo(USB_TypeDef *USBx, uint32_t num); |
||
| 2 | mjames | 608 | HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep); |
| 609 | HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep); |
||
| 9 | mjames | 610 | HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep); |
| 611 | HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep); |
||
| 612 | HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep); |
||
| 613 | HAL_StatusTypeDef USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address); |
||
| 614 | HAL_StatusTypeDef USB_DevConnect(USB_TypeDef *USBx); |
||
| 615 | HAL_StatusTypeDef USB_DevDisconnect(USB_TypeDef *USBx); |
||
| 2 | mjames | 616 | HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx); |
| 617 | HAL_StatusTypeDef USB_EP0_OutStart(USB_TypeDef *USBx, uint8_t *psetup); |
||
| 9 | mjames | 618 | HAL_StatusTypeDef USB_WritePacket(USB_TypeDef *USBx, uint8_t *src, |
| 619 | uint8_t ch_ep_num, uint16_t len); |
||
| 2 | mjames | 620 | |
| 9 | mjames | 621 | void *USB_ReadPacket(USB_TypeDef *USBx, uint8_t *dest, uint16_t len); |
| 622 | |||
| 623 | uint32_t USB_ReadInterrupts(USB_TypeDef *USBx); |
||
| 624 | uint32_t USB_ReadDevAllOutEpInterrupt(USB_TypeDef *USBx); |
||
| 625 | uint32_t USB_ReadDevOutEPInterrupt(USB_TypeDef *USBx, uint8_t epnum); |
||
| 626 | uint32_t USB_ReadDevAllInEpInterrupt(USB_TypeDef *USBx); |
||
| 627 | uint32_t USB_ReadDevInEPInterrupt(USB_TypeDef *USBx, uint8_t epnum); |
||
| 628 | void USB_ClearInterrupts(USB_TypeDef *USBx, uint32_t interrupt); |
||
| 2 | mjames | 629 | HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx); |
| 630 | HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx); |
||
| 9 | mjames | 631 | |
| 632 | void USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, |
||
| 633 | uint16_t wPMABufAddr, uint16_t wNBytes); |
||
| 634 | |||
| 635 | void USB_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, |
||
| 636 | uint16_t wPMABufAddr, uint16_t wNBytes); |
||
| 637 | #endif /* defined (USB) */ |
||
| 2 | mjames | 638 | /** |
| 639 | * @} |
||
| 640 | */ |
||
| 9 | mjames | 641 | |
| 2 | mjames | 642 | /** |
| 643 | * @} |
||
| 644 | */ |
||
| 645 | |||
| 646 | /** |
||
| 647 | * @} |
||
| 9 | mjames | 648 | */ |
| 2 | mjames | 649 | |
| 650 | /** |
||
| 651 | * @} |
||
| 652 | */ |
||
| 9 | mjames | 653 | #endif /* defined (USB) || defined (USB_OTG_FS) */ |
| 2 | mjames | 654 | |
| 655 | #ifdef __cplusplus |
||
| 656 | } |
||
| 657 | #endif |
||
| 658 | |||
| 659 | |||
| 9 | mjames | 660 | #endif /* STM32F1xx_LL_USB_H */ |
| 2 | mjames | 661 | |
| 662 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |