]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4/stm32f4xx_ll_usb.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4 / stm32f4xx_ll_usb.h
1 /**
2 ******************************************************************************
3 * @file stm32f4xx_ll_usb.h
4 * @author MCD Application Team
5 * @version V1.1.0
6 * @date 19-June-2014
7 * @brief Header file of USB Core HAL module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2014 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
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_LL_USB_H
40 #define __STM32F4xx_LL_USB_H
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
48
49 /** @addtogroup STM32F4xx_HAL
50 * @{
51 */
52
53 /** @addtogroup USB_Core
54 * @{
55 */
56
57 /* Exported types ------------------------------------------------------------*/
58
59 /**
60 * @brief USB Mode definition
61 */
62 typedef enum
63 {
64 USB_OTG_DEVICE_MODE = 0,
65 USB_OTG_HOST_MODE = 1,
66 USB_OTG_DRD_MODE = 2
67
68 }USB_OTG_ModeTypeDef;
69
70 /**
71 * @brief URB States definition
72 */
73 typedef enum {
74 URB_IDLE = 0,
75 URB_DONE,
76 URB_NOTREADY,
77 URB_NYET,
78 URB_ERROR,
79 URB_STALL
80
81 }USB_OTG_URBStateTypeDef;
82
83 /**
84 * @brief Host channel States definition
85 */
86 typedef enum {
87 HC_IDLE = 0,
88 HC_XFRC,
89 HC_HALTED,
90 HC_NAK,
91 HC_NYET,
92 HC_STALL,
93 HC_XACTERR,
94 HC_BBLERR,
95 HC_DATATGLERR
96
97 }USB_OTG_HCStateTypeDef;
98
99 /**
100 * @brief PCD Initialization Structure definition
101 */
102 typedef struct
103 {
104 uint32_t dev_endpoints; /*!< Device Endpoints number.
105 This parameter depends on the used USB core.
106 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
107
108 uint32_t Host_channels; /*!< Host Channels number.
109 This parameter Depends on the used USB core.
110 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
111
112 uint32_t speed; /*!< USB Core speed.
113 This parameter can be any value of @ref USB_Core_Speed_ */
114
115 uint32_t dma_enable; /*!< Enable or disable of the USB embedded DMA. */
116
117 uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size.
118 This parameter can be any value of @ref USB_EP0_MPS_ */
119
120 uint32_t phy_itface; /*!< Select the used PHY interface.
121 This parameter can be any value of @ref USB_Core_PHY_ */
122
123 uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */
124
125 uint32_t low_power_enable; /*!< Enable or disable the low power mode. */
126
127 uint32_t vbus_sensing_enable; /*!< Enable or disable the VBUS Sensing feature. */
128
129 uint32_t use_dedicated_ep1; /*!< Enable or disable the use of the dedicated EP1 interrupt. */
130
131 uint32_t use_external_vbus; /*!< Enable or disable the use of the external VBUS. */
132
133 }USB_OTG_CfgTypeDef;
134
135 typedef struct
136 {
137 uint8_t num; /*!< Endpoint number
138 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
139
140 uint8_t is_in; /*!< Endpoint direction
141 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
142
143 uint8_t is_stall; /*!< Endpoint stall condition
144 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
145
146 uint8_t type; /*!< Endpoint type
147 This parameter can be any value of @ref USB_EP_Type_ */
148
149 uint8_t data_pid_start; /*!< Initial data PID
150 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
151
152 uint8_t even_odd_frame; /*!< IFrame parity
153 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
154
155 uint16_t tx_fifo_num; /*!< Transmission FIFO number
156 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
157
158 uint32_t maxpacket; /*!< Endpoint Max packet size
159 This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
160
161 uint8_t *xfer_buff; /*!< Pointer to transfer buffer */
162
163 uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address */
164
165 uint32_t xfer_len; /*!< Current transfer length */
166
167 uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */
168
169 }USB_OTG_EPTypeDef;
170
171 typedef struct
172 {
173 uint8_t dev_addr ; /*!< USB device address.
174 This parameter must be a number between Min_Data = 1 and Max_Data = 255 */
175
176 uint8_t ch_num; /*!< Host channel number.
177 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
178
179 uint8_t ep_num; /*!< Endpoint number.
180 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
181
182 uint8_t ep_is_in; /*!< Endpoint direction
183 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
184
185 uint8_t speed; /*!< USB Host speed.
186 This parameter can be any value of @ref USB_Core_Speed_ */
187
188 uint8_t do_ping; /*!< Enable or disable the use of the PING protocol for HS mode. */
189
190 uint8_t process_ping; /*!< Execute the PING protocol for HS mode. */
191
192 uint8_t ep_type; /*!< Endpoint Type.
193 This parameter can be any value of @ref USB_EP_Type_ */
194
195 uint16_t max_packet; /*!< Endpoint Max packet size.
196 This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
197
198 uint8_t data_pid; /*!< Initial data PID.
199 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
200
201 uint8_t *xfer_buff; /*!< Pointer to transfer buffer. */
202
203 uint32_t xfer_len; /*!< Current transfer length. */
204
205 uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer. */
206
207 uint8_t toggle_in; /*!< IN transfer current toggle flag.
208 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
209
210 uint8_t toggle_out; /*!< OUT transfer current toggle flag
211 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
212
213 uint32_t dma_addr; /*!< 32 bits aligned transfer buffer address. */
214
215 uint32_t ErrCnt; /*!< Host channel error count.*/
216
217 USB_OTG_URBStateTypeDef urb_state; /*!< URB state.
218 This parameter can be any value of @ref USB_OTG_URBStateTypeDef */
219
220 USB_OTG_HCStateTypeDef state; /*!< Host Channel state.
221 This parameter can be any value of @ref USB_OTG_HCStateTypeDef */
222
223 }USB_OTG_HCTypeDef;
224
225 /* Exported constants --------------------------------------------------------*/
226
227 /** @defgroup PCD_Exported_Constants
228 * @{
229 */
230
231 /** @defgroup USB_Core_Mode_
232 * @{
233 */
234 #define USB_OTG_MODE_DEVICE 0
235 #define USB_OTG_MODE_HOST 1
236 #define USB_OTG_MODE_DRD 2
237 /**
238 * @}
239 */
240
241 /** @defgroup USB_Core_Speed_
242 * @{
243 */
244 #define USB_OTG_SPEED_HIGH 0
245 #define USB_OTG_SPEED_HIGH_IN_FULL 1
246 #define USB_OTG_SPEED_LOW 2
247 #define USB_OTG_SPEED_FULL 3
248 /**
249 * @}
250 */
251
252 /** @defgroup USB_Core_PHY_
253 * @{
254 */
255 #define USB_OTG_ULPI_PHY 1
256 #define USB_OTG_EMBEDDED_PHY 2
257 /**
258 * @}
259 */
260
261 /** @defgroup USB_Core_MPS_
262 * @{
263 */
264 #define USB_OTG_HS_MAX_PACKET_SIZE 512
265 #define USB_OTG_FS_MAX_PACKET_SIZE 64
266 #define USB_OTG_MAX_EP0_SIZE 64
267 /**
268 * @}
269 */
270
271 /** @defgroup USB_Core_Phy_Frequency_
272 * @{
273 */
274 #define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ (0 << 1)
275 #define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ (1 << 1)
276 #define DSTS_ENUMSPD_LS_PHY_6MHZ (2 << 1)
277 #define DSTS_ENUMSPD_FS_PHY_48MHZ (3 << 1)
278 /**
279 * @}
280 */
281
282 /** @defgroup USB_CORE_Frame_Interval_
283 * @{
284 */
285 #define DCFG_FRAME_INTERVAL_80 0
286 #define DCFG_FRAME_INTERVAL_85 1
287 #define DCFG_FRAME_INTERVAL_90 2
288 #define DCFG_FRAME_INTERVAL_95 3
289 /**
290 * @}
291 */
292
293 /** @defgroup USB_EP0_MPS_
294 * @{
295 */
296 #define DEP0CTL_MPS_64 0
297 #define DEP0CTL_MPS_32 1
298 #define DEP0CTL_MPS_16 2
299 #define DEP0CTL_MPS_8 3
300 /**
301 * @}
302 */
303
304 /** @defgroup USB_EP_Speed_
305 * @{
306 */
307 #define EP_SPEED_LOW 0
308 #define EP_SPEED_FULL 1
309 #define EP_SPEED_HIGH 2
310 /**
311 * @}
312 */
313
314 /** @defgroup USB_EP_Type_
315 * @{
316 */
317 #define EP_TYPE_CTRL 0
318 #define EP_TYPE_ISOC 1
319 #define EP_TYPE_BULK 2
320 #define EP_TYPE_INTR 3
321 #define EP_TYPE_MSK 3
322 /**
323 * @}
324 */
325
326 /** @defgroup USB_STS_Defines_
327 * @{
328 */
329 #define STS_GOUT_NAK 1
330 #define STS_DATA_UPDT 2
331 #define STS_XFER_COMP 3
332 #define STS_SETUP_COMP 4
333 #define STS_SETUP_UPDT 6
334 /**
335 * @}
336 */
337
338 /** @defgroup HCFG_SPEED_Defines_
339 * @{
340 */
341 #define HCFG_30_60_MHZ 0
342 #define HCFG_48_MHZ 1
343 #define HCFG_6_MHZ 2
344 /**
345 * @}
346 */
347
348 /** @defgroup HPRT0_PRTSPD_SPEED_Defines_
349 * @{
350 */
351 #define HPRT0_PRTSPD_HIGH_SPEED 0
352 #define HPRT0_PRTSPD_FULL_SPEED 1
353 #define HPRT0_PRTSPD_LOW_SPEED 2
354 /**
355 * @}
356 */
357
358 #define HCCHAR_CTRL 0
359 #define HCCHAR_ISOC 1
360 #define HCCHAR_BULK 2
361 #define HCCHAR_INTR 3
362
363 #define HC_PID_DATA0 0
364 #define HC_PID_DATA2 1
365 #define HC_PID_DATA1 2
366 #define HC_PID_SETUP 3
367
368 #define GRXSTS_PKTSTS_IN 2
369 #define GRXSTS_PKTSTS_IN_XFER_COMP 3
370 #define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5
371 #define GRXSTS_PKTSTS_CH_HALTED 7
372
373 #define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_PCGCCTL_BASE)
374 #define USBx_HPRT0 *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_HOST_PORT_BASE)
375
376 #define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)((uint32_t )USBx + USB_OTG_DEVICE_BASE))
377 #define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)((uint32_t)USBx + USB_OTG_IN_ENDPOINT_BASE + (i)*USB_OTG_EP_REG_SIZE))
378 #define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)((uint32_t)USBx + USB_OTG_OUT_ENDPOINT_BASE + (i)*USB_OTG_EP_REG_SIZE))
379 #define USBx_DFIFO(i) *(__IO uint32_t *)((uint32_t)USBx + USB_OTG_FIFO_BASE + (i) * USB_OTG_FIFO_SIZE)
380
381 #define USBx_HOST ((USB_OTG_HostTypeDef *)((uint32_t )USBx + USB_OTG_HOST_BASE))
382 #define USBx_HC(i) ((USB_OTG_HostChannelTypeDef *)((uint32_t)USBx + USB_OTG_HOST_CHANNEL_BASE + (i)*USB_OTG_HOST_CHANNEL_SIZE))
383
384 /* Exported macro ------------------------------------------------------------*/
385 #define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK &= ~(__INTERRUPT__))
386 #define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK |= (__INTERRUPT__))
387
388 #define CLEAR_IN_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_INEP(__EPNUM__)->DIEPINT = (__INTERRUPT__))
389 #define CLEAR_OUT_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_OUTEP(__EPNUM__)->DOEPINT = (__INTERRUPT__))
390
391 /* Exported functions --------------------------------------------------------*/
392 HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef Init);
393 HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef Init);
394 HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
395 HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
396 HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx , USB_OTG_ModeTypeDef mode);
397 HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx , uint8_t speed);
398 HAL_StatusTypeDef USB_FlushRxFifo (USB_OTG_GlobalTypeDef *USBx);
399 HAL_StatusTypeDef USB_FlushTxFifo (USB_OTG_GlobalTypeDef *USBx, uint32_t num );
400 HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
401 HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
402 HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
403 HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
404 HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep, uint8_t dma);
405 HAL_StatusTypeDef USB_EP0StartXfer(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep, uint8_t dma);
406 HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len, uint8_t dma);
407 void * USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len);
408 HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep);
409 HAL_StatusTypeDef USB_EPClearStall(USB_OTG_GlobalTypeDef *USBx , USB_OTG_EPTypeDef *ep);
410 HAL_StatusTypeDef USB_SetDevAddress (USB_OTG_GlobalTypeDef *USBx, uint8_t address);
411 HAL_StatusTypeDef USB_DevConnect (USB_OTG_GlobalTypeDef *USBx);
412 HAL_StatusTypeDef USB_DevDisconnect (USB_OTG_GlobalTypeDef *USBx);
413 HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx);
414 HAL_StatusTypeDef USB_ActivateSetup (USB_OTG_GlobalTypeDef *USBx);
415 HAL_StatusTypeDef USB_EP0_OutStart(USB_OTG_GlobalTypeDef *USBx, uint8_t dma, uint8_t *psetup);
416 uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx);
417 uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx);
418 uint32_t USB_ReadInterrupts (USB_OTG_GlobalTypeDef *USBx);
419 uint32_t USB_ReadDevAllOutEpInterrupt (USB_OTG_GlobalTypeDef *USBx);
420 uint32_t USB_ReadDevOutEPInterrupt (USB_OTG_GlobalTypeDef *USBx , uint8_t epnum);
421 uint32_t USB_ReadDevAllInEpInterrupt (USB_OTG_GlobalTypeDef *USBx);
422 uint32_t USB_ReadDevInEPInterrupt (USB_OTG_GlobalTypeDef *USBx , uint8_t epnum);
423 void USB_ClearInterrupts (USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt);
424
425 HAL_StatusTypeDef USB_HostInit (USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
426 HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx , uint8_t freq);
427 HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx);
428 HAL_StatusTypeDef USB_DriveVbus (USB_OTG_GlobalTypeDef *USBx, uint8_t state);
429 uint32_t USB_GetHostSpeed (USB_OTG_GlobalTypeDef *USBx);
430 uint32_t USB_GetCurrentFrame (USB_OTG_GlobalTypeDef *USBx);
431 HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx,
432 uint8_t ch_num,
433 uint8_t epnum,
434 uint8_t dev_address,
435 uint8_t speed,
436 uint8_t ep_type,
437 uint16_t mps);
438 HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDef *hc, uint8_t dma);
439 uint32_t USB_HC_ReadInterrupt (USB_OTG_GlobalTypeDef *USBx);
440 HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx , uint8_t hc_num);
441 HAL_StatusTypeDef USB_DoPing(USB_OTG_GlobalTypeDef *USBx , uint8_t ch_num);
442 HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx);
443
444 /**
445 * @}
446 */
447
448 /**
449 * @}
450 */
451
452 #ifdef __cplusplus
453 }
454 #endif
455
456
457 #endif /* __STM32F4xx_LL_USB_H */
458
459 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Imprint / Impressum