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