Mercurial > public > ostc4
comparison Common/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.c @ 128:c78bcbd5deda FlipDisplay
Added current STM32 standandard libraries in version independend folder structure
author | Ideenmodellierer |
---|---|
date | Sun, 17 Feb 2019 21:12:22 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
127:1369f8660eaa | 128:c78bcbd5deda |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file stm32f4xx_hal_pcd_ex.c | |
4 * @author MCD Application Team | |
5 * @brief PCD 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 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> | |
14 * | |
15 * Redistribution and use in source and binary forms, with or without modification, | |
16 * are permitted provided that the following conditions are met: | |
17 * 1. Redistributions of source code must retain the above copyright notice, | |
18 * this list of conditions and the following disclaimer. | |
19 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
20 * this list of conditions and the following disclaimer in the documentation | |
21 * and/or other materials provided with the distribution. | |
22 * 3. Neither the name of STMicroelectronics nor the names of its contributors | |
23 * may be used to endorse or promote products derived from this software | |
24 * without specific prior written permission. | |
25 * | |
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
34 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
36 * | |
37 ****************************************************************************** | |
38 */ | |
39 | |
40 /* Includes ------------------------------------------------------------------*/ | |
41 #include "stm32f4xx_hal.h" | |
42 | |
43 /** @addtogroup STM32F4xx_HAL_Driver | |
44 * @{ | |
45 */ | |
46 | |
47 /** @defgroup PCDEx PCDEx | |
48 * @brief PCD Extended HAL module driver | |
49 * @{ | |
50 */ | |
51 #ifdef HAL_PCD_MODULE_ENABLED | |
52 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || \ | |
53 defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \ | |
54 defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) || \ | |
55 defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ | |
56 defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) | |
57 /* Private types -------------------------------------------------------------*/ | |
58 /* Private variables ---------------------------------------------------------*/ | |
59 /* Private constants ---------------------------------------------------------*/ | |
60 /* Private macros ------------------------------------------------------------*/ | |
61 /* Private functions ---------------------------------------------------------*/ | |
62 /* Exported functions --------------------------------------------------------*/ | |
63 | |
64 /** @defgroup PCDEx_Exported_Functions PCD Extended Exported Functions | |
65 * @{ | |
66 */ | |
67 | |
68 /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions | |
69 * @brief PCDEx control functions | |
70 * | |
71 @verbatim | |
72 =============================================================================== | |
73 ##### Extended features functions ##### | |
74 =============================================================================== | |
75 [..] This section provides functions allowing to: | |
76 (+) Update FIFO configuration | |
77 | |
78 @endverbatim | |
79 * @{ | |
80 */ | |
81 | |
82 /** | |
83 * @brief Set Tx FIFO | |
84 * @param hpcd PCD handle | |
85 * @param fifo The number of Tx fifo | |
86 * @param size Fifo size | |
87 * @retval HAL status | |
88 */ | |
89 HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size) | |
90 { | |
91 uint8_t i = 0; | |
92 uint32_t Tx_Offset = 0U; | |
93 | |
94 /* TXn min size = 16 words. (n : Transmit FIFO index) | |
95 When a TxFIFO is not used, the Configuration should be as follows: | |
96 case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes) | |
97 --> Txm can use the space allocated for Txn. | |
98 case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes) | |
99 --> Txn should be configured with the minimum space of 16 words | |
100 The FIFO is used optimally when used TxFIFOs are allocated in the top | |
101 of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones. | |
102 When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */ | |
103 | |
104 Tx_Offset = hpcd->Instance->GRXFSIZ; | |
105 | |
106 if(fifo == 0) | |
107 { | |
108 hpcd->Instance->DIEPTXF0_HNPTXFSIZ = (uint32_t)(((uint32_t)size << 16U) | Tx_Offset); | |
109 } | |
110 else | |
111 { | |
112 Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16U; | |
113 for (i = 0; i < (fifo - 1); i++) | |
114 { | |
115 Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16U); | |
116 } | |
117 | |
118 /* Multiply Tx_Size by 2 to get higher performance */ | |
119 hpcd->Instance->DIEPTXF[fifo - 1] = (uint32_t)(((uint32_t)size << 16U) | Tx_Offset); | |
120 } | |
121 | |
122 return HAL_OK; | |
123 } | |
124 | |
125 /** | |
126 * @brief Set Rx FIFO | |
127 * @param hpcd PCD handle | |
128 * @param size Size of Rx fifo | |
129 * @retval HAL status | |
130 */ | |
131 HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size) | |
132 { | |
133 hpcd->Instance->GRXFSIZ = size; | |
134 | |
135 return HAL_OK; | |
136 } | |
137 | |
138 #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ | |
139 defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) | |
140 /** | |
141 * @brief Activate LPM feature | |
142 * @param hpcd PCD handle | |
143 * @retval HAL status | |
144 */ | |
145 HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd) | |
146 { | |
147 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; | |
148 | |
149 hpcd->lpm_active = ENABLE; | |
150 hpcd->LPM_State = LPM_L0; | |
151 USBx->GINTMSK |= USB_OTG_GINTMSK_LPMINTM; | |
152 USBx->GLPMCFG |= (USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL); | |
153 | |
154 return HAL_OK; | |
155 } | |
156 | |
157 /** | |
158 * @brief Deactivate LPM feature. | |
159 * @param hpcd PCD handle | |
160 * @retval HAL status | |
161 */ | |
162 HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd) | |
163 { | |
164 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; | |
165 | |
166 hpcd->lpm_active = DISABLE; | |
167 USBx->GINTMSK &= ~USB_OTG_GINTMSK_LPMINTM; | |
168 USBx->GLPMCFG &= ~(USB_OTG_GLPMCFG_LPMEN | USB_OTG_GLPMCFG_LPMACK | USB_OTG_GLPMCFG_ENBESL); | |
169 | |
170 return HAL_OK; | |
171 } | |
172 | |
173 /** | |
174 * @brief Send LPM message to user layer callback. | |
175 * @param hpcd PCD handle | |
176 * @param msg LPM message | |
177 * @retval HAL status | |
178 */ | |
179 __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg) | |
180 { | |
181 /* Prevent unused argument(s) compilation warning */ | |
182 UNUSED(hpcd); | |
183 UNUSED(msg); | |
184 } | |
185 #endif /* STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Rx || STM32F412Vx || STM32F412Cx || STM32F413xx || STM32F423xx */ | |
186 | |
187 #if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) | |
188 /** | |
189 * @brief HAL_PCDEx_BCD_VBUSDetect : handle BatteryCharging Process | |
190 * @param hpcd PCD handle | |
191 * @retval HAL status | |
192 */ | |
193 void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd) | |
194 { | |
195 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; | |
196 uint32_t tickstart = HAL_GetTick(); | |
197 | |
198 /* Start BCD When device is connected */ | |
199 if (USBx_DEVICE->DCTL & USB_OTG_DCTL_SDIS) | |
200 { | |
201 /* Enable DCD : Data Contact Detect */ | |
202 USBx->GCCFG |= USB_OTG_GCCFG_DCDEN; | |
203 | |
204 /* Wait Detect flag or a timeout is happen*/ | |
205 while ((USBx->GCCFG & USB_OTG_GCCFG_DCDET) == 0U) | |
206 { | |
207 /* Check for the Timeout */ | |
208 if((HAL_GetTick() - tickstart ) > 1000U) | |
209 { | |
210 HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_ERROR); | |
211 return; | |
212 } | |
213 } | |
214 | |
215 /* Right response got */ | |
216 HAL_Delay(100U); | |
217 | |
218 /* Check Detect flag*/ | |
219 if (USBx->GCCFG & USB_OTG_GCCFG_DCDET) | |
220 { | |
221 HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_CONTACT_DETECTION); | |
222 } | |
223 | |
224 /*Primary detection: checks if connected to Standard Downstream Port | |
225 (without charging capability) */ | |
226 USBx->GCCFG &=~ USB_OTG_GCCFG_DCDEN; | |
227 USBx->GCCFG |= USB_OTG_GCCFG_PDEN; | |
228 HAL_Delay(100U); | |
229 | |
230 if (!(USBx->GCCFG & USB_OTG_GCCFG_PDET)) | |
231 { | |
232 /* Case of Standard Downstream Port */ | |
233 HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_STD_DOWNSTREAM_PORT); | |
234 } | |
235 else | |
236 { | |
237 /* start secondary detection to check connection to Charging Downstream | |
238 Port or Dedicated Charging Port */ | |
239 USBx->GCCFG &=~ USB_OTG_GCCFG_PDEN; | |
240 USBx->GCCFG |= USB_OTG_GCCFG_SDEN; | |
241 HAL_Delay(100U); | |
242 | |
243 if ((USBx->GCCFG) & USB_OTG_GCCFG_SDET) | |
244 { | |
245 /* case Dedicated Charging Port */ | |
246 HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DEDICATED_CHARGING_PORT); | |
247 } | |
248 else | |
249 { | |
250 /* case Charging Downstream Port */ | |
251 HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_CHARGING_DOWNSTREAM_PORT); | |
252 } | |
253 } | |
254 /* Battery Charging capability discovery finished */ | |
255 HAL_PCDEx_BCD_Callback(hpcd, PCD_BCD_DISCOVERY_COMPLETED); | |
256 } | |
257 } | |
258 | |
259 /** | |
260 * @brief HAL_PCDEx_ActivateBCD : active BatteryCharging feature | |
261 * @param hpcd PCD handle | |
262 * @retval HAL status | |
263 */ | |
264 HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd) | |
265 { | |
266 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; | |
267 | |
268 hpcd->battery_charging_active = ENABLE; | |
269 USBx->GCCFG |= (USB_OTG_GCCFG_BCDEN); | |
270 | |
271 return HAL_OK; | |
272 } | |
273 | |
274 /** | |
275 * @brief HAL_PCDEx_DeActivateBCD : de-active BatteryCharging feature | |
276 * @param hpcd PCD handle | |
277 * @retval HAL status | |
278 */ | |
279 HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd) | |
280 { | |
281 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; | |
282 hpcd->battery_charging_active = DISABLE; | |
283 USBx->GCCFG &= ~(USB_OTG_GCCFG_BCDEN); | |
284 return HAL_OK; | |
285 } | |
286 | |
287 /** | |
288 * @brief HAL_PCDEx_BatteryCharging_Callback : Send BatteryCharging message to user layer | |
289 * @param hpcd PCD handle | |
290 * @param msg LPM message | |
291 * @retval HAL status | |
292 */ | |
293 __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg) | |
294 { | |
295 /* Prevent unused argument(s) compilation warning */ | |
296 UNUSED(hpcd); | |
297 UNUSED(msg); | |
298 } | |
299 | |
300 #endif /* STM32F412Zx || STM32F412Rx || STM32F412Vx || STM32F412Cx || STM32F413xx || STM32F423xx */ | |
301 | |
302 /** | |
303 * @} | |
304 */ | |
305 | |
306 /** | |
307 * @} | |
308 */ | |
309 | |
310 #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || | |
311 STM32F401xC || STM32F401xE || STM32F411xE || STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Rx || | |
312 STM32F412Vx || STM32F412Cx || STM32F413xx || STM32F423xx */ | |
313 #endif /* HAL_PCD_MODULE_ENABLED */ | |
314 /** | |
315 * @} | |
316 */ | |
317 | |
318 /** | |
319 * @} | |
320 */ | |
321 | |
322 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |