stm32g4xx_ll_usb.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_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) 2019 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 STM32G4xx_LL_USB_H
  20. #define STM32G4xx_LL_USB_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif /* __cplusplus */
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g4xx_hal_def.h"
  26. #if defined (USB)
  27. /** @addtogroup STM32G4xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup USB_LL
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /**
  35. * @brief USB Mode definition
  36. */
  37. typedef enum
  38. {
  39. USB_DEVICE_MODE = 0
  40. } USB_ModeTypeDef;
  41. /**
  42. * @brief USB Instance Initialization Structure definition
  43. */
  44. typedef struct
  45. {
  46. uint8_t dev_endpoints; /*!< Device Endpoints number.
  47. This parameter depends on the used USB core.
  48. This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
  49. uint8_t speed; /*!< USB Core speed.
  50. This parameter can be any value of @ref PCD_Speed/HCD_Speed
  51. (HCD_SPEED_xxx, HCD_SPEED_xxx) */
  52. uint8_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size. */
  53. uint8_t phy_itface; /*!< Select the used PHY interface.
  54. This parameter can be any value of @ref PCD_PHY_Module/HCD_PHY_Module */
  55. uint8_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */
  56. uint8_t low_power_enable; /*!< Enable or disable the low Power Mode. */
  57. uint8_t lpm_enable; /*!< Enable or disable Link Power Management. */
  58. uint8_t battery_charging_enable; /*!< Enable or disable Battery charging. */
  59. } USB_CfgTypeDef;
  60. typedef struct
  61. {
  62. uint8_t num; /*!< Endpoint number
  63. This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
  64. uint8_t is_in; /*!< Endpoint direction
  65. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  66. uint8_t is_stall; /*!< Endpoint stall condition
  67. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  68. uint8_t type; /*!< Endpoint type
  69. This parameter can be any value of @ref USB_LL_EP_Type */
  70. uint8_t data_pid_start; /*!< Initial data PID
  71. This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
  72. uint16_t pmaadress; /*!< PMA Address
  73. This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
  74. uint16_t pmaaddr0; /*!< PMA Address0
  75. This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
  76. uint16_t pmaaddr1; /*!< PMA Address1
  77. This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
  78. uint8_t doublebuffer; /*!< Double buffer enable
  79. This parameter can be 0 or 1 */
  80. uint32_t maxpacket; /*!< Endpoint Max packet size
  81. This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
  82. uint8_t *xfer_buff; /*!< Pointer to transfer buffer */
  83. uint32_t xfer_len; /*!< Current transfer length */
  84. uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */
  85. uint32_t xfer_len_db; /*!< double buffer transfer length used with bulk double buffer in */
  86. uint8_t xfer_fill_db; /*!< double buffer Need to Fill new buffer used with bulk_in */
  87. } USB_EPTypeDef;
  88. /* Exported constants --------------------------------------------------------*/
  89. /** @defgroup PCD_Exported_Constants PCD Exported Constants
  90. * @{
  91. */
  92. /** @defgroup USB_LL_EP0_MPS USB Low Layer EP0 MPS
  93. * @{
  94. */
  95. #define EP_MPS_64 0U
  96. #define EP_MPS_32 1U
  97. #define EP_MPS_16 2U
  98. #define EP_MPS_8 3U
  99. /**
  100. * @}
  101. */
  102. /** @defgroup USB_LL_EP_Type USB Low Layer EP Type
  103. * @{
  104. */
  105. #define EP_TYPE_CTRL 0U
  106. #define EP_TYPE_ISOC 1U
  107. #define EP_TYPE_BULK 2U
  108. #define EP_TYPE_INTR 3U
  109. #define EP_TYPE_MSK 3U
  110. /**
  111. * @}
  112. */
  113. /** @defgroup USB_LL Device Speed
  114. * @{
  115. */
  116. #define USBD_FS_SPEED 2U
  117. /**
  118. * @}
  119. */
  120. #define BTABLE_ADDRESS 0x000U
  121. #define PMA_ACCESS 1U
  122. #ifndef USB_EP_RX_STRX
  123. #define USB_EP_RX_STRX (0x3U << 12)
  124. #endif /* USB_EP_RX_STRX */
  125. #define EP_ADDR_MSK 0x7U
  126. #ifndef USE_USB_DOUBLE_BUFFER
  127. #define USE_USB_DOUBLE_BUFFER 1U
  128. #endif /* USE_USB_DOUBLE_BUFFER */
  129. /**
  130. * @}
  131. */
  132. /* Exported macro ------------------------------------------------------------*/
  133. /**
  134. * @}
  135. */
  136. /* Exported functions --------------------------------------------------------*/
  137. /** @addtogroup USB_LL_Exported_Functions USB Low Layer Exported Functions
  138. * @{
  139. */
  140. HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg);
  141. HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg);
  142. HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx);
  143. HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx);
  144. HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode);
  145. HAL_StatusTypeDef USB_FlushRxFifo(USB_TypeDef const *USBx);
  146. HAL_StatusTypeDef USB_FlushTxFifo(USB_TypeDef const *USBx, uint32_t num);
  147. #if defined (HAL_PCD_MODULE_ENABLED)
  148. HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  149. HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  150. HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  151. HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  152. HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  153. HAL_StatusTypeDef USB_EPStopXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep);
  154. #endif /* defined (HAL_PCD_MODULE_ENABLED) */
  155. HAL_StatusTypeDef USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address);
  156. HAL_StatusTypeDef USB_DevConnect(USB_TypeDef *USBx);
  157. HAL_StatusTypeDef USB_DevDisconnect(USB_TypeDef *USBx);
  158. HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx);
  159. uint32_t USB_ReadInterrupts(USB_TypeDef const *USBx);
  160. HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx);
  161. HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx);
  162. void USB_WritePMA(USB_TypeDef const *USBx, uint8_t *pbUsrBuf,
  163. uint16_t wPMABufAddr, uint16_t wNBytes);
  164. void USB_ReadPMA(USB_TypeDef const *USBx, uint8_t *pbUsrBuf,
  165. uint16_t wPMABufAddr, uint16_t wNBytes);
  166. /**
  167. * @}
  168. */
  169. /**
  170. * @}
  171. */
  172. /**
  173. * @}
  174. */
  175. /**
  176. * @}
  177. */
  178. #endif /* defined (USB) */
  179. #ifdef __cplusplus
  180. }
  181. #endif /* __cplusplus */
  182. #endif /* STM32G4xx_LL_USB_H */