1 /**
2 ******************************************************************************
3 * @file stm32f2xx_hal_pcd_ex.c
4 * @author MCD Application Team
5 * @brief PCD Extended HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the USB Peripheral Controller:
8 * + Extended features functions
9 *
10 ******************************************************************************
11 * @attention
12 *
13 * Copyright (c) 2016 STMicroelectronics.
14 * All rights reserved.
15 *
16 * This software is licensed under terms that can be found in the LICENSE file
17 * in the root directory of this software component.
18 * If no LICENSE file comes with this software, it is provided AS-IS.
19 *
20 ******************************************************************************
21 */
22
23 /* Includes ------------------------------------------------------------------*/
24 #include "stm32f2xx_hal.h"
25
26 /** @addtogroup STM32F2xx_HAL_Driver
27 * @{
28 */
29
30 /** @defgroup PCDEx PCDEx
31 * @brief PCD Extended HAL module driver
32 * @{
33 */
34
35 #ifdef HAL_PCD_MODULE_ENABLED
36
37 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
38 /* Private types -------------------------------------------------------------*/
39 /* Private variables ---------------------------------------------------------*/
40 /* Private constants ---------------------------------------------------------*/
41 /* Private macros ------------------------------------------------------------*/
42 /* Private functions ---------------------------------------------------------*/
43 /* Exported functions --------------------------------------------------------*/
44
45 /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
46 * @{
47 */
48
49 /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
50 * @brief PCDEx control functions
51 *
52 @verbatim
53 ===============================================================================
54 ##### Extended features functions #####
55 ===============================================================================
56 [..] This section provides functions allowing to:
57 (+) Update FIFO configuration
58
59 @endverbatim
60 * @{
61 */
62 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
63 /**
64 * @brief Set Tx FIFO
65 * @param hpcd PCD handle
66 * @param fifo The number of Tx fifo
67 * @param size Fifo size
68 * @retval HAL status
69 */
HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef * hpcd,uint8_t fifo,uint16_t size)70 HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
71 {
72 uint8_t i;
73 uint32_t Tx_Offset;
74
75 /* TXn min size = 16 words. (n : Transmit FIFO index)
76 When a TxFIFO is not used, the Configuration should be as follows:
77 case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
78 --> Txm can use the space allocated for Txn.
79 case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
80 --> Txn should be configured with the minimum space of 16 words
81 The FIFO is used optimally when used TxFIFOs are allocated in the top
82 of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
83 When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
84
85 Tx_Offset = hpcd->Instance->GRXFSIZ;
86
87 if (fifo == 0U)
88 {
89 hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset;
90 }
91 else
92 {
93 Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
94 for (i = 0U; i < (fifo - 1U); i++)
95 {
96 Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
97 }
98
99 /* Multiply Tx_Size by 2 to get higher performance */
100 hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset;
101 }
102
103 return HAL_OK;
104 }
105
106 /**
107 * @brief Set Rx FIFO
108 * @param hpcd PCD handle
109 * @param size Size of Rx fifo
110 * @retval HAL status
111 */
HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef * hpcd,uint16_t size)112 HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
113 {
114 hpcd->Instance->GRXFSIZ = size;
115
116 return HAL_OK;
117 }
118 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
119
120 /**
121 * @brief Send LPM message to user layer callback.
122 * @param hpcd PCD handle
123 * @param msg LPM message
124 * @retval HAL status
125 */
HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef * hpcd,PCD_LPM_MsgTypeDef msg)126 __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
127 {
128 /* Prevent unused argument(s) compilation warning */
129 UNUSED(hpcd);
130 UNUSED(msg);
131
132 /* NOTE : This function should not be modified, when the callback is needed,
133 the HAL_PCDEx_LPM_Callback could be implemented in the user file
134 */
135 }
136
137 /**
138 * @brief Send BatteryCharging message to user layer callback.
139 * @param hpcd PCD handle
140 * @param msg LPM message
141 * @retval HAL status
142 */
HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef * hpcd,PCD_BCD_MsgTypeDef msg)143 __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
144 {
145 /* Prevent unused argument(s) compilation warning */
146 UNUSED(hpcd);
147 UNUSED(msg);
148
149 /* NOTE : This function should not be modified, when the callback is needed,
150 the HAL_PCDEx_BCD_Callback could be implemented in the user file
151 */
152 }
153
154 /**
155 * @}
156 */
157
158 /**
159 * @}
160 */
161 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
162 #endif /* HAL_PCD_MODULE_ENABLED */
163
164 /**
165 * @}
166 */
167
168 /**
169 * @}
170 */
171