STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
stm32h7xx_ll_usb.c
Go to the documentation of this file.
1/**
2 ******************************************************************************
3 * @file stm32h7xx_ll_usb.c
4 * @author MCD Application Team
5 * @brief USB Low Layer HAL module driver.
6 *
7 * This file provides firmware functions to manage the following
8 * functionalities of the USB Peripheral Controller:
9 * + Initialization/de-initialization functions
10 * + I/O operation functions
11 * + Peripheral Control functions
12 * + Peripheral State functions
13 *
14 ******************************************************************************
15 * @attention
16 *
17 * Copyright (c) 2017 STMicroelectronics.
18 * All rights reserved.
19 *
20 * This software is licensed under terms that can be found in the LICENSE file
21 * in the root directory of this software component.
22 * If no LICENSE file comes with this software, it is provided AS-IS.
23 *
24 ******************************************************************************
25 @verbatim
26 ==============================================================================
27 ##### How to use this driver #####
28 ==============================================================================
29 [..]
30 (#) Fill parameters of Init structure in USB_CfgTypeDef structure.
31
32 (#) Call USB_CoreInit() API to initialize the USB Core peripheral.
33
34 (#) The upper HAL HCD/PCD driver will call the right routines for its internal processes.
35
36 @endverbatim
37
38 ******************************************************************************
39 */
40
41/* Includes ------------------------------------------------------------------*/
42#include "stm32h7xx_hal.h"
43
44/** @addtogroup STM32H7xx_LL_USB_DRIVER
45 * @{
46 */
47
48#if defined (HAL_PCD_MODULE_ENABLED) || defined (HAL_HCD_MODULE_ENABLED)
49#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
50/* Private typedef -----------------------------------------------------------*/
51/* Private define ------------------------------------------------------------*/
52/* Private macro -------------------------------------------------------------*/
53/* Private variables ---------------------------------------------------------*/
54/* Private function prototypes -----------------------------------------------*/
55/* Private functions ---------------------------------------------------------*/
56#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
57static HAL_StatusTypeDef USB_CoreReset(USB_OTG_GlobalTypeDef *USBx);
58
59/* Exported functions --------------------------------------------------------*/
60/** @defgroup USB_LL_Exported_Functions USB Low Layer Exported Functions
61 * @{
62 */
63
64/** @defgroup USB_LL_Exported_Functions_Group1 Initialization/de-initialization functions
65 * @brief Initialization and Configuration functions
66 *
67@verbatim
68 ===============================================================================
69 ##### Initialization/de-initialization functions #####
70 ===============================================================================
71
72@endverbatim
73 * @{
74 */
75
76/**
77 * @brief Initializes the USB Core
78 * @param USBx USB Instance
79 * @param cfg pointer to a USB_OTG_CfgTypeDef structure that contains
80 * the configuration information for the specified USBx peripheral.
81 * @retval HAL status
82 */
83HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
84{
86 if (cfg.phy_itface == USB_OTG_ULPI_PHY)
87 {
88 USBx->GCCFG &= ~(USB_OTG_GCCFG_PWRDWN);
89
90 /* Init The ULPI Interface */
92
93 /* Select vbus source */
95 if (cfg.use_external_vbus == 1U)
96 {
98 }
99
100 /* Reset after a PHY select */
101 ret = USB_CoreReset(USBx);
102 }
103 else /* FS interface (embedded Phy) */
104 {
105 /* Select FS Embedded PHY */
107
108 /* Reset after a PHY select */
109 ret = USB_CoreReset(USBx);
110
111 if (cfg.battery_charging_enable == 0U)
112 {
113 /* Activate the USB Transceiver */
115 }
116 else
117 {
118 /* Deactivate the USB Transceiver */
119 USBx->GCCFG &= ~(USB_OTG_GCCFG_PWRDWN);
120 }
121 }
122
123 if (cfg.dma_enable == 1U)
124 {
125 /* make sure to reserve 18 fifo Locations for DMA buffers */
126 USBx->GDFIFOCFG &= ~(0xFFFFUL << 16);
127 USBx->GDFIFOCFG |= 0x3EEUL << 16;
128
130 USBx->GAHBCFG |= USB_OTG_GAHBCFG_HBSTLEN_INCR4;
132 }
133
134 return ret;
135}
136
137
138/**
139 * @brief Set the USB turnaround time
140 * @param USBx USB Instance
141 * @param hclk: AHB clock frequency
142 * @retval USB turnaround time In PHY Clocks number
143 */
144HAL_StatusTypeDef USB_SetTurnaroundTime(USB_OTG_GlobalTypeDef *USBx,
145 uint32_t hclk, uint8_t speed)
146{
147 uint32_t UsbTrd;
148
149 /* The USBTRD is configured according to the tables below, depending on AHB frequency
150 used by application. In the low AHB frequency range it is used to stretch enough the USB response
151 time to IN tokens, the USB turnaround time, so to compensate for the longer AHB read access
152 latency to the Data FIFO */
153 if (speed == USBD_FS_SPEED)
154 {
155 if ((hclk >= 14200000U) && (hclk < 15000000U))
156 {
157 /* hclk Clock Range between 14.2-15 MHz */
158 UsbTrd = 0xFU;
159 }
160 else if ((hclk >= 15000000U) && (hclk < 16000000U))
161 {
162 /* hclk Clock Range between 15-16 MHz */
163 UsbTrd = 0xEU;
164 }
165 else if ((hclk >= 16000000U) && (hclk < 17200000U))
166 {
167 /* hclk Clock Range between 16-17.2 MHz */
168 UsbTrd = 0xDU;
169 }
170 else if ((hclk >= 17200000U) && (hclk < 18500000U))
171 {
172 /* hclk Clock Range between 17.2-18.5 MHz */
173 UsbTrd = 0xCU;
174 }
175 else if ((hclk >= 18500000U) && (hclk < 20000000U))
176 {
177 /* hclk Clock Range between 18.5-20 MHz */
178 UsbTrd = 0xBU;
179 }
180 else if ((hclk >= 20000000U) && (hclk < 21800000U))
181 {
182 /* hclk Clock Range between 20-21.8 MHz */
183 UsbTrd = 0xAU;
184 }
185 else if ((hclk >= 21800000U) && (hclk < 24000000U))
186 {
187 /* hclk Clock Range between 21.8-24 MHz */
188 UsbTrd = 0x9U;
189 }
190 else if ((hclk >= 24000000U) && (hclk < 27700000U))
191 {
192 /* hclk Clock Range between 24-27.7 MHz */
193 UsbTrd = 0x8U;
194 }
195 else if ((hclk >= 27700000U) && (hclk < 32000000U))
196 {
197 /* hclk Clock Range between 27.7-32 MHz */
198 UsbTrd = 0x7U;
199 }
200 else /* if(hclk >= 32000000) */
201 {
202 /* hclk Clock Range between 32-200 MHz */
203 UsbTrd = 0x6U;
204 }
205 }
206 else if (speed == USBD_HS_SPEED)
207 {
208 UsbTrd = USBD_HS_TRDT_VALUE;
209 }
210 else
211 {
212 UsbTrd = USBD_DEFAULT_TRDT_VALUE;
213 }
214
216 USBx->GUSBCFG |= (uint32_t)((UsbTrd << 10) & USB_OTG_GUSBCFG_TRDT);
217
218 return HAL_OK;
219}
220
221/**
222 * @brief USB_EnableGlobalInt
223 * Enables the controller's Global Int in the AHB Config reg
224 * @param USBx Selected device
225 * @retval HAL status
226 */
227HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx)
228{
230 return HAL_OK;
231}
232
233/**
234 * @brief USB_DisableGlobalInt
235 * Disable the controller's Global Int in the AHB Config reg
236 * @param USBx Selected device
237 * @retval HAL status
238 */
239HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx)
240{
242 return HAL_OK;
243}
244
245/**
246 * @brief USB_SetCurrentMode Set functional mode
247 * @param USBx Selected device
248 * @param mode current core mode
249 * This parameter can be one of these values:
250 * @arg USB_DEVICE_MODE Peripheral mode
251 * @arg USB_HOST_MODE Host mode
252 * @retval HAL status
253 */
254HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_OTG_ModeTypeDef mode)
255{
256 uint32_t ms = 0U;
257
259
260 if (mode == USB_HOST_MODE)
261 {
263
264 do
265 {
266 HAL_Delay(10U);
267 ms += 10U;
268 } while ((USB_GetMode(USBx) != (uint32_t)USB_HOST_MODE) && (ms < HAL_USB_CURRENT_MODE_MAX_DELAY_MS));
269 }
270 else if (mode == USB_DEVICE_MODE)
271 {
273
274 do
275 {
276 HAL_Delay(10U);
277 ms += 10U;
278 } while ((USB_GetMode(USBx) != (uint32_t)USB_DEVICE_MODE) && (ms < HAL_USB_CURRENT_MODE_MAX_DELAY_MS));
279 }
280 else
281 {
282 return HAL_ERROR;
283 }
284
285 if (ms == HAL_USB_CURRENT_MODE_MAX_DELAY_MS)
286 {
287 return HAL_ERROR;
288 }
289
290 return HAL_OK;
291}
292
293/**
294 * @brief USB_DevInit Initializes the USB_OTG controller registers
295 * for device mode
296 * @param USBx Selected device
297 * @param cfg pointer to a USB_OTG_CfgTypeDef structure that contains
298 * the configuration information for the specified USBx peripheral.
299 * @retval HAL status
300 */
301HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
302{
304 uint32_t USBx_BASE = (uint32_t)USBx;
305 uint32_t i;
306
307 for (i = 0U; i < 15U; i++)
308 {
309 USBx->DIEPTXF[i] = 0U;
310 }
311
312 /* VBUS Sensing setup */
313 if (cfg.vbus_sensing_enable == 0U)
314 {
315 USBx_DEVICE->DCTL |= USB_OTG_DCTL_SDIS;
316
317 /* Deactivate VBUS Sensing B */
319
320 /* B-peripheral session valid override enable */
323 }
324 else
325 {
326 /* Enable HW VBUS sensing */
327 USBx->GCCFG |= USB_OTG_GCCFG_VBDEN;
328 }
329
330 /* Restart the Phy Clock */
331 USBx_PCGCCTL = 0U;
332
333 if (cfg.phy_itface == USB_OTG_ULPI_PHY)
334 {
335 if (cfg.speed == USBD_HS_SPEED)
336 {
337 /* Set Core speed to High speed mode */
338 (void)USB_SetDevSpeed(USBx, USB_OTG_SPEED_HIGH);
339 }
340 else
341 {
342 /* Set Core speed to Full speed mode */
343 (void)USB_SetDevSpeed(USBx, USB_OTG_SPEED_HIGH_IN_FULL);
344 }
345 }
346 else
347 {
348 /* Set Core speed to Full speed mode */
349 (void)USB_SetDevSpeed(USBx, USB_OTG_SPEED_FULL);
350 }
351
352 /* Flush the FIFOs */
353 if (USB_FlushTxFifo(USBx, 0x10U) != HAL_OK) /* all Tx FIFOs */
354 {
355 ret = HAL_ERROR;
356 }
357
358 if (USB_FlushRxFifo(USBx) != HAL_OK)
359 {
360 ret = HAL_ERROR;
361 }
362
363 /* Clear all pending Device Interrupts */
364 USBx_DEVICE->DIEPMSK = 0U;
365 USBx_DEVICE->DOEPMSK = 0U;
366 USBx_DEVICE->DAINTMSK = 0U;
367
368 for (i = 0U; i < cfg.dev_endpoints; i++)
369 {
370 if ((USBx_INEP(i)->DIEPCTL & USB_OTG_DIEPCTL_EPENA) == USB_OTG_DIEPCTL_EPENA)
371 {
372 if (i == 0U)
373 {
374 USBx_INEP(i)->DIEPCTL = USB_OTG_DIEPCTL_SNAK;
375 }
376 else
377 {
378 USBx_INEP(i)->DIEPCTL = USB_OTG_DIEPCTL_EPDIS | USB_OTG_DIEPCTL_SNAK;
379 }
380 }
381 else
382 {
383 USBx_INEP(i)->DIEPCTL = 0U;
384 }
385
386 USBx_INEP(i)->DIEPTSIZ = 0U;
387 USBx_INEP(i)->DIEPINT = 0xFB7FU;
388 }
389
390 for (i = 0U; i < cfg.dev_endpoints; i++)
391 {
392 if ((USBx_OUTEP(i)->DOEPCTL & USB_OTG_DOEPCTL_EPENA) == USB_OTG_DOEPCTL_EPENA)
393 {
394 if (i == 0U)
395 {
396 USBx_OUTEP(i)->DOEPCTL = USB_OTG_DOEPCTL_SNAK;
397 }
398 else
399 {
400 USBx_OUTEP(i)->DOEPCTL = USB_OTG_DOEPCTL_EPDIS | USB_OTG_DOEPCTL_SNAK;
401 }
402 }
403 else
404 {
405 USBx_OUTEP(i)->DOEPCTL = 0U;
406 }
407
408 USBx_OUTEP(i)->DOEPTSIZ = 0U;
409 USBx_OUTEP(i)->DOEPINT = 0xFB7FU;
410 }
411
412 USBx_DEVICE->DIEPMSK &= ~(USB_OTG_DIEPMSK_TXFURM);
413
414 /* Disable all interrupts. */
415 USBx->GINTMSK = 0U;
416
417 /* Clear any pending interrupts */
418 USBx->GINTSTS = 0xBFFFFFFFU;
419
420 /* Enable the common interrupts */
421 if (cfg.dma_enable == 0U)
422 {
424 }
425
426 /* Enable interrupts matching to the Device mode ONLY */
431
432 if (cfg.Sof_enable != 0U)
433 {
435 }
436
437 if (cfg.vbus_sensing_enable == 1U)
438 {
440 }
441
442 return ret;
443}
444
445/**
446 * @brief USB_FlushTxFifo Flush a Tx FIFO
447 * @param USBx Selected device
448 * @param num FIFO number
449 * This parameter can be a value from 1 to 15
450 15 means Flush all Tx FIFOs
451 * @retval HAL status
452 */
453HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num)
454{
455 __IO uint32_t count = 0U;
456
457 /* Wait for AHB master IDLE state. */
458 do
459 {
460 count++;
461
462 if (count > HAL_USB_TIMEOUT)
463 {
464 return HAL_TIMEOUT;
465 }
466 } while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_AHBIDL) == 0U);
467
468 /* Flush TX Fifo */
469 count = 0U;
470 USBx->GRSTCTL = (USB_OTG_GRSTCTL_TXFFLSH | (num << 6));
471
472 do
473 {
474 count++;
475
476 if (count > HAL_USB_TIMEOUT)
477 {
478 return HAL_TIMEOUT;
479 }
481
482 return HAL_OK;
483}
484
485/**
486 * @brief USB_FlushRxFifo Flush Rx FIFO
487 * @param USBx Selected device
488 * @retval HAL status
489 */
490HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
491{
492 __IO uint32_t count = 0U;
493
494 /* Wait for AHB master IDLE state. */
495 do
496 {
497 count++;
498
499 if (count > HAL_USB_TIMEOUT)
500 {
501 return HAL_TIMEOUT;
502 }
503 } while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_AHBIDL) == 0U);
504
505 /* Flush RX Fifo */
506 count = 0U;
508
509 do
510 {
511 count++;
512
513 if (count > HAL_USB_TIMEOUT)
514 {
515 return HAL_TIMEOUT;
516 }
518
519 return HAL_OK;
520}
521
522/**
523 * @brief USB_SetDevSpeed Initializes the DevSpd field of DCFG register
524 * depending the PHY type and the enumeration speed of the device.
525 * @param USBx Selected device
526 * @param speed device speed
527 * This parameter can be one of these values:
528 * @arg USB_OTG_SPEED_HIGH: High speed mode
529 * @arg USB_OTG_SPEED_HIGH_IN_FULL: High speed core in Full Speed mode
530 * @arg USB_OTG_SPEED_FULL: Full speed mode
531 * @retval Hal status
532 */
533HAL_StatusTypeDef USB_SetDevSpeed(const USB_OTG_GlobalTypeDef *USBx, uint8_t speed)
534{
535 uint32_t USBx_BASE = (uint32_t)USBx;
536
537 USBx_DEVICE->DCFG |= speed;
538 return HAL_OK;
539}
540
541/**
542 * @brief USB_GetDevSpeed Return the Dev Speed
543 * @param USBx Selected device
544 * @retval speed device speed
545 * This parameter can be one of these values:
546 * @arg USBD_HS_SPEED: High speed mode
547 * @arg USBD_FS_SPEED: Full speed mode
548 */
549uint8_t USB_GetDevSpeed(const USB_OTG_GlobalTypeDef *USBx)
550{
551 uint32_t USBx_BASE = (uint32_t)USBx;
552 uint8_t speed;
553 uint32_t DevEnumSpeed = USBx_DEVICE->DSTS & USB_OTG_DSTS_ENUMSPD;
554
555 if (DevEnumSpeed == DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ)
556 {
557 speed = USBD_HS_SPEED;
558 }
559 else if ((DevEnumSpeed == DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ) ||
560 (DevEnumSpeed == DSTS_ENUMSPD_FS_PHY_48MHZ))
561 {
562 speed = USBD_FS_SPEED;
563 }
564 else
565 {
566 speed = 0xFU;
567 }
568
569 return speed;
570}
571
572#if defined (HAL_PCD_MODULE_ENABLED)
573/**
574 * @brief Activate and configure an endpoint
575 * @param USBx Selected device
576 * @param ep pointer to endpoint structure
577 * @retval HAL status
578 */
579HAL_StatusTypeDef USB_ActivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
580{
581 uint32_t USBx_BASE = (uint32_t)USBx;
582 uint32_t epnum = (uint32_t)ep->num;
583
584 if (ep->is_in == 1U)
585 {
586 USBx_DEVICE->DAINTMSK |= USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << (ep->num & EP_ADDR_MSK));
587
588 if ((USBx_INEP(epnum)->DIEPCTL & USB_OTG_DIEPCTL_USBAEP) == 0U)
589 {
590 USBx_INEP(epnum)->DIEPCTL |= (ep->maxpacket & USB_OTG_DIEPCTL_MPSIZ) |
591 ((uint32_t)ep->type << 18) | (epnum << 22) |
594 }
595 }
596 else
597 {
598 USBx_DEVICE->DAINTMSK |= USB_OTG_DAINTMSK_OEPM & ((uint32_t)(1UL << (ep->num & EP_ADDR_MSK)) << 16);
599
600 if (((USBx_OUTEP(epnum)->DOEPCTL) & USB_OTG_DOEPCTL_USBAEP) == 0U)
601 {
602 USBx_OUTEP(epnum)->DOEPCTL |= (ep->maxpacket & USB_OTG_DOEPCTL_MPSIZ) |
603 ((uint32_t)ep->type << 18) |
606 }
607 }
608 return HAL_OK;
609}
610
611/**
612 * @brief Activate and configure a dedicated endpoint
613 * @param USBx Selected device
614 * @param ep pointer to endpoint structure
615 * @retval HAL status
616 */
617HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
618{
619 uint32_t USBx_BASE = (uint32_t)USBx;
620 uint32_t epnum = (uint32_t)ep->num;
621
622 /* Read DEPCTLn register */
623 if (ep->is_in == 1U)
624 {
625 if (((USBx_INEP(epnum)->DIEPCTL) & USB_OTG_DIEPCTL_USBAEP) == 0U)
626 {
627 USBx_INEP(epnum)->DIEPCTL |= (ep->maxpacket & USB_OTG_DIEPCTL_MPSIZ) |
628 ((uint32_t)ep->type << 18) | (epnum << 22) |
631 }
632
633 USBx_DEVICE->DEACHMSK |= USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << (ep->num & EP_ADDR_MSK));
634 }
635 else
636 {
637 if (((USBx_OUTEP(epnum)->DOEPCTL) & USB_OTG_DOEPCTL_USBAEP) == 0U)
638 {
639 USBx_OUTEP(epnum)->DOEPCTL |= (ep->maxpacket & USB_OTG_DOEPCTL_MPSIZ) |
640 ((uint32_t)ep->type << 18) | (epnum << 22) |
642 }
643
644 USBx_DEVICE->DEACHMSK |= USB_OTG_DAINTMSK_OEPM & ((uint32_t)(1UL << (ep->num & EP_ADDR_MSK)) << 16);
645 }
646
647 return HAL_OK;
648}
649
650/**
651 * @brief De-activate and de-initialize an endpoint
652 * @param USBx Selected device
653 * @param ep pointer to endpoint structure
654 * @retval HAL status
655 */
656HAL_StatusTypeDef USB_DeactivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
657{
658 uint32_t USBx_BASE = (uint32_t)USBx;
659 uint32_t epnum = (uint32_t)ep->num;
660
661 /* Read DEPCTLn register */
662 if (ep->is_in == 1U)
663 {
664 if ((USBx_INEP(epnum)->DIEPCTL & USB_OTG_DIEPCTL_EPENA) == USB_OTG_DIEPCTL_EPENA)
665 {
666 USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_SNAK;
667 USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_EPDIS;
668 }
669
670 USBx_DEVICE->DEACHMSK &= ~(USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << (ep->num & EP_ADDR_MSK)));
671 USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << (ep->num & EP_ADDR_MSK)));
672 USBx_INEP(epnum)->DIEPCTL &= ~(USB_OTG_DIEPCTL_USBAEP |
677 }
678 else
679 {
680 if ((USBx_OUTEP(epnum)->DOEPCTL & USB_OTG_DOEPCTL_EPENA) == USB_OTG_DOEPCTL_EPENA)
681 {
682 USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_SNAK;
683 USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_EPDIS;
684 }
685
686 USBx_DEVICE->DEACHMSK &= ~(USB_OTG_DAINTMSK_OEPM & ((uint32_t)(1UL << (ep->num & EP_ADDR_MSK)) << 16));
687 USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_OEPM & ((uint32_t)(1UL << (ep->num & EP_ADDR_MSK)) << 16));
688 USBx_OUTEP(epnum)->DOEPCTL &= ~(USB_OTG_DOEPCTL_USBAEP |
692 }
693
694 return HAL_OK;
695}
696
697/**
698 * @brief De-activate and de-initialize a dedicated endpoint
699 * @param USBx Selected device
700 * @param ep pointer to endpoint structure
701 * @retval HAL status
702 */
703HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
704{
705 uint32_t USBx_BASE = (uint32_t)USBx;
706 uint32_t epnum = (uint32_t)ep->num;
707
708 /* Read DEPCTLn register */
709 if (ep->is_in == 1U)
710 {
711 if ((USBx_INEP(epnum)->DIEPCTL & USB_OTG_DIEPCTL_EPENA) == USB_OTG_DIEPCTL_EPENA)
712 {
713 USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_SNAK;
714 USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_EPDIS;
715 }
716
717 USBx_INEP(epnum)->DIEPCTL &= ~ USB_OTG_DIEPCTL_USBAEP;
718 USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << (ep->num & EP_ADDR_MSK)));
719 }
720 else
721 {
722 if ((USBx_OUTEP(epnum)->DOEPCTL & USB_OTG_DOEPCTL_EPENA) == USB_OTG_DOEPCTL_EPENA)
723 {
724 USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_SNAK;
725 USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_EPDIS;
726 }
727
728 USBx_OUTEP(epnum)->DOEPCTL &= ~USB_OTG_DOEPCTL_USBAEP;
729 USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_OEPM & ((uint32_t)(1UL << (ep->num & EP_ADDR_MSK)) << 16));
730 }
731
732 return HAL_OK;
733}
734
735/**
736 * @brief USB_EPStartXfer : setup and starts a transfer over an EP
737 * @param USBx Selected device
738 * @param ep pointer to endpoint structure
739 * @param dma USB dma enabled or disabled
740 * This parameter can be one of these values:
741 * 0 : DMA feature not used
742 * 1 : DMA feature used
743 * @retval HAL status
744 */
745HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep, uint8_t dma)
746{
747 uint32_t USBx_BASE = (uint32_t)USBx;
748 uint32_t epnum = (uint32_t)ep->num;
749 uint16_t pktcnt;
750
751 /* IN endpoint */
752 if (ep->is_in == 1U)
753 {
754 /* Zero Length Packet? */
755 if (ep->xfer_len == 0U)
756 {
757 USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_PKTCNT);
758 USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (1UL << 19));
759 USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_XFRSIZ);
760 }
761 else
762 {
763 /* Program the transfer size and packet count
764 * as follows: xfersize = N * maxpacket +
765 * short_packet pktcnt = N + (short_packet
766 * exist ? 1 : 0)
767 */
768 USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_XFRSIZ);
769 USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_PKTCNT);
770
771 if (epnum == 0U)
772 {
773 if (ep->xfer_len > ep->maxpacket)
774 {
775 ep->xfer_len = ep->maxpacket;
776 }
777
778 USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (1UL << 19));
779 }
780 else
781 {
782 pktcnt = (uint16_t)((ep->xfer_len + ep->maxpacket - 1U) / ep->maxpacket);
783 USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & ((uint32_t)pktcnt << 19));
784
785 if (ep->type == EP_TYPE_ISOC)
786 {
787 USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_MULCNT);
788 USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_MULCNT & ((uint32_t)pktcnt << 29));
789 }
790 }
791
792 USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_XFRSIZ & ep->xfer_len);
793 }
794
795 if (dma == 1U)
796 {
797 if ((uint32_t)ep->dma_addr != 0U)
798 {
799 USBx_INEP(epnum)->DIEPDMA = (uint32_t)(ep->dma_addr);
800 }
801
802 if (ep->type == EP_TYPE_ISOC)
803 {
804 if ((USBx_DEVICE->DSTS & (1UL << 8)) == 0U)
805 {
806 USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_SODDFRM;
807 }
808 else
809 {
810 USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
811 }
812 }
813
814 /* EP enable, IN data in FIFO */
815 USBx_INEP(epnum)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
816 }
817 else
818 {
819 /* EP enable, IN data in FIFO */
820 USBx_INEP(epnum)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
821
822 if (ep->type != EP_TYPE_ISOC)
823 {
824 /* Enable the Tx FIFO Empty Interrupt for this EP */
825 if (ep->xfer_len > 0U)
826 {
827 USBx_DEVICE->DIEPEMPMSK |= 1UL << (ep->num & EP_ADDR_MSK);
828 }
829 }
830 else
831 {
832 if ((USBx_DEVICE->DSTS & (1UL << 8)) == 0U)
833 {
834 USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_SODDFRM;
835 }
836 else
837 {
838 USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
839 }
840
841 (void)USB_WritePacket(USBx, ep->xfer_buff, ep->num, (uint16_t)ep->xfer_len, dma);
842 }
843 }
844 }
845 else /* OUT endpoint */
846 {
847 /* Program the transfer size and packet count as follows:
848 * pktcnt = N
849 * xfersize = N * maxpacket
850 */
851 USBx_OUTEP(epnum)->DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_XFRSIZ);
852 USBx_OUTEP(epnum)->DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_PKTCNT);
853
854 if (epnum == 0U)
855 {
856 if (ep->xfer_len > 0U)
857 {
858 ep->xfer_len = ep->maxpacket;
859 }
860
861 /* Store transfer size, for EP0 this is equal to endpoint max packet size */
862 ep->xfer_size = ep->maxpacket;
863
864 USBx_OUTEP(epnum)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_XFRSIZ & ep->xfer_size);
865 USBx_OUTEP(epnum)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1UL << 19));
866 }
867 else
868 {
869 if (ep->xfer_len == 0U)
870 {
871 USBx_OUTEP(epnum)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_XFRSIZ & ep->maxpacket);
872 USBx_OUTEP(epnum)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1UL << 19));
873 }
874 else
875 {
876 pktcnt = (uint16_t)((ep->xfer_len + ep->maxpacket - 1U) / ep->maxpacket);
877 ep->xfer_size = ep->maxpacket * pktcnt;
878
879 USBx_OUTEP(epnum)->DOEPTSIZ |= USB_OTG_DOEPTSIZ_PKTCNT & ((uint32_t)pktcnt << 19);
880 USBx_OUTEP(epnum)->DOEPTSIZ |= USB_OTG_DOEPTSIZ_XFRSIZ & ep->xfer_size;
881 }
882 }
883
884 if (dma == 1U)
885 {
886 if ((uint32_t)ep->xfer_buff != 0U)
887 {
888 USBx_OUTEP(epnum)->DOEPDMA = (uint32_t)(ep->xfer_buff);
889 }
890 }
891
892 if (ep->type == EP_TYPE_ISOC)
893 {
894 if ((USBx_DEVICE->DSTS & (1UL << 8)) == 0U)
895 {
896 USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_SODDFRM;
897 }
898 else
899 {
900 USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_SD0PID_SEVNFRM;
901 }
902 }
903 /* EP enable */
904 USBx_OUTEP(epnum)->DOEPCTL |= (USB_OTG_DOEPCTL_CNAK | USB_OTG_DOEPCTL_EPENA);
905 }
906
907 return HAL_OK;
908}
909
910
911/**
912 * @brief USB_EPStoptXfer Stop transfer on an EP
913 * @param USBx usb device instance
914 * @param ep pointer to endpoint structure
915 * @retval HAL status
916 */
917HAL_StatusTypeDef USB_EPStopXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
918{
919 __IO uint32_t count = 0U;
920 __IO uint32_t RegVal;
922 uint32_t USBx_BASE = (uint32_t)USBx;
923 uint32_t dma_enable = (USBx->GAHBCFG & USB_OTG_GAHBCFG_DMAEN) >> 0x5U;
924
925 /* IN endpoint */
926 if (ep->is_in == 1U)
927 {
928 /* EP enable, IN data in FIFO */
929 if (((USBx_INEP(ep->num)->DIEPCTL) & USB_OTG_DIEPCTL_EPENA) == USB_OTG_DIEPCTL_EPENA)
930 {
931 USBx_INEP(ep->num)->DIEPCTL |= (USB_OTG_DIEPCTL_SNAK);
932 USBx_INEP(ep->num)->DIEPCTL |= (USB_OTG_DIEPCTL_EPDIS);
933
934 do
935 {
936 count++;
937
938 if (count > 0xF0000U)
939 {
940 ret = HAL_ERROR;
941 break;
942 }
943 } while (((USBx_INEP(ep->num)->DIEPCTL) & USB_OTG_DIEPCTL_EPENA) == USB_OTG_DIEPCTL_EPENA);
944 }
945 }
946 else /* OUT endpoint */
947 {
949
950 if ((USBx->GINTSTS & USB_OTG_GINTSTS_BOUTNAKEFF) == 0U)
951 {
952 USBx_DEVICE->DCTL |= USB_OTG_DCTL_SGONAK;
953 }
954
955 if (dma_enable == 0U)
956 {
957 do
958 {
959 count++;
960
961 if (count > 0xF0000U)
962 {
963 ret = HAL_ERROR;
964 break;
965 }
967
968 /* POP the RX status register to generate the NAK Effective interrupt */
969 RegVal = USBx->GRXSTSP;
970 UNUSED(RegVal);
971 }
972
973 /* Wait for Global NAK effective to be set */
974 count = 0U;
975
976 do
977 {
978 count++;
979
980 if (count > 0xF0000U)
981 {
982 ret = HAL_ERROR;
983 break;
984 }
985 } while (((USBx->GINTSTS & USB_OTG_GINTSTS_BOUTNAKEFF)
987
988 USBx_OUTEP(ep->num)->DOEPCTL |= (USB_OTG_DOEPCTL_SNAK);
989 USBx_OUTEP(ep->num)->DOEPCTL |= (USB_OTG_DOEPCTL_EPDIS);
990
991 /* Wait for EP disable to take effect */
992 count = 0U;
993
994 do
995 {
996 count++;
997
998 if (count > 0xF0000U)
999 {
1000 ret = HAL_ERROR;
1001 break;
1002 }
1003 } while (((USBx_OUTEP(ep->num)->DOEPINT & USB_OTG_DOEPINT_EPDISD)
1005
1006 /* Clear OUT EP disable interrupt */
1007 USBx_OUTEP(ep->num)->DOEPINT |= USB_OTG_DOEPINT_EPDISD;
1008
1009 /* Clear Global OUT NAK */
1010 USBx_DEVICE->DCTL |= USB_OTG_DCTL_CGONAK;
1011 }
1012
1013 return ret;
1014}
1015
1016/**
1017 * @brief USB_EPSetStall : set a stall condition over an EP
1018 * @param USBx Selected device
1019 * @param ep pointer to endpoint structure
1020 * @retval HAL status
1021 */
1022HAL_StatusTypeDef USB_EPSetStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
1023{
1024 uint32_t USBx_BASE = (uint32_t)USBx;
1025 uint32_t epnum = (uint32_t)ep->num;
1026
1027 if (ep->is_in == 1U)
1028 {
1029 if (((USBx_INEP(epnum)->DIEPCTL & USB_OTG_DIEPCTL_EPENA) == 0U) && (epnum != 0U))
1030 {
1031 USBx_INEP(epnum)->DIEPCTL &= ~(USB_OTG_DIEPCTL_EPDIS);
1032 }
1033 USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_STALL;
1034 }
1035 else
1036 {
1037 if (((USBx_OUTEP(epnum)->DOEPCTL & USB_OTG_DOEPCTL_EPENA) == 0U) && (epnum != 0U))
1038 {
1039 USBx_OUTEP(epnum)->DOEPCTL &= ~(USB_OTG_DOEPCTL_EPDIS);
1040 }
1041 USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_STALL;
1042 }
1043
1044 return HAL_OK;
1045}
1046
1047/**
1048 * @brief USB_EPClearStall : Clear a stall condition over an EP
1049 * @param USBx Selected device
1050 * @param ep pointer to endpoint structure
1051 * @retval HAL status
1052 */
1053HAL_StatusTypeDef USB_EPClearStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
1054{
1055 uint32_t USBx_BASE = (uint32_t)USBx;
1056 uint32_t epnum = (uint32_t)ep->num;
1057
1058 if (ep->is_in == 1U)
1059 {
1060 USBx_INEP(epnum)->DIEPCTL &= ~USB_OTG_DIEPCTL_STALL;
1061 if ((ep->type == EP_TYPE_INTR) || (ep->type == EP_TYPE_BULK))
1062 {
1063 USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM; /* DATA0 */
1064 }
1065 }
1066 else
1067 {
1068 USBx_OUTEP(epnum)->DOEPCTL &= ~USB_OTG_DOEPCTL_STALL;
1069 if ((ep->type == EP_TYPE_INTR) || (ep->type == EP_TYPE_BULK))
1070 {
1071 USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_SD0PID_SEVNFRM; /* DATA0 */
1072 }
1073 }
1074 return HAL_OK;
1075}
1076#endif /* defined (HAL_PCD_MODULE_ENABLED) */
1077
1078/**
1079 * @brief USB_WritePacket : Writes a packet into the Tx FIFO associated
1080 * with the EP/channel
1081 * @param USBx Selected device
1082 * @param src pointer to source buffer
1083 * @param ch_ep_num endpoint or host channel number
1084 * @param len Number of bytes to write
1085 * @param dma USB dma enabled or disabled
1086 * This parameter can be one of these values:
1087 * 0 : DMA feature not used
1088 * 1 : DMA feature used
1089 * @retval HAL status
1090 */
1091HAL_StatusTypeDef USB_WritePacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
1092 uint8_t ch_ep_num, uint16_t len, uint8_t dma)
1093{
1094 uint32_t USBx_BASE = (uint32_t)USBx;
1095 uint8_t *pSrc = src;
1096 uint32_t count32b;
1097 uint32_t i;
1098
1099 if (dma == 0U)
1100 {
1101 count32b = ((uint32_t)len + 3U) / 4U;
1102 for (i = 0U; i < count32b; i++)
1103 {
1104 USBx_DFIFO((uint32_t)ch_ep_num) = __UNALIGNED_UINT32_READ(pSrc);
1105 pSrc++;
1106 pSrc++;
1107 pSrc++;
1108 pSrc++;
1109 }
1110 }
1111
1112 return HAL_OK;
1113}
1114
1115/**
1116 * @brief USB_ReadPacket : read a packet from the RX FIFO
1117 * @param USBx Selected device
1118 * @param dest source pointer
1119 * @param len Number of bytes to read
1120 * @retval pointer to destination buffer
1121 */
1122void *USB_ReadPacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)
1123{
1124 uint32_t USBx_BASE = (uint32_t)USBx;
1125 uint8_t *pDest = dest;
1126 uint32_t pData;
1127 uint32_t i;
1128 uint32_t count32b = (uint32_t)len >> 2U;
1129 uint16_t remaining_bytes = len % 4U;
1130
1131 for (i = 0U; i < count32b; i++)
1132 {
1133 __UNALIGNED_UINT32_WRITE(pDest, USBx_DFIFO(0U));
1134 pDest++;
1135 pDest++;
1136 pDest++;
1137 pDest++;
1138 }
1139
1140 /* When Number of data is not word aligned, read the remaining byte */
1141 if (remaining_bytes != 0U)
1142 {
1143 i = 0U;
1144 __UNALIGNED_UINT32_WRITE(&pData, USBx_DFIFO(0U));
1145
1146 do
1147 {
1148 *(uint8_t *)pDest = (uint8_t)(pData >> (8U * (uint8_t)(i)));
1149 i++;
1150 pDest++;
1151 remaining_bytes--;
1152 } while (remaining_bytes != 0U);
1153 }
1154
1155 return ((void *)pDest);
1156}
1157
1158/**
1159 * @brief USB_StopDevice : Stop the usb device mode
1160 * @param USBx Selected device
1161 * @retval HAL status
1162 */
1163HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx)
1164{
1166 uint32_t USBx_BASE = (uint32_t)USBx;
1167 uint32_t i;
1168
1169 /* Clear Pending interrupt */
1170 for (i = 0U; i < 15U; i++)
1171 {
1172 USBx_INEP(i)->DIEPINT = 0xFB7FU;
1173 USBx_OUTEP(i)->DOEPINT = 0xFB7FU;
1174 }
1175
1176 /* Clear interrupt masks */
1177 USBx_DEVICE->DIEPMSK = 0U;
1178 USBx_DEVICE->DOEPMSK = 0U;
1179 USBx_DEVICE->DAINTMSK = 0U;
1180
1181 /* Flush the FIFO */
1182 ret = USB_FlushRxFifo(USBx);
1183 if (ret != HAL_OK)
1184 {
1185 return ret;
1186 }
1187
1188 ret = USB_FlushTxFifo(USBx, 0x10U);
1189 if (ret != HAL_OK)
1190 {
1191 return ret;
1192 }
1193
1194 return ret;
1195}
1196
1197/**
1198 * @brief USB_SetDevAddress : Stop the usb device mode
1199 * @param USBx Selected device
1200 * @param address new device address to be assigned
1201 * This parameter can be a value from 0 to 255
1202 * @retval HAL status
1203 */
1204HAL_StatusTypeDef USB_SetDevAddress(const USB_OTG_GlobalTypeDef *USBx, uint8_t address)
1205{
1206 uint32_t USBx_BASE = (uint32_t)USBx;
1207
1208 USBx_DEVICE->DCFG &= ~(USB_OTG_DCFG_DAD);
1209 USBx_DEVICE->DCFG |= ((uint32_t)address << 4) & USB_OTG_DCFG_DAD;
1210
1211 return HAL_OK;
1212}
1213
1214/**
1215 * @brief USB_DevConnect : Connect the USB device by enabling Rpu
1216 * @param USBx Selected device
1217 * @retval HAL status
1218 */
1219HAL_StatusTypeDef USB_DevConnect(const USB_OTG_GlobalTypeDef *USBx)
1220{
1221 uint32_t USBx_BASE = (uint32_t)USBx;
1222
1223 /* In case phy is stopped, ensure to ungate and restore the phy CLK */
1225
1226 USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_SDIS;
1227
1228 return HAL_OK;
1229}
1230
1231/**
1232 * @brief USB_DevDisconnect : Disconnect the USB device by disabling Rpu
1233 * @param USBx Selected device
1234 * @retval HAL status
1235 */
1236HAL_StatusTypeDef USB_DevDisconnect(const USB_OTG_GlobalTypeDef *USBx)
1237{
1238 uint32_t USBx_BASE = (uint32_t)USBx;
1239
1240 /* In case phy is stopped, ensure to ungate and restore the phy CLK */
1242
1243 USBx_DEVICE->DCTL |= USB_OTG_DCTL_SDIS;
1244
1245 return HAL_OK;
1246}
1247
1248/**
1249 * @brief USB_ReadInterrupts: return the global USB interrupt status
1250 * @param USBx Selected device
1251 * @retval USB Global Interrupt status
1252 */
1253uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef const *USBx)
1254{
1255 uint32_t tmpreg;
1256
1257 tmpreg = USBx->GINTSTS;
1258 tmpreg &= USBx->GINTMSK;
1259
1260 return tmpreg;
1261}
1262
1263/**
1264 * @brief USB_ReadChInterrupts: return USB channel interrupt status
1265 * @param USBx Selected device
1266 * @param chnum Channel number
1267 * @retval USB Channel Interrupt status
1268 */
1269uint32_t USB_ReadChInterrupts(const USB_OTG_GlobalTypeDef *USBx, uint8_t chnum)
1270{
1271 uint32_t USBx_BASE = (uint32_t)USBx;
1272 uint32_t tmpreg;
1273
1274 tmpreg = USBx_HC(chnum)->HCINT;
1275 tmpreg &= USBx_HC(chnum)->HCINTMSK;
1276
1277 return tmpreg;
1278}
1279
1280/**
1281 * @brief USB_ReadDevAllOutEpInterrupt: return the USB device OUT endpoints interrupt status
1282 * @param USBx Selected device
1283 * @retval USB Device OUT EP interrupt status
1284 */
1285uint32_t USB_ReadDevAllOutEpInterrupt(const USB_OTG_GlobalTypeDef *USBx)
1286{
1287 uint32_t USBx_BASE = (uint32_t)USBx;
1288 uint32_t tmpreg;
1289
1290 tmpreg = USBx_DEVICE->DAINT;
1291 tmpreg &= USBx_DEVICE->DAINTMSK;
1292
1293 return ((tmpreg & 0xffff0000U) >> 16);
1294}
1295
1296/**
1297 * @brief USB_ReadDevAllInEpInterrupt: return the USB device IN endpoints interrupt status
1298 * @param USBx Selected device
1299 * @retval USB Device IN EP interrupt status
1300 */
1301uint32_t USB_ReadDevAllInEpInterrupt(const USB_OTG_GlobalTypeDef *USBx)
1302{
1303 uint32_t USBx_BASE = (uint32_t)USBx;
1304 uint32_t tmpreg;
1305
1306 tmpreg = USBx_DEVICE->DAINT;
1307 tmpreg &= USBx_DEVICE->DAINTMSK;
1308
1309 return ((tmpreg & 0xFFFFU));
1310}
1311
1312/**
1313 * @brief Returns Device OUT EP Interrupt register
1314 * @param USBx Selected device
1315 * @param epnum endpoint number
1316 * This parameter can be a value from 0 to 15
1317 * @retval Device OUT EP Interrupt register
1318 */
1319uint32_t USB_ReadDevOutEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
1320{
1321 uint32_t USBx_BASE = (uint32_t)USBx;
1322 uint32_t tmpreg;
1323
1324 tmpreg = USBx_OUTEP((uint32_t)epnum)->DOEPINT;
1325 tmpreg &= USBx_DEVICE->DOEPMSK;
1326
1327 return tmpreg;
1328}
1329
1330/**
1331 * @brief Returns Device IN EP Interrupt register
1332 * @param USBx Selected device
1333 * @param epnum endpoint number
1334 * This parameter can be a value from 0 to 15
1335 * @retval Device IN EP Interrupt register
1336 */
1337uint32_t USB_ReadDevInEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
1338{
1339 uint32_t USBx_BASE = (uint32_t)USBx;
1340 uint32_t tmpreg;
1341 uint32_t msk;
1342 uint32_t emp;
1343
1344 msk = USBx_DEVICE->DIEPMSK;
1345 emp = USBx_DEVICE->DIEPEMPMSK;
1346 msk |= ((emp >> (epnum & EP_ADDR_MSK)) & 0x1U) << 7;
1347 tmpreg = USBx_INEP((uint32_t)epnum)->DIEPINT & msk;
1348
1349 return tmpreg;
1350}
1351
1352/**
1353 * @brief USB_ClearInterrupts: clear a USB interrupt
1354 * @param USBx Selected device
1355 * @param interrupt flag
1356 * @retval None
1357 */
1358void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt)
1359{
1360 USBx->GINTSTS &= interrupt;
1361}
1362
1363/**
1364 * @brief Returns USB core mode
1365 * @param USBx Selected device
1366 * @retval return core mode : Host or Device
1367 * This parameter can be one of these values:
1368 * 1 : Host
1369 * 0 : Device
1370 */
1371uint32_t USB_GetMode(const USB_OTG_GlobalTypeDef *USBx)
1372{
1373 return ((USBx->GINTSTS) & 0x1U);
1374}
1375
1376/**
1377 * @brief Activate EP0 for Setup transactions
1378 * @param USBx Selected device
1379 * @retval HAL status
1380 */
1381HAL_StatusTypeDef USB_ActivateSetup(const USB_OTG_GlobalTypeDef *USBx)
1382{
1383 uint32_t USBx_BASE = (uint32_t)USBx;
1384
1385 /* Set the MPS of the IN EP0 to 64 bytes */
1386 USBx_INEP(0U)->DIEPCTL &= ~USB_OTG_DIEPCTL_MPSIZ;
1387
1388 USBx_DEVICE->DCTL |= USB_OTG_DCTL_CGINAK;
1389
1390 return HAL_OK;
1391}
1392
1393/**
1394 * @brief Prepare the EP0 to start the first control setup
1395 * @param USBx Selected device
1396 * @param dma USB dma enabled or disabled
1397 * This parameter can be one of these values:
1398 * 0 : DMA feature not used
1399 * 1 : DMA feature used
1400 * @param psetup pointer to setup packet
1401 * @retval HAL status
1402 */
1403HAL_StatusTypeDef USB_EP0_OutStart(const USB_OTG_GlobalTypeDef *USBx, uint8_t dma, const uint8_t *psetup)
1404{
1405 uint32_t USBx_BASE = (uint32_t)USBx;
1406 uint32_t gSNPSiD = *(__IO const uint32_t *)(&USBx->CID + 0x1U);
1407
1408 if (gSNPSiD > USB_OTG_CORE_ID_300A)
1409 {
1410 if ((USBx_OUTEP(0U)->DOEPCTL & USB_OTG_DOEPCTL_EPENA) == USB_OTG_DOEPCTL_EPENA)
1411 {
1412 return HAL_OK;
1413 }
1414 }
1415
1416 USBx_OUTEP(0U)->DOEPTSIZ = 0U;
1417 USBx_OUTEP(0U)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1UL << 19));
1418 USBx_OUTEP(0U)->DOEPTSIZ |= (3U * 8U);
1419 USBx_OUTEP(0U)->DOEPTSIZ |= USB_OTG_DOEPTSIZ_STUPCNT;
1420
1421 if (dma == 1U)
1422 {
1423 USBx_OUTEP(0U)->DOEPDMA = (uint32_t)psetup;
1424 /* EP enable */
1425 USBx_OUTEP(0U)->DOEPCTL |= USB_OTG_DOEPCTL_EPENA | USB_OTG_DOEPCTL_USBAEP;
1426 }
1427
1428 return HAL_OK;
1429}
1430
1431/**
1432 * @brief Reset the USB Core (needed after USB clock settings change)
1433 * @param USBx Selected device
1434 * @retval HAL status
1435 */
1436static HAL_StatusTypeDef USB_CoreReset(USB_OTG_GlobalTypeDef *USBx)
1437{
1438 __IO uint32_t count = 0U;
1439
1440 /* Wait for AHB master IDLE state. */
1441 do
1442 {
1443 count++;
1444
1445 if (count > HAL_USB_TIMEOUT)
1446 {
1447 return HAL_TIMEOUT;
1448 }
1449 } while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_AHBIDL) == 0U);
1450
1451 count = 10U;
1452
1453 /* few cycles before setting core reset */
1454 while (count > 0U)
1455 {
1456 count--;
1457 }
1458
1459 /* Core Soft Reset */
1461
1462 do
1463 {
1464 count++;
1465
1466 if (count > HAL_USB_TIMEOUT)
1467 {
1468 return HAL_TIMEOUT;
1469 }
1471
1472 return HAL_OK;
1473}
1474
1475/**
1476 * @brief USB_HostInit : Initializes the USB OTG controller registers
1477 * for Host mode
1478 * @param USBx Selected device
1479 * @param cfg pointer to a USB_OTG_CfgTypeDef structure that contains
1480 * the configuration information for the specified USBx peripheral.
1481 * @retval HAL status
1482 */
1483HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
1484{
1486 uint32_t USBx_BASE = (uint32_t)USBx;
1487 uint32_t i;
1488
1489 /* Restart the Phy Clock */
1490 USBx_PCGCCTL = 0U;
1491
1492 /* Disable VBUS sensing */
1493 USBx->GCCFG &= ~(USB_OTG_GCCFG_VBDEN);
1494
1495 /* Disable Battery chargin detector */
1496 USBx->GCCFG &= ~(USB_OTG_GCCFG_BCDEN);
1497
1498
1499 if ((USBx->GUSBCFG & USB_OTG_GUSBCFG_PHYSEL) == 0U)
1500 {
1501 if (cfg.speed == USBH_FSLS_SPEED)
1502 {
1503 /* Force Device Enumeration to FS/LS mode only */
1504 USBx_HOST->HCFG |= USB_OTG_HCFG_FSLSS;
1505 }
1506 else
1507 {
1508 /* Set default Max speed support */
1509 USBx_HOST->HCFG &= ~(USB_OTG_HCFG_FSLSS);
1510 }
1511 }
1512 else
1513 {
1514 /* Set default Max speed support */
1515 USBx_HOST->HCFG &= ~(USB_OTG_HCFG_FSLSS);
1516 }
1517
1518 /* Make sure the FIFOs are flushed. */
1519 if (USB_FlushTxFifo(USBx, 0x10U) != HAL_OK) /* all Tx FIFOs */
1520 {
1521 ret = HAL_ERROR;
1522 }
1523
1524 if (USB_FlushRxFifo(USBx) != HAL_OK)
1525 {
1526 ret = HAL_ERROR;
1527 }
1528
1529 /* Clear all pending HC Interrupts */
1530 for (i = 0U; i < cfg.Host_channels; i++)
1531 {
1532 USBx_HC(i)->HCINT = CLEAR_INTERRUPT_MASK;
1533 USBx_HC(i)->HCINTMSK = 0U;
1534 }
1535
1536 /* Disable all interrupts. */
1537 USBx->GINTMSK = 0U;
1538
1539 /* Clear any pending interrupts */
1540 USBx->GINTSTS = CLEAR_INTERRUPT_MASK;
1541 /* set Rx FIFO size */
1542 USBx->GRXFSIZ = 0x200U;
1543 USBx->DIEPTXF0_HNPTXFSIZ = (uint32_t)(((0x100UL << 16) & USB_OTG_NPTXFD) | 0x200U);
1544 USBx->HPTXFSIZ = (uint32_t)(((0xE0UL << 16) & USB_OTG_HPTXFSIZ_PTXFD) | 0x300U);
1545
1546 /* Enable the common interrupts */
1547 if (cfg.dma_enable == 0U)
1548 {
1550 }
1551
1552 /* Enable interrupts matching to the Host mode ONLY */
1556
1557 return ret;
1558}
1559
1560/**
1561 * @brief USB_InitFSLSPClkSel : Initializes the FSLSPClkSel field of the
1562 * HCFG register on the PHY type and set the right frame interval
1563 * @param USBx Selected device
1564 * @param freq clock frequency
1565 * This parameter can be one of these values:
1566 * HCFG_48_MHZ : Full Speed 48 MHz Clock
1567 * HCFG_6_MHZ : Low Speed 6 MHz Clock
1568 * @retval HAL status
1569 */
1570HAL_StatusTypeDef USB_InitFSLSPClkSel(const USB_OTG_GlobalTypeDef *USBx, uint8_t freq)
1571{
1572 uint32_t USBx_BASE = (uint32_t)USBx;
1573
1574 USBx_HOST->HCFG &= ~(USB_OTG_HCFG_FSLSPCS);
1575 USBx_HOST->HCFG |= (uint32_t)freq & USB_OTG_HCFG_FSLSPCS;
1576
1577 if (freq == HCFG_48_MHZ)
1578 {
1579 USBx_HOST->HFIR = HFIR_48_MHZ;
1580 }
1581 else if (freq == HCFG_6_MHZ)
1582 {
1583 USBx_HOST->HFIR = HFIR_6_MHZ;
1584 }
1585 else
1586 {
1587 return HAL_ERROR;
1588 }
1589
1590 return HAL_OK;
1591}
1592
1593/**
1594 * @brief USB_OTG_ResetPort : Reset Host Port
1595 * @param USBx Selected device
1596 * @retval HAL status
1597 * @note (1)The application must wait at least 10 ms
1598 * before clearing the reset bit.
1599 */
1600HAL_StatusTypeDef USB_ResetPort(const USB_OTG_GlobalTypeDef *USBx)
1601{
1602 uint32_t USBx_BASE = (uint32_t)USBx;
1603
1604 __IO uint32_t hprt0 = 0U;
1605
1606 hprt0 = USBx_HPRT0;
1607
1610
1611 USBx_HPRT0 = (USB_OTG_HPRT_PRST | hprt0);
1612 HAL_Delay(100U); /* See Note #1 */
1613 USBx_HPRT0 = ((~USB_OTG_HPRT_PRST) & hprt0);
1614 HAL_Delay(10U);
1615
1616 return HAL_OK;
1617}
1618
1619/**
1620 * @brief USB_DriveVbus : activate or de-activate vbus
1621 * @param state VBUS state
1622 * This parameter can be one of these values:
1623 * 0 : Deactivate VBUS
1624 * 1 : Activate VBUS
1625 * @retval HAL status
1626 */
1627HAL_StatusTypeDef USB_DriveVbus(const USB_OTG_GlobalTypeDef *USBx, uint8_t state)
1628{
1629 uint32_t USBx_BASE = (uint32_t)USBx;
1630 __IO uint32_t hprt0 = 0U;
1631
1632 hprt0 = USBx_HPRT0;
1633
1636
1637 if (((hprt0 & USB_OTG_HPRT_PPWR) == 0U) && (state == 1U))
1638 {
1639 USBx_HPRT0 = (USB_OTG_HPRT_PPWR | hprt0);
1640 }
1641 if (((hprt0 & USB_OTG_HPRT_PPWR) == USB_OTG_HPRT_PPWR) && (state == 0U))
1642 {
1643 USBx_HPRT0 = ((~USB_OTG_HPRT_PPWR) & hprt0);
1644 }
1645 return HAL_OK;
1646}
1647
1648/**
1649 * @brief Return Host Port speed
1650 * @param USBx Selected device
1651 * @retval speed : Host port device speed
1652 * This parameter can be one of these values:
1653 * @arg HCD_DEVICE_SPEED_HIGH: High speed mode
1654 * @arg HCD_DEVICE_SPEED_FULL: Full speed mode
1655 * @arg HCD_DEVICE_SPEED_LOW: Low speed mode
1656 */
1657uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef const *USBx)
1658{
1659 uint32_t USBx_BASE = (uint32_t)USBx;
1660 __IO uint32_t hprt0 = 0U;
1661
1662 hprt0 = USBx_HPRT0;
1663 return ((hprt0 & USB_OTG_HPRT_PSPD) >> 17);
1664}
1665
1666/**
1667 * @brief Return Host Current Frame number
1668 * @param USBx Selected device
1669 * @retval current frame number
1670 */
1671uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef const *USBx)
1672{
1673 uint32_t USBx_BASE = (uint32_t)USBx;
1674
1675 return (USBx_HOST->HFNUM & USB_OTG_HFNUM_FRNUM);
1676}
1677
1678#if defined (HAL_HCD_MODULE_ENABLED)
1679/**
1680 * @brief Initialize a host channel
1681 * @param USBx Selected device
1682 * @param ch_num Channel number
1683 * This parameter can be a value from 1 to 15
1684 * @param epnum Endpoint number
1685 * This parameter can be a value from 1 to 15
1686 * @param dev_address Current device address
1687 * This parameter can be a value from 0 to 255
1688 * @param speed Current device speed
1689 * This parameter can be one of these values:
1690 * @arg USB_OTG_SPEED_HIGH: High speed mode
1691 * @arg USB_OTG_SPEED_FULL: Full speed mode
1692 * @arg USB_OTG_SPEED_LOW: Low speed mode
1693 * @param ep_type Endpoint Type
1694 * This parameter can be one of these values:
1695 * @arg EP_TYPE_CTRL: Control type
1696 * @arg EP_TYPE_ISOC: Isochronous type
1697 * @arg EP_TYPE_BULK: Bulk type
1698 * @arg EP_TYPE_INTR: Interrupt type
1699 * @param mps Max Packet Size
1700 * This parameter can be a value from 0 to 32K
1701 * @retval HAL state
1702 */
1703HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num,
1704 uint8_t epnum, uint8_t dev_address, uint8_t speed,
1705 uint8_t ep_type, uint16_t mps)
1706{
1708 uint32_t USBx_BASE = (uint32_t)USBx;
1709 uint32_t HCcharEpDir;
1710 uint32_t HCcharLowSpeed;
1711 uint32_t HostCoreSpeed;
1712
1713 /* Clear old interrupt conditions for this host channel. */
1714 USBx_HC((uint32_t)ch_num)->HCINT = CLEAR_INTERRUPT_MASK;
1715
1716 /* Enable channel interrupts required for this transfer. */
1717 switch (ep_type)
1718 {
1719 case EP_TYPE_CTRL:
1720 case EP_TYPE_BULK:
1721 USBx_HC((uint32_t)ch_num)->HCINTMSK = USB_OTG_HCINTMSK_XFRCM |
1727
1728 if ((epnum & 0x80U) == 0x80U)
1729 {
1730 USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_BBERRM;
1731 }
1732 else
1733 {
1734 USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_NYET |
1736 }
1737 break;
1738
1739 case EP_TYPE_INTR:
1740 USBx_HC((uint32_t)ch_num)->HCINTMSK = USB_OTG_HCINTMSK_XFRCM |
1747
1748 if ((epnum & 0x80U) == 0x80U)
1749 {
1750 USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_BBERRM;
1751 }
1752
1753 break;
1754
1755 case EP_TYPE_ISOC:
1756 USBx_HC((uint32_t)ch_num)->HCINTMSK = USB_OTG_HCINTMSK_XFRCM |
1760
1761 if ((epnum & 0x80U) == 0x80U)
1762 {
1763 USBx_HC((uint32_t)ch_num)->HCINTMSK |= (USB_OTG_HCINTMSK_TXERRM | USB_OTG_HCINTMSK_BBERRM);
1764 }
1765 break;
1766
1767 default:
1768 ret = HAL_ERROR;
1769 break;
1770 }
1771
1772 /* Clear Hub Start Split transaction */
1773 USBx_HC((uint32_t)ch_num)->HCSPLT = 0U;
1774
1775 /* Enable host channel Halt interrupt */
1776 USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_CHHM;
1777
1778 /* Enable the top level host channel interrupt. */
1779 USBx_HOST->HAINTMSK |= 1UL << (ch_num & 0xFU);
1780
1781 /* Make sure host channel interrupts are enabled. */
1783
1784 /* Program the HCCHAR register */
1785 if ((epnum & 0x80U) == 0x80U)
1786 {
1787 HCcharEpDir = (0x1UL << 15) & USB_OTG_HCCHAR_EPDIR;
1788 }
1789 else
1790 {
1791 HCcharEpDir = 0U;
1792 }
1793
1794 HostCoreSpeed = USB_GetHostSpeed(USBx);
1795
1796 /* LS device plugged to HUB */
1797 if ((speed == HPRT0_PRTSPD_LOW_SPEED) && (HostCoreSpeed != HPRT0_PRTSPD_LOW_SPEED))
1798 {
1799 HCcharLowSpeed = (0x1UL << 17) & USB_OTG_HCCHAR_LSDEV;
1800 }
1801 else
1802 {
1803 HCcharLowSpeed = 0U;
1804 }
1805
1806 USBx_HC((uint32_t)ch_num)->HCCHAR = (((uint32_t)dev_address << 22) & USB_OTG_HCCHAR_DAD) |
1807 ((((uint32_t)epnum & 0x7FU) << 11) & USB_OTG_HCCHAR_EPNUM) |
1808 (((uint32_t)ep_type << 18) & USB_OTG_HCCHAR_EPTYP) |
1809 ((uint32_t)mps & USB_OTG_HCCHAR_MPSIZ) |
1810 USB_OTG_HCCHAR_MC_0 | HCcharEpDir | HCcharLowSpeed;
1811
1812 if ((ep_type == EP_TYPE_INTR) || (ep_type == EP_TYPE_ISOC))
1813 {
1814 USBx_HC((uint32_t)ch_num)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM;
1815 }
1816
1817 return ret;
1818}
1819
1820/**
1821 * @brief Start a transfer over a host channel
1822 * @param USBx Selected device
1823 * @param hc pointer to host channel structure
1824 * @param dma USB dma enabled or disabled
1825 * This parameter can be one of these values:
1826 * 0 : DMA feature not used
1827 * 1 : DMA feature used
1828 * @retval HAL state
1829 */
1830HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDef *hc, uint8_t dma)
1831{
1832 uint32_t USBx_BASE = (uint32_t)USBx;
1833 uint32_t ch_num = (uint32_t)hc->ch_num;
1834 __IO uint32_t tmpreg;
1835 uint8_t is_oddframe;
1836 uint16_t len_words;
1837 uint16_t num_packets;
1838 uint16_t max_hc_pkt_count = HC_MAX_PKT_CNT;
1839
1840 /* in DMA mode host Core automatically issues ping in case of NYET/NAK */
1841 if (dma == 1U)
1842 {
1843 if (((hc->ep_type == EP_TYPE_CTRL) || (hc->ep_type == EP_TYPE_BULK)) && (hc->do_ssplit == 0U))
1844 {
1845
1846 USBx_HC((uint32_t)ch_num)->HCINTMSK &= ~(USB_OTG_HCINTMSK_NYET |
1849 }
1850 }
1851 else
1852 {
1853 if ((hc->speed == USBH_HS_SPEED) && (hc->do_ping == 1U))
1854 {
1855 (void)USB_DoPing(USBx, hc->ch_num);
1856 return HAL_OK;
1857 }
1858 }
1859
1860 if (hc->do_ssplit == 1U)
1861 {
1862 /* Set number of packet to 1 for Split transaction */
1863 num_packets = 1U;
1864
1865 if (hc->ep_is_in != 0U)
1866 {
1867 hc->XferSize = (uint32_t)num_packets * hc->max_packet;
1868 }
1869 else
1870 {
1871 if (hc->ep_type == EP_TYPE_ISOC)
1872 {
1873 if (hc->xfer_len > ISO_SPLT_MPS)
1874 {
1875 /* Isochrone Max Packet Size for Split mode */
1876 hc->XferSize = hc->max_packet;
1877 hc->xfer_len = hc->XferSize;
1878
1879 if ((hc->iso_splt_xactPos == HCSPLT_BEGIN) || (hc->iso_splt_xactPos == HCSPLT_MIDDLE))
1880 {
1881 hc->iso_splt_xactPos = HCSPLT_MIDDLE;
1882 }
1883 else
1884 {
1885 hc->iso_splt_xactPos = HCSPLT_BEGIN;
1886 }
1887 }
1888 else
1889 {
1890 hc->XferSize = hc->xfer_len;
1891
1892 if ((hc->iso_splt_xactPos != HCSPLT_BEGIN) && (hc->iso_splt_xactPos != HCSPLT_MIDDLE))
1893 {
1894 hc->iso_splt_xactPos = HCSPLT_FULL;
1895 }
1896 else
1897 {
1898 hc->iso_splt_xactPos = HCSPLT_END;
1899 }
1900 }
1901 }
1902 else
1903 {
1904 if ((dma == 1U) && (hc->xfer_len > hc->max_packet))
1905 {
1906 hc->XferSize = (uint32_t)num_packets * hc->max_packet;
1907 }
1908 else
1909 {
1910 hc->XferSize = hc->xfer_len;
1911 }
1912 }
1913 }
1914 }
1915 else
1916 {
1917 /* Compute the expected number of packets associated to the transfer */
1918 if (hc->xfer_len > 0U)
1919 {
1920 num_packets = (uint16_t)((hc->xfer_len + hc->max_packet - 1U) / hc->max_packet);
1921
1922 if (num_packets > max_hc_pkt_count)
1923 {
1924 num_packets = max_hc_pkt_count;
1925 hc->XferSize = (uint32_t)num_packets * hc->max_packet;
1926 }
1927 }
1928 else
1929 {
1930 num_packets = 1U;
1931 }
1932
1933 /*
1934 * For IN channel HCTSIZ.XferSize is expected to be an integer multiple of
1935 * max_packet size.
1936 */
1937 if (hc->ep_is_in != 0U)
1938 {
1939 hc->XferSize = (uint32_t)num_packets * hc->max_packet;
1940 }
1941 else
1942 {
1943 hc->XferSize = hc->xfer_len;
1944 }
1945 }
1946
1947 /* Initialize the HCTSIZn register */
1948 USBx_HC(ch_num)->HCTSIZ = (hc->XferSize & USB_OTG_HCTSIZ_XFRSIZ) |
1949 (((uint32_t)num_packets << 19) & USB_OTG_HCTSIZ_PKTCNT) |
1950 (((uint32_t)hc->data_pid << 29) & USB_OTG_HCTSIZ_DPID);
1951
1952 if (dma != 0U)
1953 {
1954 /* xfer_buff MUST be 32-bits aligned */
1955 USBx_HC(ch_num)->HCDMA = (uint32_t)hc->xfer_buff;
1956 }
1957
1958 is_oddframe = (((uint32_t)USBx_HOST->HFNUM & 0x01U) != 0U) ? 0U : 1U;
1959 USBx_HC(ch_num)->HCCHAR &= ~USB_OTG_HCCHAR_ODDFRM;
1960 USBx_HC(ch_num)->HCCHAR |= (uint32_t)is_oddframe << 29;
1961
1962 if (hc->do_ssplit == 1U)
1963 {
1964 /* Set Hub start Split transaction */
1965 USBx_HC((uint32_t)ch_num)->HCSPLT = ((uint32_t)hc->hub_addr << USB_OTG_HCSPLT_HUBADDR_Pos) |
1966 (uint32_t)hc->hub_port_nbr | USB_OTG_HCSPLT_SPLITEN;
1967
1968 /* unmask ack & nyet for IN/OUT transactions */
1969 USBx_HC((uint32_t)ch_num)->HCINTMSK |= (USB_OTG_HCINTMSK_ACKM |
1971
1972 if ((hc->do_csplit == 1U) && (hc->ep_is_in == 0U))
1973 {
1974 USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_COMPLSPLT;
1975 USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_NYET;
1976 }
1977
1978 if (((hc->ep_type == EP_TYPE_ISOC) || (hc->ep_type == EP_TYPE_INTR)) &&
1979 (hc->do_csplit == 1U) && (hc->ep_is_in == 1U))
1980 {
1981 USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_COMPLSPLT;
1982 }
1983
1984 /* Position management for iso out transaction on split mode */
1985 if ((hc->ep_type == EP_TYPE_ISOC) && (hc->ep_is_in == 0U))
1986 {
1987 /* Set data payload position */
1988 switch (hc->iso_splt_xactPos)
1989 {
1990 case HCSPLT_BEGIN:
1991 /* First data payload for OUT Transaction */
1992 USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_XACTPOS_1;
1993 break;
1994
1995 case HCSPLT_MIDDLE:
1996 /* Middle data payload for OUT Transaction */
1997 USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_XACTPOS_Pos;
1998 break;
1999
2000 case HCSPLT_END:
2001 /* End data payload for OUT Transaction */
2002 USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_XACTPOS_0;
2003 break;
2004
2005 case HCSPLT_FULL:
2006 /* Entire data payload for OUT Transaction */
2007 USBx_HC((uint32_t)ch_num)->HCSPLT |= USB_OTG_HCSPLT_XACTPOS;
2008 break;
2009
2010 default:
2011 break;
2012 }
2013 }
2014 }
2015 else
2016 {
2017 /* Clear Hub Start Split transaction */
2018 USBx_HC((uint32_t)ch_num)->HCSPLT = 0U;
2019 }
2020
2021 /* Set host channel enable */
2022 tmpreg = USBx_HC(ch_num)->HCCHAR;
2023 tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
2024
2025 /* make sure to set the correct ep direction */
2026 if (hc->ep_is_in != 0U)
2027 {
2028 tmpreg |= USB_OTG_HCCHAR_EPDIR;
2029 }
2030 else
2031 {
2032 tmpreg &= ~USB_OTG_HCCHAR_EPDIR;
2033 }
2034 tmpreg |= USB_OTG_HCCHAR_CHENA;
2035 USBx_HC(ch_num)->HCCHAR = tmpreg;
2036
2037 if (dma != 0U) /* dma mode */
2038 {
2039 return HAL_OK;
2040 }
2041
2042 if ((hc->ep_is_in == 0U) && (hc->xfer_len > 0U) && (hc->do_csplit == 0U))
2043 {
2044 switch (hc->ep_type)
2045 {
2046 /* Non periodic transfer */
2047 case EP_TYPE_CTRL:
2048 case EP_TYPE_BULK:
2049
2050 len_words = (uint16_t)((hc->xfer_len + 3U) / 4U);
2051
2052 /* check if there is enough space in FIFO space */
2053 if (len_words > (USBx->HNPTXSTS & 0xFFFFU))
2054 {
2055 /* need to process data in nptxfempty interrupt */
2057 }
2058 break;
2059
2060 /* Periodic transfer */
2061 case EP_TYPE_INTR:
2062 case EP_TYPE_ISOC:
2063 len_words = (uint16_t)((hc->xfer_len + 3U) / 4U);
2064 /* check if there is enough space in FIFO space */
2065 if (len_words > (USBx_HOST->HPTXSTS & 0xFFFFU)) /* split the transfer */
2066 {
2067 /* need to process data in ptxfempty interrupt */
2069 }
2070 break;
2071
2072 default:
2073 break;
2074 }
2075
2076 /* Write packet into the Tx FIFO. */
2077 (void)USB_WritePacket(USBx, hc->xfer_buff, hc->ch_num, (uint16_t)hc->xfer_len, 0);
2078 }
2079
2080 return HAL_OK;
2081}
2082
2083/**
2084 * @brief Read all host channel interrupts status
2085 * @param USBx Selected device
2086 * @retval HAL state
2087 */
2088uint32_t USB_HC_ReadInterrupt(const USB_OTG_GlobalTypeDef *USBx)
2089{
2090 uint32_t USBx_BASE = (uint32_t)USBx;
2091
2092 return ((USBx_HOST->HAINT) & 0xFFFFU);
2093}
2094
2095/**
2096 * @brief Halt a host channel
2097 * @param USBx Selected device
2098 * @param hc_num Host Channel number
2099 * This parameter can be a value from 1 to 15
2100 * @retval HAL state
2101 */
2102HAL_StatusTypeDef USB_HC_Halt(const USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num)
2103{
2104 uint32_t USBx_BASE = (uint32_t)USBx;
2105 uint32_t hcnum = (uint32_t)hc_num;
2106 __IO uint32_t count = 0U;
2107 uint32_t HcEpType = (USBx_HC(hcnum)->HCCHAR & USB_OTG_HCCHAR_EPTYP) >> 18;
2108 uint32_t ChannelEna = (USBx_HC(hcnum)->HCCHAR & USB_OTG_HCCHAR_CHENA) >> 31;
2109 uint32_t SplitEna = (USBx_HC(hcnum)->HCSPLT & USB_OTG_HCSPLT_SPLITEN) >> 31;
2110
2111 /* In buffer DMA, Channel disable must not be programmed for non-split periodic channels.
2112 At the end of the next uframe/frame (in the worst case), the core generates a channel halted
2113 and disables the channel automatically. */
2114
2115 if ((((USBx->GAHBCFG & USB_OTG_GAHBCFG_DMAEN) == USB_OTG_GAHBCFG_DMAEN) && (SplitEna == 0U)) &&
2116 ((ChannelEna == 0U) || (((HcEpType == HCCHAR_ISOC) || (HcEpType == HCCHAR_INTR)))))
2117 {
2118 return HAL_OK;
2119 }
2120
2121 /* Check for space in the request queue to issue the halt. */
2122 if ((HcEpType == HCCHAR_CTRL) || (HcEpType == HCCHAR_BULK))
2123 {
2124 USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHDIS;
2125
2126 if ((USBx->GAHBCFG & USB_OTG_GAHBCFG_DMAEN) == 0U)
2127 {
2128 if ((USBx->HNPTXSTS & (0xFFUL << 16)) == 0U)
2129 {
2130 USBx_HC(hcnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHENA;
2131 USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
2132 do
2133 {
2134 count++;
2135
2136 if (count > 1000U)
2137 {
2138 break;
2139 }
2140 } while ((USBx_HC(hcnum)->HCCHAR & USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA);
2141 }
2142 else
2143 {
2144 USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
2145 }
2146 }
2147 else
2148 {
2149 USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
2150 }
2151 }
2152 else
2153 {
2154 USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHDIS;
2155
2156 if ((USBx_HOST->HPTXSTS & (0xFFUL << 16)) == 0U)
2157 {
2158 USBx_HC(hcnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHENA;
2159 USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
2160 do
2161 {
2162 count++;
2163
2164 if (count > 1000U)
2165 {
2166 break;
2167 }
2168 } while ((USBx_HC(hcnum)->HCCHAR & USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA);
2169 }
2170 else
2171 {
2172 USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
2173 }
2174 }
2175
2176 return HAL_OK;
2177}
2178
2179/**
2180 * @brief Activate a host channel
2181 * @param USBx Selected device
2182 * @param ch_num Host Channel number
2183 * This parameter can be a value from 1 to 15
2184 * @param ch_dir Host Channel direction
2185 * @retval HAL state
2186 */
2187HAL_StatusTypeDef USB_HC_Activate(const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num, uint8_t ch_dir)
2188{
2189 UNUSED(ch_dir);
2190
2191 __IO uint32_t tmpreg;
2192 uint32_t USBx_BASE = (uint32_t)USBx;
2193
2194 /* activate the channel */
2195 tmpreg = USBx_HC(ch_num)->HCCHAR;
2196
2197 if ((tmpreg & USB_OTG_HCCHAR_CHDIS) == 0U)
2198 {
2199 tmpreg |= USB_OTG_HCCHAR_CHENA;
2200 USBx_HC(ch_num)->HCCHAR = tmpreg;
2201 }
2202
2203 return HAL_OK;
2204}
2205#endif /* defined (HAL_HCD_MODULE_ENABLED) */
2206
2207/**
2208 * @brief Initiate Do Ping protocol
2209 * @param USBx Selected device
2210 * @param hc_num Host Channel number
2211 * This parameter can be a value from 1 to 15
2212 * @retval HAL state
2213 */
2214HAL_StatusTypeDef USB_DoPing(const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num)
2215{
2216 uint32_t USBx_BASE = (uint32_t)USBx;
2217 uint32_t chnum = (uint32_t)ch_num;
2218 uint32_t num_packets = 1U;
2219 uint32_t tmpreg;
2220
2221 USBx_HC(chnum)->HCTSIZ = ((num_packets << 19) & USB_OTG_HCTSIZ_PKTCNT) |
2223
2224 /* Set host channel enable */
2225 tmpreg = USBx_HC(chnum)->HCCHAR;
2226 tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
2227 tmpreg |= USB_OTG_HCCHAR_CHENA;
2228 USBx_HC(chnum)->HCCHAR = tmpreg;
2229
2230 return HAL_OK;
2231}
2232
2233/**
2234 * @brief Stop Host Core
2235 * @param USBx Selected device
2236 * @retval HAL state
2237 */
2238HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx)
2239{
2241 uint32_t USBx_BASE = (uint32_t)USBx;
2242 __IO uint32_t count = 0U;
2243 uint32_t value;
2244 uint32_t i;
2245
2246 (void)USB_DisableGlobalInt(USBx);
2247
2248 /* Flush USB FIFO */
2249 if (USB_FlushTxFifo(USBx, 0x10U) != HAL_OK) /* all Tx FIFOs */
2250 {
2251 ret = HAL_ERROR;
2252 }
2253
2254 if (USB_FlushRxFifo(USBx) != HAL_OK)
2255 {
2256 ret = HAL_ERROR;
2257 }
2258
2259 /* Flush out any leftover queued requests. */
2260 for (i = 0U; i <= 15U; i++)
2261 {
2262 value = USBx_HC(i)->HCCHAR;
2266 USBx_HC(i)->HCCHAR = value;
2267 }
2268
2269 /* Halt all channels to put them into a known state. */
2270 for (i = 0U; i <= 15U; i++)
2271 {
2272 value = USBx_HC(i)->HCCHAR;
2276 USBx_HC(i)->HCCHAR = value;
2277
2278 do
2279 {
2280 count++;
2281
2282 if (count > 1000U)
2283 {
2284 break;
2285 }
2286 } while ((USBx_HC(i)->HCCHAR & USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA);
2287 }
2288
2289 /* Clear any pending Host interrupts */
2290 USBx_HOST->HAINT = CLEAR_INTERRUPT_MASK;
2291 USBx->GINTSTS = CLEAR_INTERRUPT_MASK;
2292
2293 (void)USB_EnableGlobalInt(USBx);
2294
2295 return ret;
2296}
2297
2298/**
2299 * @brief USB_ActivateRemoteWakeup active remote wakeup signalling
2300 * @param USBx Selected device
2301 * @retval HAL status
2302 */
2303HAL_StatusTypeDef USB_ActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx)
2304{
2305 uint32_t USBx_BASE = (uint32_t)USBx;
2306
2307 if ((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS)
2308 {
2309 /* active Remote wakeup signalling */
2310 USBx_DEVICE->DCTL |= USB_OTG_DCTL_RWUSIG;
2311 }
2312
2313 return HAL_OK;
2314}
2315
2316/**
2317 * @brief USB_DeActivateRemoteWakeup de-active remote wakeup signalling
2318 * @param USBx Selected device
2319 * @retval HAL status
2320 */
2321HAL_StatusTypeDef USB_DeActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx)
2322{
2323 uint32_t USBx_BASE = (uint32_t)USBx;
2324
2325 /* active Remote wakeup signalling */
2326 USBx_DEVICE->DCTL &= ~(USB_OTG_DCTL_RWUSIG);
2327
2328 return HAL_OK;
2329}
2330#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
2331
2332/**
2333 * @}
2334 */
2335
2336/**
2337 * @}
2338 */
2339#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
2340#endif /* defined (HAL_PCD_MODULE_ENABLED) || defined (HAL_HCD_MODULE_ENABLED) */
2341
2342/**
2343 * @}
2344 */
#define __UNALIGNED_UINT32_WRITE(addr, val)
Definition cmsis_armcc.h:97
#define __UNALIGNED_UINT32_READ(addr)
#define __IO
Defines 'read / write' permissions.
static ActuatorControllerState state
Definition main.cpp:57
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
#define USB_OTG_HCINTMSK_STALLM
STALL response received interrupt mask.
#define USB_OTG_GUSBCFG_FDMOD
Forced peripheral mode.
#define USB_OTG_DIEPCTL_SNAK
Set NAK.
#define USB_OTG_HCINTMSK_NYET
response received interrupt mask
#define USB_OTG_DOEPCTL_SNAK
Set NAK.
#define USB_OTG_GINTMSK_USBRST
USB reset mask.
#define USB_OTG_DOEPCTL_SD0PID_SEVNFRM
Set DATA0 PID.
#define USB_OTG_HCSPLT_XACTPOS_1
0x00008000
#define USB_OTG_DOEPCTL_MPSIZ
Bit 1.
#define USB_OTG_GOTGCTL_BVALOEN
B-peripheral session valid override enable.
#define USB_OTG_HCCHAR_MC_0
0x00100000
#define USB_OTG_GINTMSK_OTGINT
OTG interrupt mask.
#define USB_OTG_DCTL_SDIS
Soft disconnect.
#define USB_OTG_GCCFG_VBDEN
Secondary detection (SD) mode enable.
#define USB_OTG_HPRT_PCDET
Port connect detected.
#define USB_OTG_HCCHAR_EPTYP
Endpoint type.
#define USB_OTG_HCCHAR_CHENA
Channel enable.
#define USB_OTG_GINTMSK_HCIM
Host channels interrupt mask.
#define USB_OTG_DCTL_CGINAK
Clear global IN NAK.
#define USB_OTG_HPRT_PPWR
Port power.
#define USB_OTG_HCCHAR_LSDEV
Low-speed device.
#define USB_OTG_GUSBCFG_PHYSEL
USB 2.0 high-speed ULPI PHY or USB 1.1 full-speed serial transceiver select.
#define USB_OTG_HCINTMSK_ACKM
ACK response received/transmitted interrupt mask.
#define USB_OTG_DCTL_CGONAK
Clear global OUT NAK.
#define USB_OTG_GINTMSK_PTXFEM
Periodic TxFIFO empty mask.
#define USB_OTG_GINTSTS_BOUTNAKEFF
Global OUT NAK effective.
#define USB_OTG_HCTSIZ_DOPING
Do PING.
#define USB_OTG_DIEPCTL_EPTYP
Endpoint type.
#define USB_OTG_GAHBCFG_HBSTLEN
Burst length/type.
#define USB_OTG_HCCHAR_EPDIR
Endpoint direction.
#define USB_OTG_DOEPINT_EPDISD
Endpoint disabled interrupt.
#define USB_OTG_HCCHAR_CHDIS
Channel disable.
#define USB_OTG_GUSBCFG_ULPIEVBUSI
ULPI external VBUS indicator.
#define USB_OTG_GINTMSK_NPTXFEM
Nonperiodic TxFIFO empty mask.
#define USB_OTG_DIEPTSIZ_MULCNT
Packet count.
#define USB_OTG_GAHBCFG_DMAEN
DMA enable.
#define USB_OTG_GCCFG_PWRDWN
Power down.
#define USB_OTG_DOEPCTL_EPTYP
Endpoint type.
#define USB_OTG_HCINTMSK_NAKM
NAK response received interrupt mask.
#define USB_OTG_DIEPCTL_USBAEP
USB active endpoint.
#define USB_OTG_HCINTMSK_TXERRM
Transaction error mask.
#define USB_OTG_DIEPTSIZ_XFRSIZ
Transfer size.
#define USB_OTG_HPRT_PRST
Port reset.
#define USB_OTG_HPRT_PSPD
Port speed.
#define USB_OTG_DOEPTSIZ_STUPCNT
SETUP packet count.
#define USB_OTG_DOEPCTL_STALL
STALL handshake.
#define USB_OTG_GINTMSK_ENUMDNEM
Enumeration done mask.
#define USB_OTG_DIEPTSIZ_PKTCNT
Packet count.
#define USB_OTG_HCTSIZ_DPID
Data PID.
#define USB_OTG_DCTL_SGONAK
Set global OUT NAK.
#define USB_OTG_PCGCCTL_STOPCLK
SETUP packet count.
#define USB_OTG_DOEPCTL_SODDFRM
Set odd frame.
#define USB_OTG_HCINTMSK_DTERRM
Data toggle error mask.
#define USB_OTG_HPRT_PENCHNG
Port enable/disable change.
#define USB_OTG_GINTMSK_PXFRM_IISOOXFRM
Incomplete periodic transfer mask.
#define USB_OTG_HPTXFSIZ_PTXFD
Host periodic TxFIFO depth.
#define USB_OTG_DOEPCTL_EPENA
Endpoint enable.
#define USB_OTG_GINTMSK_SRQIM
Session request/new session detected interrupt mask.
#define USB_OTG_HCFG_FSLSPCS
FS/LS PHY clock select.
#define USB_OTG_DIEPMSK_TXFURM
FIFO underrun mask.
#define USB_OTG_DCTL_RWUSIG
Remote wakeup signaling.
#define USB_OTG_HCINTMSK_CHHM
Channel halted mask.
#define USB_OTG_DSTS_SUSPSTS
Suspend status.
#define USB_OTG_HPRT_PENA
Port enable.
#define USB_OTG_HCSPLT_HUBADDR_Pos
#define USB_OTG_HCSPLT_XACTPOS_Pos
#define USB_OTG_HCFG_FSLSS
FS- and LS-only support.
#define USB_OTG_HCTSIZ_XFRSIZ
Transfer size.
#define USB_OTG_GINTMSK_IISOIXFRM
Incomplete isochronous IN transfer mask.
#define USB_OTG_GUSBCFG_ULPIFSLS
ULPI FS/LS select.
#define USB_OTG_HCINTMSK_BBERRM
Babble error mask.
#define USB_OTG_DIEPCTL_EPDIS
Endpoint disable.
#define USB_OTG_HCSPLT_SPLITEN
Split enable.
#define USB_OTG_HCINTMSK_XFRCM
Transfer completed mask.
#define USB_OTG_NPTXFD
Nonperiodic TxFIFO depth.
#define USB_OTG_GINTMSK_USBSUSPM
USB suspend mask.
#define USB_OTG_GINTMSK_IEPINT
IN endpoints interrupt mask.
#define USB_OTG_GINTSTS_DISCINT
Disconnect detected interrupt.
#define USB_OTG_DAINTMSK_IEPM
IN EP interrupt mask bits.
#define USB_OTG_HCTSIZ_PKTCNT
Packet count.
#define USB_OTG_HFNUM_FRNUM
Frame number.
#define USB_OTG_DIEPCTL_STALL
STALL handshake.
#define USB_OTG_HCSPLT_COMPLSPLT
Do complete split.
#define USB_OTG_GINTMSK_WUIM
Resume/remote wakeup detected interrupt mask.
#define USB_OTG_DIEPCTL_CNAK
Clear NAK.
#define USB_OTG_GINTMSK_PRTIM
Host port interrupt mask.
#define USB_OTG_DOEPTSIZ_XFRSIZ
Transfer size.
#define USB_OTG_GINTMSK_GONAKEFFM
Global OUT NAK effective mask.
#define USB_OTG_GINTMSK_SOFM
Start of frame mask.
#define USB_OTG_HPRT_POCCHNG
Port overcurrent change.
#define USB_OTG_DOEPCTL_CNAK
Clear NAK.
#define USB_OTG_GINTSTS_RXFLVL
RxFIFO nonempty.
#define USB_OTG_DIEPCTL_MPSIZ
Maximum packet size.
#define USB_OTG_GUSBCFG_TSDPS
TermSel DLine pulsing selection.
#define USB_OTG_DOEPCTL_USBAEP
USB active endpoint.
#define USB_OTG_GRSTCTL_AHBIDL
AHB master idle.
#define USB_OTG_GUSBCFG_FHMOD
Forced host mode.
#define USB_OTG_DIEPCTL_SD0PID_SEVNFRM
Set DATA0 PID.
#define USB_OTG_HCSPLT_XACTPOS
XACTPOS.
#define USB_OTG_GRSTCTL_TXFFLSH
TxFIFO flush.
#define USB_OTG_GRSTCTL_RXFFLSH
RxFIFO flush.
#define USB_OTG_GINTMSK_RXFLVLM
Receive FIFO nonempty mask.
#define USB_OTG_DAINTMSK_OEPM
OUT EP interrupt mask bits.
#define USB_OTG_HCCHAR_DAD
Device address.
#define USB_OTG_HCINTMSK_FRMORM
Frame overrun mask.
#define USB_OTG_DIEPCTL_TXFNUM
TxFIFO number.
#define USB_OTG_GRSTCTL_CSRST
Core soft reset.
#define USB_OTG_DIEPCTL_EPENA
Endpoint enable.
#define USB_OTG_GCCFG_BCDEN
Battery charging detector (BCD) enable.
#define USB_OTG_HCCHAR_ODDFRM
Odd frame.
#define USB_OTG_PCGCCTL_GATECLK
Bit 0.
#define USB_OTG_HCCHAR_EPNUM
Endpoint number.
#define USB_OTG_HCSPLT_XACTPOS_0
0x00004000
#define USB_OTG_DOEPTSIZ_PKTCNT
Packet count.
#define USB_OTG_DIEPCTL_SODDFRM
Set odd frame.
#define USB_OTG_GUSBCFG_TRDT
USB turnaround time.
#define USB_OTG_GOTGCTL_BVALOVAL
B-peripheral session valid override value.
#define USB_OTG_DOEPCTL_EPDIS
Endpoint disable.
#define USB_OTG_HCINTMSK_AHBERR
AHB error.
#define USB_OTG_DSTS_ENUMSPD
Enumerated speed.
#define USB_OTG_HCCHAR_MPSIZ
Maximum packet size.
#define USB_OTG_DCFG_DAD
Device address.
#define USB_OTG_GUSBCFG_ULPIEVBUSD
ULPI External VBUS Drive.
#define USB_OTG_GAHBCFG_GINT
Global interrupt mask.
#define USB_OTG_GINTMSK_OEPINT
OUT endpoints interrupt mask.
size_type count(const key_type &key) const
Definition json.hpp:19264
interrupt()
Definition pt_cali.py:242
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_TIMEOUT
@ HAL_ERROR
@ HAL_OK
#define UNUSED(x)
USB_OTG_Core_Registers.
__IO uint32_t GDFIFOCFG
DFIFO Software Config Register 05Ch.
__IO uint32_t GRXSTSP
Receive Sts Q Read & POP Register 020h.
__IO uint32_t GINTSTS
Core Interrupt Register 014h.
__IO uint32_t GUSBCFG
Core USB Configuration Register 00Ch.
__IO uint32_t GAHBCFG
Core AHB Configuration Register 008h.
__IO uint32_t GINTMSK
Core Interrupt Mask Register 018h.
__IO uint32_t GOTGCTL
USB_OTG Control and Status Register 000h.
__IO uint32_t CID
User ID Register 03Ch.
__IO uint32_t GRSTCTL
Core Reset Register 010h.
__IO uint32_t DIEPTXF[0x0F]
dev Periodic Transmit FIFO
__IO uint32_t HNPTXSTS
Non Periodic Tx FIFO/Queue Sts reg 02Ch.
__IO uint32_t GCCFG
General Purpose IO Register 038h.
__IO uint32_t DIEPTXF0_HNPTXFSIZ
EP0 / Non Periodic Tx FIFO Size Register 028h.
__IO uint32_t HPTXFSIZ
Host Periodic Tx FIFO Size Reg 100h.
__IO uint32_t GRXFSIZ
Receive FIFO Size Register 024h.