38
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * @file stm32f4xx_hal_pcd.h
|
|
4 * @author MCD Application Team
|
|
5 * @version V1.2.0
|
|
6 * @date 26-December-2014
|
|
7 * @brief Header file of PCD HAL module.
|
|
8 ******************************************************************************
|
|
9 * @attention
|
|
10 *
|
|
11 * <h2><center>© 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_HAL_PCD_H
|
|
40 #define __STM32F4xx_HAL_PCD_H
|
|
41
|
|
42 #ifdef __cplusplus
|
|
43 extern "C" {
|
|
44 #endif
|
|
45
|
|
46 /* Includes ------------------------------------------------------------------*/
|
|
47 #include "stm32f4xx_ll_usb.h"
|
|
48
|
|
49 /** @addtogroup STM32F4xx_HAL_Driver
|
|
50 * @{
|
|
51 */
|
|
52
|
|
53 /** @addtogroup PCD
|
|
54 * @{
|
|
55 */
|
|
56
|
|
57 /* Exported types ------------------------------------------------------------*/
|
|
58 /** @defgroup PCD_Exported_Types PCD Exported Types
|
|
59 * @{
|
|
60 */
|
|
61
|
|
62 /**
|
|
63 * @brief PCD State structure definition
|
|
64 */
|
|
65 typedef enum
|
|
66 {
|
|
67 HAL_PCD_STATE_RESET = 0x00,
|
|
68 HAL_PCD_STATE_READY = 0x01,
|
|
69 HAL_PCD_STATE_ERROR = 0x02,
|
|
70 HAL_PCD_STATE_BUSY = 0x03,
|
|
71 HAL_PCD_STATE_TIMEOUT = 0x04
|
|
72 } PCD_StateTypeDef;
|
|
73
|
|
74
|
|
75 typedef USB_OTG_GlobalTypeDef PCD_TypeDef;
|
|
76 typedef USB_OTG_CfgTypeDef PCD_InitTypeDef;
|
|
77 typedef USB_OTG_EPTypeDef PCD_EPTypeDef ;
|
|
78
|
|
79 /**
|
|
80 * @brief PCD Handle Structure definition
|
|
81 */
|
|
82 typedef struct
|
|
83 {
|
|
84 PCD_TypeDef *Instance; /*!< Register base address */
|
|
85 PCD_InitTypeDef Init; /*!< PCD required parameters */
|
|
86 PCD_EPTypeDef IN_ep[15]; /*!< IN endpoint parameters */
|
|
87 PCD_EPTypeDef OUT_ep[15]; /*!< OUT endpoint parameters */
|
|
88 HAL_LockTypeDef Lock; /*!< PCD peripheral status */
|
|
89 __IO PCD_StateTypeDef State; /*!< PCD communication state */
|
|
90 uint32_t Setup[12]; /*!< Setup packet buffer */
|
|
91 void *pData; /*!< Pointer to upper stack Handler */
|
|
92
|
|
93 } PCD_HandleTypeDef;
|
|
94
|
|
95 /**
|
|
96 * @}
|
|
97 */
|
|
98
|
|
99 /* Include PCD HAL Extension module */
|
|
100 #include "stm32f4xx_hal_pcd_ex.h"
|
|
101
|
|
102 /* Exported constants --------------------------------------------------------*/
|
|
103 /** @defgroup PCD_Exported_Constants PCD Exported Constants
|
|
104 * @{
|
|
105 */
|
|
106
|
|
107 /** @defgroup PCD_Speed PCD Speed
|
|
108 * @{
|
|
109 */
|
|
110 #define PCD_SPEED_HIGH 0
|
|
111 #define PCD_SPEED_HIGH_IN_FULL 1
|
|
112 #define PCD_SPEED_FULL 2
|
|
113 /**
|
|
114 * @}
|
|
115 */
|
|
116
|
|
117 /** @defgroup PCD_PHY_Module PCD PHY Module
|
|
118 * @{
|
|
119 */
|
|
120 #define PCD_PHY_ULPI 1
|
|
121 #define PCD_PHY_EMBEDDED 2
|
|
122 /**
|
|
123 * @}
|
|
124 */
|
|
125
|
|
126 /**
|
|
127 * @}
|
|
128 */
|
|
129
|
|
130 /* Exported macros -----------------------------------------------------------*/
|
|
131 /** @defgroup PCD_Exported_Macros PCD Exported Macros
|
|
132 * @brief macros to handle interrupts and specific clock configurations
|
|
133 * @{
|
|
134 */
|
|
135 #define __HAL_PCD_ENABLE(__HANDLE__) USB_EnableGlobalInt ((__HANDLE__)->Instance)
|
|
136 #define __HAL_PCD_DISABLE(__HANDLE__) USB_DisableGlobalInt ((__HANDLE__)->Instance)
|
|
137
|
|
138 #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__))
|
|
139 #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->GINTSTS) = (__INTERRUPT__))
|
|
140 #define __HAL_PCD_IS_INVALID_INTERRUPT(__HANDLE__) (USB_ReadInterrupts((__HANDLE__)->Instance) == 0)
|
|
141
|
|
142
|
|
143 #define __HAL_PCD_UNGATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) &= \
|
|
144 ~(USB_OTG_PCGCCTL_STOPCLK)
|
|
145
|
|
146 #define __HAL_PCD_GATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) |= USB_OTG_PCGCCTL_STOPCLK
|
|
147
|
|
148 #define __HAL_PCD_IS_PHY_SUSPENDED(__HANDLE__) ((*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE))&0x10)
|
|
149
|
|
150 #define USB_OTG_FS_WAKEUP_EXTI_RISING_EDGE ((uint32_t)0x08)
|
|
151 #define USB_OTG_FS_WAKEUP_EXTI_FALLING_EDGE ((uint32_t)0x0C)
|
|
152 #define USB_OTG_FS_WAKEUP_EXTI_RISING_FALLING_EDGE ((uint32_t)0x10)
|
|
153
|
|
154 #define USB_OTG_HS_WAKEUP_EXTI_RISING_EDGE ((uint32_t)0x08)
|
|
155 #define USB_OTG_HS_WAKEUP_EXTI_FALLING_EDGE ((uint32_t)0x0C)
|
|
156 #define USB_OTG_HS_WAKEUP_EXTI_RISING_FALLING_EDGE ((uint32_t)0x10)
|
|
157
|
|
158 #define USB_OTG_HS_WAKEUP_EXTI_LINE ((uint32_t)0x00100000) /*!< External interrupt line 20 Connected to the USB HS EXTI Line */
|
|
159 #define USB_OTG_FS_WAKEUP_EXTI_LINE ((uint32_t)0x00040000) /*!< External interrupt line 18 Connected to the USB FS EXTI Line */
|
|
160
|
|
161 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= (USB_OTG_HS_WAKEUP_EXTI_LINE)
|
|
162 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE)
|
|
163 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_HS_WAKEUP_EXTI_LINE)
|
|
164 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = (USB_OTG_HS_WAKEUP_EXTI_LINE)
|
|
165
|
|
166 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_EDGE() EXTI->FTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE);\
|
|
167 EXTI->RTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE
|
|
168
|
|
169 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_FALLING_EDGE() EXTI->FTSR |= (USB_OTG_HS_WAKEUP_EXTI_LINE);\
|
|
170 EXTI->RTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE)
|
|
171
|
|
172 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_FALLING_EDGE() EXTI->RTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE);\
|
|
173 EXTI->FTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE;)\
|
|
174 EXTI->RTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE;\
|
|
175 EXTI->FTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE
|
|
176
|
|
177 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_GENERATE_SWIT() (EXTI->SWIER |= USB_OTG_FS_WAKEUP_EXTI_LINE)
|
|
178
|
|
179 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= USB_OTG_FS_WAKEUP_EXTI_LINE
|
|
180 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE)
|
|
181 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_FS_WAKEUP_EXTI_LINE)
|
|
182 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = USB_OTG_FS_WAKEUP_EXTI_LINE
|
|
183
|
|
184 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE() EXTI->FTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE);\
|
|
185 EXTI->RTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE
|
|
186
|
|
187
|
|
188 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_FALLING_EDGE() EXTI->FTSR |= (USB_OTG_FS_WAKEUP_EXTI_LINE);\
|
|
189 EXTI->RTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE)
|
|
190
|
|
191 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_FALLING_EDGE() EXTI->RTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE);\
|
|
192 EXTI->FTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE);\
|
|
193 EXTI->RTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE;\
|
|
194 EXTI->FTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE
|
|
195
|
|
196 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_GENERATE_SWIT() (EXTI->SWIER |= USB_OTG_FS_WAKEUP_EXTI_LINE)
|
|
197
|
|
198 /* Exported functions --------------------------------------------------------*/
|
|
199 /** @addtogroup PCD_Exported_Functions PCD Exported Functions
|
|
200 * @{
|
|
201 */
|
|
202
|
|
203 /* Initialization/de-initialization functions ********************************/
|
|
204 /** @addtogroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
|
|
205 * @{
|
|
206 */
|
|
207 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd);
|
|
208 HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd);
|
|
209 void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
|
|
210 void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
|
|
211 /**
|
|
212 * @}
|
|
213 */
|
|
214
|
|
215 /* I/O operation functions ***************************************************/
|
|
216 /* Non-Blocking mode: Interrupt */
|
|
217 /** @addtogroup PCD_Exported_Functions_Group2 IO operation functions
|
|
218 * @{
|
|
219 */
|
|
220 /* Non-Blocking mode: Interrupt */
|
|
221 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd);
|
|
222 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd);
|
|
223 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
|
|
224
|
|
225 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
|
|
226 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
|
|
227 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
|
|
228 void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
|
|
229 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
|
|
230 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
|
|
231 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
|
|
232 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
|
|
233 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
|
|
234 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
|
|
235 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
|
|
236 /**
|
|
237 * @}
|
|
238 */
|
|
239
|
|
240 /* Peripheral Control functions **********************************************/
|
|
241 /** @addtogroup PCD_Exported_Functions_Group3 Peripheral Control functions
|
|
242 * @{
|
|
243 */
|
|
244 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd);
|
|
245 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd);
|
|
246 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address);
|
|
247 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type);
|
|
248 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
|
|
249 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
|
|
250 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
|
|
251 uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
|
|
252 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
|
|
253 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
|
|
254 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
|
|
255 HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
|
|
256 HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
|
|
257 /**
|
|
258 * @}
|
|
259 */
|
|
260
|
|
261 /* Peripheral State functions ************************************************/
|
|
262 /** @addtogroup PCD_Exported_Functions_Group4 Peripheral State functions
|
|
263 * @{
|
|
264 */
|
|
265 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd);
|
|
266 /**
|
|
267 * @}
|
|
268 */
|
|
269
|
|
270 /**
|
|
271 * @}
|
|
272 */
|
|
273
|
|
274 /** @defgroup PCD_Instance_definition PCD Instance definition
|
|
275 * @{
|
|
276 */
|
|
277 #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
|
|
278 #define IS_PCD_ALL_INSTANCE(INSTANCE) (((INSTANCE) == USB_OTG_FS) || \
|
|
279 ((INSTANCE) == USB_OTG_HS))
|
|
280 #elif defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE)
|
|
281 #define IS_PCD_ALL_INSTANCE(INSTANCE) (((INSTANCE) == USB_OTG_FS))
|
|
282 #endif
|
|
283 /**
|
|
284 * @}
|
|
285 */
|
|
286
|
|
287 /**
|
|
288 * @}
|
|
289 */
|
|
290
|
|
291 /**
|
|
292 * @}
|
|
293 */
|
|
294
|
|
295 /**
|
|
296 * @}
|
|
297 */
|
|
298
|
|
299 #ifdef __cplusplus
|
|
300 }
|
|
301 #endif
|
|
302
|
|
303
|
|
304 #endif /* __STM32F4xx_HAL_PCD_H */
|
|
305
|
|
306 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|