stm32l4xx_ll_usb.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_usb.h
  4. * @author MCD Application Team
  5. * @brief Header file of USB Low Layer HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32L4xx_LL_USB_H
  20. #define STM32L4xx_LL_USB_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif /* __cplusplus */
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l4xx_hal_def.h"
  26. #if defined (USB) || defined (USB_OTG_FS)
  27. /** @addtogroup STM32L4xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup USB_LL
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. #ifndef HAL_USB_TIMEOUT
  35. #define HAL_USB_TIMEOUT 0xF000000U
  36. #endif /* define HAL_USB_TIMEOUT */
  37. #ifndef HAL_USB_CURRENT_MODE_MAX_DELAY_MS
  38. #define HAL_USB_CURRENT_MODE_MAX_DELAY_MS 200U
  39. #endif /* define HAL_USB_CURRENT_MODE_MAX_DELAY_MS */
  40. /**
  41. * @brief USB Mode definition
  42. */
  43. typedef enum
  44. {
  45. USB_DEVICE_MODE = 0,
  46. USB_HOST_MODE = 1,
  47. USB_DRD_MODE = 2
  48. } USB_ModeTypeDef;
  49. /**
  50. * @brief URB States definition
  51. */
  52. typedef enum
  53. {
  54. URB_IDLE = 0,
  55. URB_DONE,
  56. URB_NOTREADY,
  57. URB_NYET,
  58. URB_ERROR,
  59. URB_STALL
  60. } USB_URBStateTypeDef;
  61. /**
  62. * @brief Host channel States definition
  63. */
  64. typedef enum
  65. {
  66. HC_IDLE = 0,
  67. HC_XFRC,
  68. HC_HALTED,
  69. HC_ACK,
  70. HC_NAK,
  71. HC_NYET,
  72. HC_STALL,
  73. HC_XACTERR,
  74. HC_BBLERR,
  75. HC_DATATGLERR
  76. } USB_HCStateTypeDef;
  77. /**
  78. * @brief USB Instance Initialization Structure definition
  79. */
  80. typedef struct
  81. {
  82. uint8_t dev_endpoints; /*!< Device Endpoints number.
  83. This parameter depends on the used USB core.
  84. This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
  85. #if defined (USB_OTG_FS)
  86. uint8_t Host_channels; /*!< Host Channels number.
  87. This parameter Depends on the used USB core.
  88. This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
  89. #endif /* defined (USB_OTG_FS) */
  90. uint8_t dma_enable; /*!< USB DMA state.
  91. If DMA is not supported this parameter shall be set by default to zero */
  92. uint8_t speed; /*!< USB Core speed.
  93. This parameter can be any value of @ref PCD_Speed/HCD_Speed
  94. (HCD_SPEED_xxx, HCD_SPEED_xxx) */
  95. uint8_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. */
  96. uint8_t phy_itface; /*!< Select the used PHY interface.
  97. This parameter can be any value of @ref PCD_PHY_Module/HCD_PHY_Module */
  98. uint8_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */
  99. uint8_t low_power_enable; /*!< Enable or disable the low Power Mode. */
  100. uint8_t lpm_enable; /*!< Enable or disable Link Power Management. */
  101. uint8_t battery_charging_enable; /*!< Enable or disable Battery charging. */
  102. #if defined (USB_OTG_FS)
  103. uint8_t vbus_sensing_enable; /*!< Enable or disable the VBUS Sensing feature. */
  104. uint8_t use_dedicated_ep1; /*!< Enable or disable the use of the dedicated EP1 interrupt. */
  105. uint8_t use_external_vbus; /*!< Enable or disable the use of the external VBUS. */
  106. #endif /* defined (USB_OTG_FS) */
  107. } USB_CfgTypeDef;
  108. typedef struct
  109. {
  110. uint8_t num; /*!< Endpoint number
  111. This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
  112. uint8_t is_in; /*!< Endpoint direction
  113. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  114. uint8_t is_stall; /*!< Endpoint stall condition
  115. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  116. #if defined (USB_OTG_FS)
  117. uint8_t is_iso_incomplete; /*!< Endpoint isoc condition
  118. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  119. #endif /* defined (USB_OTG_FS) */
  120. uint8_t type; /*!< Endpoint type
  121. This parameter can be any value of @ref USB_LL_EP_Type */
  122. uint8_t data_pid_start; /*!< Initial data PID
  123. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  124. #if defined (USB)
  125. uint16_t pmaadress; /*!< PMA Address
  126. This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
  127. uint16_t pmaaddr0; /*!< PMA Address0
  128. This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
  129. uint16_t pmaaddr1; /*!< PMA Address1
  130. This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
  131. uint8_t doublebuffer; /*!< Double buffer enable
  132. This parameter can be 0 or 1 */
  133. #endif /* defined (USB) */
  134. uint32_t maxpacket; /*!< Endpoint Max packet size
  135. This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
  136. uint8_t *xfer_buff; /*!< Pointer to transfer buffer */
  137. uint32_t xfer_len; /*!< Current transfer length */
  138. uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */
  139. #if defined (USB_OTG_FS)
  140. uint8_t even_odd_frame; /*!< IFrame parity
  141. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  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. uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address */
  145. uint32_t xfer_size; /*!< requested transfer size */
  146. #endif /* defined (USB_OTG_FS) */
  147. #if defined (USB)
  148. uint32_t xfer_len_db; /*!< double buffer transfer length used with bulk double buffer in */
  149. uint8_t xfer_fill_db; /*!< double buffer Need to Fill new buffer used with bulk_in */
  150. #endif /* defined (USB) */
  151. } USB_EPTypeDef;
  152. typedef struct
  153. {
  154. uint8_t dev_addr; /*!< USB device address.
  155. This parameter must be a number between Min_Data = 1 and Max_Data = 255 */
  156. uint8_t ch_num; /*!< Host channel number.
  157. This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
  158. uint8_t ep_num; /*!< Endpoint number.
  159. This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
  160. uint8_t ep_is_in; /*!< Endpoint direction
  161. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  162. uint8_t speed; /*!< USB Host Channel speed.
  163. This parameter can be any value of @ref HCD_Device_Speed:
  164. (HCD_DEVICE_SPEED_xxx) */
  165. uint8_t do_ping; /*!< Enable or disable the use of the PING protocol for HS mode. */
  166. uint8_t hub_port_nbr; /*!< USB HUB port number */
  167. uint8_t hub_addr; /*!< USB HUB address */
  168. uint8_t ep_type; /*!< Endpoint Type.
  169. This parameter can be any value of @ref USB_LL_EP_Type */
  170. uint16_t max_packet; /*!< Endpoint Max packet size.
  171. This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
  172. uint8_t data_pid; /*!< Initial data PID.
  173. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  174. uint8_t *xfer_buff; /*!< Pointer to transfer buffer. */
  175. uint32_t XferSize; /*!< OTG Channel transfer size. */
  176. uint32_t xfer_len; /*!< Current transfer length. */
  177. uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer. */
  178. uint8_t toggle_in; /*!< IN transfer current toggle flag.
  179. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  180. uint8_t toggle_out; /*!< OUT transfer current toggle flag
  181. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  182. uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address. */
  183. uint32_t ErrCnt; /*!< Host channel error count. */
  184. USB_URBStateTypeDef urb_state; /*!< URB state.
  185. This parameter can be any value of @ref USB_URBStateTypeDef */
  186. USB_HCStateTypeDef state; /*!< Host Channel state.
  187. This parameter can be any value of @ref USB_HCStateTypeDef */
  188. } USB_HCTypeDef;
  189. #if defined (USB_OTG_FS)
  190. typedef USB_ModeTypeDef USB_OTG_ModeTypeDef;
  191. typedef USB_CfgTypeDef USB_OTG_CfgTypeDef;
  192. typedef USB_EPTypeDef USB_OTG_EPTypeDef;
  193. typedef USB_URBStateTypeDef USB_OTG_URBStateTypeDef;
  194. typedef USB_HCStateTypeDef USB_OTG_HCStateTypeDef;
  195. typedef USB_HCTypeDef USB_OTG_HCTypeDef;
  196. #endif /* defined (USB_OTG_FS) */
  197. /* Exported constants --------------------------------------------------------*/
  198. /** @defgroup PCD_Exported_Constants PCD Exported Constants
  199. * @{
  200. */
  201. #if defined (USB_OTG_FS)
  202. /** @defgroup USB_OTG_CORE VERSION ID
  203. * @{
  204. */
  205. #define USB_OTG_CORE_ID_300A 0x4F54300AU
  206. #define USB_OTG_CORE_ID_310A 0x4F54310AU
  207. /**
  208. * @}
  209. */
  210. /** @defgroup USB_Core_Mode_ USB Core Mode
  211. * @{
  212. */
  213. #define USB_OTG_MODE_DEVICE 0U
  214. #define USB_OTG_MODE_HOST 1U
  215. #define USB_OTG_MODE_DRD 2U
  216. /**
  217. * @}
  218. */
  219. /** @defgroup USB_LL_Core_Speed USB Low Layer Core Speed
  220. * @{
  221. */
  222. #define USB_OTG_SPEED_FULL 3U
  223. /**
  224. * @}
  225. */
  226. /** @defgroup USB_LL_Core_PHY USB Low Layer Core PHY
  227. * @{
  228. */
  229. #define USB_OTG_EMBEDDED_PHY 2U
  230. /**
  231. * @}
  232. */
  233. /** @defgroup USB_LL_Turnaround_Timeout Turnaround Timeout Value
  234. * @{
  235. */
  236. #ifndef USBD_FS_TRDT_VALUE
  237. #define USBD_FS_TRDT_VALUE 5U
  238. #define USBD_DEFAULT_TRDT_VALUE 9U
  239. #endif /* USBD_HS_TRDT_VALUE */
  240. /**
  241. * @}
  242. */
  243. /** @defgroup USB_LL_Core_MPS USB Low Layer Core MPS
  244. * @{
  245. */
  246. #define USB_OTG_FS_MAX_PACKET_SIZE 64U
  247. #define USB_OTG_MAX_EP0_SIZE 64U
  248. /**
  249. * @}
  250. */
  251. /** @defgroup USB_LL_Core_PHY_Frequency USB Low Layer Core PHY Frequency
  252. * @{
  253. */
  254. #define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ (0U << 1)
  255. #define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ (1U << 1)
  256. #define DSTS_ENUMSPD_FS_PHY_48MHZ (3U << 1)
  257. /**
  258. * @}
  259. */
  260. /** @defgroup USB_LL_CORE_Frame_Interval USB Low Layer Core Frame Interval
  261. * @{
  262. */
  263. #define DCFG_FRAME_INTERVAL_80 0U
  264. #define DCFG_FRAME_INTERVAL_85 1U
  265. #define DCFG_FRAME_INTERVAL_90 2U
  266. #define DCFG_FRAME_INTERVAL_95 3U
  267. /**
  268. * @}
  269. */
  270. #endif /* defined (USB_OTG_FS) */
  271. /** @defgroup USB_LL_EP0_MPS USB Low Layer EP0 MPS
  272. * @{
  273. */
  274. #define EP_MPS_64 0U
  275. #define EP_MPS_32 1U
  276. #define EP_MPS_16 2U
  277. #define EP_MPS_8 3U
  278. /**
  279. * @}
  280. */
  281. /** @defgroup USB_LL_EP_Type USB Low Layer EP Type
  282. * @{
  283. */
  284. #define EP_TYPE_CTRL 0U
  285. #define EP_TYPE_ISOC 1U
  286. #define EP_TYPE_BULK 2U
  287. #define EP_TYPE_INTR 3U
  288. #define EP_TYPE_MSK 3U
  289. /**
  290. * @}
  291. */
  292. /** @defgroup USB_LL_EP_Speed USB Low Layer EP Speed
  293. * @{
  294. */
  295. #define EP_SPEED_LOW 0U
  296. #define EP_SPEED_FULL 1U
  297. #define EP_SPEED_HIGH 2U
  298. /**
  299. * @}
  300. */
  301. /** @defgroup USB_LL_CH_PID_Type USB Low Layer Channel PID Type
  302. * @{
  303. */
  304. #define HC_PID_DATA0 0U
  305. #define HC_PID_DATA2 1U
  306. #define HC_PID_DATA1 2U
  307. #define HC_PID_SETUP 3U
  308. /**
  309. * @}
  310. */
  311. /** @defgroup USB_LL Device Speed
  312. * @{
  313. */
  314. #define USBD_FS_SPEED 2U
  315. #define USBH_FSLS_SPEED 1U
  316. /**
  317. * @}
  318. */
  319. #if defined (USB_OTG_FS)
  320. /** @defgroup USB_LL_STS_Defines USB Low Layer STS Defines
  321. * @{
  322. */
  323. #define STS_GOUT_NAK 1U
  324. #define STS_DATA_UPDT 2U
  325. #define STS_XFER_COMP 3U
  326. #define STS_SETUP_COMP 4U
  327. #define STS_SETUP_UPDT 6U
  328. /**
  329. * @}
  330. */
  331. /** @defgroup USB_LL_HCFG_SPEED_Defines USB Low Layer HCFG Speed Defines
  332. * @{
  333. */
  334. #define HCFG_30_60_MHZ 0U
  335. #define HCFG_48_MHZ 1U
  336. #define HCFG_6_MHZ 2U
  337. /**
  338. * @}
  339. */
  340. /** @defgroup USB_LL_HFIR_Defines USB Low Layer frame interval Defines
  341. * @{
  342. */
  343. #define HFIR_6_MHZ 6000U
  344. #define HFIR_60_MHZ 60000U
  345. #define HFIR_48_MHZ 48000U
  346. /**
  347. * @}
  348. */
  349. /** @defgroup USB_LL_HPRT0_PRTSPD_SPEED_Defines USB Low Layer HPRT0 PRTSPD Speed Defines
  350. * @{
  351. */
  352. #define HPRT0_PRTSPD_HIGH_SPEED 0U
  353. #define HPRT0_PRTSPD_FULL_SPEED 1U
  354. #define HPRT0_PRTSPD_LOW_SPEED 2U
  355. /**
  356. * @}
  357. */
  358. #define HCCHAR_CTRL 0U
  359. #define HCCHAR_ISOC 1U
  360. #define HCCHAR_BULK 2U
  361. #define HCCHAR_INTR 3U
  362. #define GRXSTS_PKTSTS_IN 2U
  363. #define GRXSTS_PKTSTS_IN_XFER_COMP 3U
  364. #define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5U
  365. #define GRXSTS_PKTSTS_CH_HALTED 7U
  366. #define CLEAR_INTERRUPT_MASK 0xFFFFFFFFU
  367. #define HC_MAX_PKT_CNT 256U
  368. #define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_PCGCCTL_BASE)
  369. #define USBx_HPRT0 *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_HOST_PORT_BASE)
  370. #define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)(USBx_BASE + USB_OTG_DEVICE_BASE))
  371. #define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)(USBx_BASE\
  372. + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
  373. #define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)(USBx_BASE\
  374. + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
  375. #define USBx_DFIFO(i) *(__IO uint32_t *)(USBx_BASE + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE))
  376. #define USBx_HOST ((USB_OTG_HostTypeDef *)(USBx_BASE + USB_OTG_HOST_BASE))
  377. #define USBx_HC(i) ((USB_OTG_HostChannelTypeDef *)(USBx_BASE\
  378. + USB_OTG_HOST_CHANNEL_BASE\
  379. + ((i) * USB_OTG_HOST_CHANNEL_SIZE)))
  380. #define EP_ADDR_MSK 0xFU
  381. #endif /* defined (USB_OTG_FS) */
  382. #if defined (USB)
  383. #define BTABLE_ADDRESS 0x000U
  384. #define PMA_ACCESS 1U
  385. #ifndef USB_EP_RX_STRX
  386. #define USB_EP_RX_STRX (0x3U << 12)
  387. #endif /* USB_EP_RX_STRX */
  388. #define EP_ADDR_MSK 0x7U
  389. #ifndef USE_USB_DOUBLE_BUFFER
  390. #define USE_USB_DOUBLE_BUFFER 1U
  391. #endif /* USE_USB_DOUBLE_BUFFER */
  392. #endif /* defined (USB) */
  393. /**
  394. * @}
  395. */
  396. /* Exported macro ------------------------------------------------------------*/
  397. /** @defgroup USB_LL_Exported_Macros USB Low Layer Exported Macros
  398. * @{
  399. */
  400. #if defined (USB_OTG_FS)
  401. #define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK &= ~(__INTERRUPT__))
  402. #define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK |= (__INTERRUPT__))
  403. #define CLEAR_IN_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_INEP(__EPNUM__)->DIEPINT = (__INTERRUPT__))
  404. #define CLEAR_OUT_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_OUTEP(__EPNUM__)->DOEPINT = (__INTERRUPT__))
  405. #endif /* defined (USB_OTG_FS) */
  406. /**
  407. * @}
  408. */
  409. /* Exported functions --------------------------------------------------------*/
  410. /** @addtogroup USB_LL_Exported_Functions USB Low Layer Exported Functions
  411. * @{
  412. */
  413. #if defined (USB_OTG_FS)
  414. HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
  415. HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
  416. HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
  417. HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
  418. HAL_StatusTypeDef USB_SetTurnaroundTime(USB_OTG_GlobalTypeDef *USBx, uint32_t hclk, uint8_t speed);
  419. HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_ModeTypeDef mode);
  420. HAL_StatusTypeDef USB_SetDevSpeed(const USB_OTG_GlobalTypeDef *USBx, uint8_t speed);
  421. HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx);
  422. HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num);
  423. HAL_StatusTypeDef USB_ActivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
  424. HAL_StatusTypeDef USB_DeactivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
  425. HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
  426. HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
  427. HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
  428. HAL_StatusTypeDef USB_WritePacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
  429. uint8_t ch_ep_num, uint16_t len);
  430. void *USB_ReadPacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len);
  431. HAL_StatusTypeDef USB_EPSetStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
  432. HAL_StatusTypeDef USB_EPClearStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
  433. HAL_StatusTypeDef USB_EPStopXfer(const USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
  434. HAL_StatusTypeDef USB_SetDevAddress(const USB_OTG_GlobalTypeDef *USBx, uint8_t address);
  435. HAL_StatusTypeDef USB_DevConnect(const USB_OTG_GlobalTypeDef *USBx);
  436. HAL_StatusTypeDef USB_DevDisconnect(const USB_OTG_GlobalTypeDef *USBx);
  437. HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx);
  438. HAL_StatusTypeDef USB_ActivateSetup(const USB_OTG_GlobalTypeDef *USBx);
  439. HAL_StatusTypeDef USB_EP0_OutStart(const USB_OTG_GlobalTypeDef *USBx, const uint8_t *psetup);
  440. uint8_t USB_GetDevSpeed(const USB_OTG_GlobalTypeDef *USBx);
  441. uint32_t USB_GetMode(const USB_OTG_GlobalTypeDef *USBx);
  442. uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef const *USBx);
  443. uint32_t USB_ReadChInterrupts(const USB_OTG_GlobalTypeDef *USBx, uint8_t chnum);
  444. uint32_t USB_ReadDevAllOutEpInterrupt(const USB_OTG_GlobalTypeDef *USBx);
  445. uint32_t USB_ReadDevOutEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum);
  446. uint32_t USB_ReadDevAllInEpInterrupt(const USB_OTG_GlobalTypeDef *USBx);
  447. uint32_t USB_ReadDevInEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum);
  448. void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt);
  449. HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
  450. HAL_StatusTypeDef USB_InitFSLSPClkSel(const USB_OTG_GlobalTypeDef *USBx, uint8_t freq);
  451. HAL_StatusTypeDef USB_ResetPort(const USB_OTG_GlobalTypeDef *USBx);
  452. HAL_StatusTypeDef USB_DriveVbus(const USB_OTG_GlobalTypeDef *USBx, uint8_t state);
  453. uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef const *USBx);
  454. uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef const *USBx);
  455. HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num,
  456. uint8_t epnum, uint8_t dev_address, uint8_t speed,
  457. uint8_t ep_type, uint16_t mps);
  458. HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx,
  459. USB_OTG_HCTypeDef *hc);
  460. uint32_t USB_HC_ReadInterrupt(const USB_OTG_GlobalTypeDef *USBx);
  461. HAL_StatusTypeDef USB_HC_Halt(const USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num);
  462. HAL_StatusTypeDef USB_DoPing(const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num);
  463. HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx);
  464. HAL_StatusTypeDef USB_ActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx);
  465. HAL_StatusTypeDef USB_DeActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx);
  466. #endif /* defined (USB_OTG_FS) */
  467. #if defined (USB)
  468. HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg);
  469. HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg);
  470. HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx);
  471. HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx);
  472. HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode);
  473. HAL_StatusTypeDef USB_SetDevSpeed(USB_TypeDef *USBx, uint8_t speed);
  474. HAL_StatusTypeDef USB_FlushRxFifo(USB_TypeDef const *USBx);
  475. HAL_StatusTypeDef USB_FlushTxFifo(USB_TypeDef const *USBx, uint32_t num);
  476. #if defined (HAL_PCD_MODULE_ENABLED)
  477. HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  478. HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  479. HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  480. HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  481. HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  482. HAL_StatusTypeDef USB_EPStopXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  483. #endif /* defined (HAL_PCD_MODULE_ENABLED) */
  484. HAL_StatusTypeDef USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address);
  485. HAL_StatusTypeDef USB_DevConnect(USB_TypeDef *USBx);
  486. HAL_StatusTypeDef USB_DevDisconnect(USB_TypeDef *USBx);
  487. HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx);
  488. HAL_StatusTypeDef USB_EP0_OutStart(USB_TypeDef *USBx, uint8_t *psetup);
  489. HAL_StatusTypeDef USB_WritePacket(USB_TypeDef *USBx, uint8_t *src,
  490. uint8_t ch_ep_num, uint16_t len);
  491. void *USB_ReadPacket(USB_TypeDef *USBx, uint8_t *dest, uint16_t len);
  492. uint32_t USB_ReadInterrupts(USB_TypeDef const *USBx);
  493. uint32_t USB_ReadDevAllOutEpInterrupt(USB_TypeDef *USBx);
  494. uint32_t USB_ReadDevOutEPInterrupt(USB_TypeDef *USBx, uint8_t epnum);
  495. uint32_t USB_ReadDevAllInEpInterrupt(USB_TypeDef *USBx);
  496. uint32_t USB_ReadDevInEPInterrupt(USB_TypeDef *USBx, uint8_t epnum);
  497. void USB_ClearInterrupts(USB_TypeDef *USBx, uint32_t interrupt);
  498. HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx);
  499. HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx);
  500. void USB_WritePMA(USB_TypeDef const *USBx, uint8_t *pbUsrBuf,
  501. uint16_t wPMABufAddr, uint16_t wNBytes);
  502. void USB_ReadPMA(USB_TypeDef const *USBx, uint8_t *pbUsrBuf,
  503. uint16_t wPMABufAddr, uint16_t wNBytes);
  504. #endif /* defined (USB) */
  505. /**
  506. * @}
  507. */
  508. /**
  509. * @}
  510. */
  511. /**
  512. * @}
  513. */
  514. /**
  515. * @}
  516. */
  517. #endif /* defined (USB) || defined (USB_OTG_FS) */
  518. #ifdef __cplusplus
  519. }
  520. #endif /* __cplusplus */
  521. #endif /* STM32L4xx_LL_USB_H */