stm32f7xx_hal_pcd.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_pcd.h
  4. * @author MCD Application Team
  5. * @brief Header file of PCD HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef __STM32F7xx_HAL_PCD_H
  37. #define __STM32F7xx_HAL_PCD_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f7xx_ll_usb.h"
  43. /** @addtogroup STM32F7xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup PCD
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup PCD_Exported_Types PCD Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief PCD State structure definition
  55. */
  56. typedef enum
  57. {
  58. HAL_PCD_STATE_RESET = 0x00,
  59. HAL_PCD_STATE_READY = 0x01,
  60. HAL_PCD_STATE_ERROR = 0x02,
  61. HAL_PCD_STATE_BUSY = 0x03,
  62. HAL_PCD_STATE_TIMEOUT = 0x04
  63. } PCD_StateTypeDef;
  64. /* Device LPM suspend state */
  65. typedef enum
  66. {
  67. LPM_L0 = 0x00, /* on */
  68. LPM_L1 = 0x01, /* LPM L1 sleep */
  69. LPM_L2 = 0x02, /* suspend */
  70. LPM_L3 = 0x03, /* off */
  71. }PCD_LPM_StateTypeDef;
  72. #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
  73. typedef USB_OTG_GlobalTypeDef PCD_TypeDef;
  74. typedef USB_OTG_CfgTypeDef PCD_InitTypeDef;
  75. typedef USB_OTG_EPTypeDef PCD_EPTypeDef;
  76. #endif /* USB_OTG_FS || USB_OTG_HS */
  77. /**
  78. * @brief PCD Handle Structure definition
  79. */
  80. typedef struct
  81. {
  82. PCD_TypeDef *Instance; /*!< Register base address */
  83. PCD_InitTypeDef Init; /*!< PCD required parameters */
  84. __IO uint8_t USB_Address; /*!< USB Address */
  85. PCD_EPTypeDef IN_ep[16]; /*!< IN endpoint parameters */
  86. PCD_EPTypeDef OUT_ep[16]; /*!< OUT endpoint parameters */
  87. HAL_LockTypeDef Lock; /*!< PCD peripheral status */
  88. __IO PCD_StateTypeDef State; /*!< PCD communication state */
  89. uint32_t Setup[12]; /*!< Setup packet buffer */
  90. PCD_LPM_StateTypeDef LPM_State; /*!< LPM State */
  91. uint32_t BESL;
  92. uint32_t lpm_active; /*!< Enable or disable the Link Power Management .
  93. This parameter can be set to ENABLE or DISABLE */
  94. void *pData; /*!< Pointer to upper stack Handler */
  95. } PCD_HandleTypeDef;
  96. /**
  97. * @}
  98. */
  99. /* Include PCD HAL Extended module */
  100. #include "stm32f7xx_hal_pcd_ex.h"
  101. /* Exported constants --------------------------------------------------------*/
  102. /** @defgroup PCD_Exported_Constants PCD Exported Constants
  103. * @{
  104. */
  105. /** @defgroup PCD_Speed PCD Speed
  106. * @{
  107. */
  108. #if defined (USB_OTG_HS)
  109. #define PCD_SPEED_HIGH 0U
  110. #define PCD_SPEED_HIGH_IN_FULL 1U
  111. #endif
  112. #define PCD_SPEED_FULL 2U
  113. /**
  114. * @}
  115. */
  116. /** @defgroup PCD_PHY_Module PCD PHY Module
  117. * @{
  118. */
  119. #define PCD_PHY_ULPI 1U
  120. #define PCD_PHY_EMBEDDED 2U
  121. #define PCD_PHY_UTMI 3U
  122. /**
  123. * @}
  124. */
  125. /** @defgroup PCD_Turnaround_Timeout Turnaround Timeout Value
  126. * @{
  127. */
  128. #ifndef USBD_HS_TRDT_VALUE
  129. #define USBD_HS_TRDT_VALUE 9U
  130. #endif /* USBD_HS_TRDT_VALUE */
  131. #ifndef USBD_FS_TRDT_VALUE
  132. #define USBD_FS_TRDT_VALUE 5U
  133. #endif /* USBD_HS_TRDT_VALUE */
  134. /**
  135. * @}
  136. */
  137. /**
  138. * @}
  139. */
  140. /* Exported macros -----------------------------------------------------------*/
  141. /** @defgroup PCD_Exported_Macros PCD Exported Macros
  142. * @brief macros to handle interrupts and specific clock configurations
  143. * @{
  144. */
  145. #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
  146. #define __HAL_PCD_ENABLE(__HANDLE__) (void)USB_EnableGlobalInt ((__HANDLE__)->Instance)
  147. #define __HAL_PCD_DISABLE(__HANDLE__) (void)USB_DisableGlobalInt ((__HANDLE__)->Instance)
  148. #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__))
  149. #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->GINTSTS) &= (__INTERRUPT__))
  150. #define __HAL_PCD_IS_INVALID_INTERRUPT(__HANDLE__) (USB_ReadInterrupts((__HANDLE__)->Instance) == 0U)
  151. #define __HAL_PCD_UNGATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) &= \
  152. ~(USB_OTG_PCGCCTL_STOPCLK)
  153. #define __HAL_PCD_GATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) |= USB_OTG_PCGCCTL_STOPCLK
  154. #define __HAL_PCD_IS_PHY_SUSPENDED(__HANDLE__) ((*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE)) & 0x10U)
  155. #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= (USB_OTG_HS_WAKEUP_EXTI_LINE)
  156. #define __HAL_USB_OTG_HS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE)
  157. #define __HAL_USB_OTG_HS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_HS_WAKEUP_EXTI_LINE)
  158. #define __HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = (USB_OTG_HS_WAKEUP_EXTI_LINE)
  159. #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_EDGE() \
  160. do { \
  161. EXTI->FTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE); \
  162. EXTI->RTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE; \
  163. } while(0U)
  164. #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= USB_OTG_FS_WAKEUP_EXTI_LINE
  165. #define __HAL_USB_OTG_FS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE)
  166. #define __HAL_USB_OTG_FS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_FS_WAKEUP_EXTI_LINE)
  167. #define __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = USB_OTG_FS_WAKEUP_EXTI_LINE
  168. #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE() \
  169. do { \
  170. EXTI->FTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE); \
  171. EXTI->RTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE; \
  172. } while(0U)
  173. #endif /* USB_OTG_FS || USB_OTG_HS */
  174. /**
  175. * @}
  176. */
  177. /* Exported functions --------------------------------------------------------*/
  178. /** @addtogroup PCD_Exported_Functions PCD Exported Functions
  179. * @{
  180. */
  181. /* Initialization/de-initialization functions ********************************/
  182. /** @addtogroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
  183. * @{
  184. */
  185. HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd);
  186. HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd);
  187. void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
  188. void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
  189. /**
  190. * @}
  191. */
  192. /* I/O operation functions ***************************************************/
  193. /* Non-Blocking mode: Interrupt */
  194. /** @addtogroup PCD_Exported_Functions_Group2 Input and Output operation functions
  195. * @{
  196. */
  197. HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd);
  198. HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd);
  199. void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
  200. void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
  201. void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
  202. void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
  203. void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
  204. void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
  205. void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
  206. void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
  207. void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
  208. void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
  209. void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
  210. void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
  211. /**
  212. * @}
  213. */
  214. /* Peripheral Control functions **********************************************/
  215. /** @addtogroup PCD_Exported_Functions_Group3 Peripheral Control functions
  216. * @{
  217. */
  218. HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd);
  219. HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd);
  220. HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address);
  221. HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type);
  222. HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
  223. HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
  224. HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
  225. uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
  226. HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
  227. HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
  228. HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
  229. HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
  230. HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
  231. /**
  232. * @}
  233. */
  234. /* Peripheral State functions ************************************************/
  235. /** @addtogroup PCD_Exported_Functions_Group4 Peripheral State functions
  236. * @{
  237. */
  238. PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd);
  239. /**
  240. * @}
  241. */
  242. /**
  243. * @}
  244. */
  245. /* Private constants ---------------------------------------------------------*/
  246. /** @defgroup PCD_Private_Constants PCD Private Constants
  247. * @{
  248. */
  249. /** @defgroup USB_EXTI_Line_Interrupt USB EXTI line interrupt
  250. * @{
  251. */
  252. #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
  253. #define USB_OTG_FS_WAKEUP_EXTI_RISING_EDGE 0x08U
  254. #define USB_OTG_FS_WAKEUP_EXTI_FALLING_EDGE 0x0CU
  255. #define USB_OTG_FS_WAKEUP_EXTI_RISING_FALLING_EDGE 0x10U
  256. #define USB_OTG_HS_WAKEUP_EXTI_RISING_EDGE 0x08U
  257. #define USB_OTG_HS_WAKEUP_EXTI_FALLING_EDGE 0x0CU
  258. #define USB_OTG_HS_WAKEUP_EXTI_RISING_FALLING_EDGE 0x10U
  259. #ifndef LL_EXTI_LINE_18
  260. #define LL_EXTI_LINE_18 0x00040000U
  261. #endif
  262. #ifndef LL_EXTI_LINE_20
  263. #define LL_EXTI_LINE_20 0x00100000U
  264. #endif
  265. #define USB_OTG_FS_WAKEUP_EXTI_LINE LL_EXTI_LINE_18 /*!< External interrupt line 17 Connected to the USB EXTI Line */
  266. #define USB_OTG_HS_WAKEUP_EXTI_LINE LL_EXTI_LINE_20 /*!< External interrupt line 20 Connected to the USB HS EXTI Line */
  267. #endif /* USB_OTG_FS || USB_OTG_HS */
  268. /**
  269. * @}
  270. */
  271. /**
  272. * @}
  273. */
  274. /* Private macros ------------------------------------------------------------*/
  275. /** @defgroup PCD_Private_Macros PCD Private Macros
  276. * @{
  277. */
  278. /**
  279. * @}
  280. */
  281. /**
  282. * @}
  283. */
  284. /**
  285. * @}
  286. */
  287. #ifdef __cplusplus
  288. }
  289. #endif
  290. #endif /* __STM32F7xx_HAL_PCD_H */
  291. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/