You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

313 lines
12 KiB

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