Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 9 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /** |
1 | /** |
2 | ****************************************************************************** |
2 | ****************************************************************************** |
3 | * @file stm32f1xx_hal_pcd.c |
3 | * @file stm32f1xx_hal_pcd.c |
4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
5 | * @brief PCD HAL module driver. |
5 | * @brief PCD HAL module driver. |
6 | * This file provides firmware functions to manage the following |
6 | * This file provides firmware functions to manage the following |
7 | * functionalities of the USB Peripheral Controller: |
7 | * functionalities of the USB Peripheral Controller: |
8 | * + Initialization and de-initialization functions |
8 | * + Initialization and de-initialization functions |
9 | * + IO operation functions |
9 | * + IO operation functions |
10 | * + Peripheral Control functions |
10 | * + Peripheral Control functions |
11 | * + Peripheral State functions |
11 | * + Peripheral State functions |
12 | * |
12 | * |
13 | @verbatim |
13 | @verbatim |
14 | ============================================================================== |
14 | ============================================================================== |
15 | ##### How to use this driver ##### |
15 | ##### How to use this driver ##### |
Line 20... | Line 20... | ||
20 | (#) Declare a PCD_HandleTypeDef handle structure, for example: |
20 | (#) Declare a PCD_HandleTypeDef handle structure, for example: |
21 | PCD_HandleTypeDef hpcd; |
21 | PCD_HandleTypeDef hpcd; |
22 | 22 | ||
23 | (#) Fill parameters of Init structure in HCD handle |
23 | (#) Fill parameters of Init structure in HCD handle |
24 | 24 | ||
25 | (#) Call HAL_PCD_Init() API to initialize the HCD peripheral (Core, Device core, ...) |
25 | (#) Call HAL_PCD_Init() API to initialize the PCD peripheral (Core, Device core, ...) |
26 | 26 | ||
27 | (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API: |
27 | (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API: |
28 | (##) Enable the PCD/USB Low Level interface clock using the following macro |
28 | (##) Enable the PCD/USB Low Level interface clock using |
29 | (+++) __HAL_RCC_USB_CLK_ENABLE(); For USB Device FS peripheral available |
29 | (+++) __HAL_RCC_USB_CLK_ENABLE(); For USB Device only FS peripheral |
30 | on STM32F102xx and STM32F103xx devices |
- | |
31 | (+++) __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); For USB OTG FS peripheral available |
- | |
32 | on STM32F105xx and STM32F107xx devices |
- | |
33 | 30 | ||
34 | (##) Initialize the related GPIO clocks |
31 | (##) Initialize the related GPIO clocks |
35 | (##) Configure PCD pin-out |
32 | (##) Configure PCD pin-out |
36 | (##) Configure PCD NVIC interrupt |
33 | (##) Configure PCD NVIC interrupt |
37 | 34 | ||
38 | (#)Associate the Upper USB device stack to the HAL PCD Driver: |
35 | (#)Associate the Upper USB device stack to the HAL PCD Driver: |
39 | (##) hpcd.pData = pdev; |
36 | (##) hpcd.pData = pdev; |
40 | 37 | ||
41 | (#)Enable HCD transmission and reception: |
38 | (#)Enable PCD transmission and reception: |
42 | (##) HAL_PCD_Start(); |
39 | (##) HAL_PCD_Start(); |
43 | 40 | ||
44 | @endverbatim |
41 | @endverbatim |
45 | ****************************************************************************** |
42 | ****************************************************************************** |
46 | * @attention |
43 | * @attention |
47 | * |
44 | * |
48 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
45 | * <h2><center>© Copyright (c) 2016 STMicroelectronics. |
- | 46 | * All rights reserved.</center></h2> |
|
49 | * |
47 | * |
50 | * Redistribution and use in source and binary forms, with or without modification, |
48 | * This software component is licensed by ST under BSD 3-Clause license, |
51 | * are permitted provided that the following conditions are met: |
49 | * the "License"; You may not use this file except in compliance with the |
52 | * 1. Redistributions of source code must retain the above copyright notice, |
- | |
53 | * this list of conditions and the following disclaimer. |
- | |
54 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
- | |
55 | * this list of conditions and the following disclaimer in the documentation |
- | |
56 | * and/or other materials provided with the distribution. |
50 | * License. You may obtain a copy of the License at: |
57 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
- | |
58 | * may be used to endorse or promote products derived from this software |
51 | * opensource.org/licenses/BSD-3-Clause |
59 | * without specific prior written permission. |
- | |
60 | * |
- | |
61 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
- | |
62 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
- | |
63 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
- | |
64 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
- | |
65 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
- | |
66 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
- | |
67 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
- | |
68 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
- | |
69 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- | |
70 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- | |
71 | * |
52 | * |
72 | ****************************************************************************** |
53 | ****************************************************************************** |
73 | */ |
54 | */ |
74 | 55 | ||
75 | /* Includes ------------------------------------------------------------------*/ |
56 | /* Includes ------------------------------------------------------------------*/ |
Line 77... | Line 58... | ||
77 | 58 | ||
78 | /** @addtogroup STM32F1xx_HAL_Driver |
59 | /** @addtogroup STM32F1xx_HAL_Driver |
79 | * @{ |
60 | * @{ |
80 | */ |
61 | */ |
81 | 62 | ||
82 | - | ||
83 | - | ||
84 | #ifdef HAL_PCD_MODULE_ENABLED |
- | |
85 | - | ||
86 | #if defined(STM32F102x6) || defined(STM32F102xB) || \ |
- | |
87 | defined(STM32F103x6) || defined(STM32F103xB) || \ |
- | |
88 | defined(STM32F103xE) || defined(STM32F103xG) || \ |
- | |
89 | defined(STM32F105xC) || defined(STM32F107xC) |
- | |
90 | - | ||
91 | /** @defgroup PCD PCD |
63 | /** @defgroup PCD PCD |
92 | * @brief PCD HAL module driver |
64 | * @brief PCD HAL module driver |
93 | * @{ |
65 | * @{ |
94 | */ |
66 | */ |
95 | 67 | ||
- | 68 | #ifdef HAL_PCD_MODULE_ENABLED |
|
- | 69 | ||
- | 70 | #if defined (USB) || defined (USB_OTG_FS) |
|
- | 71 | ||
96 | /* Private types -------------------------------------------------------------*/ |
72 | /* Private types -------------------------------------------------------------*/ |
97 | /* Private variables ---------------------------------------------------------*/ |
73 | /* Private variables ---------------------------------------------------------*/ |
98 | /* Private constants ---------------------------------------------------------*/ |
74 | /* Private constants ---------------------------------------------------------*/ |
99 | /* Private macros ------------------------------------------------------------*/ |
75 | /* Private macros ------------------------------------------------------------*/ |
100 | /** @defgroup PCD_Private_Macros PCD Private Macros |
76 | /** @defgroup PCD_Private_Macros PCD Private Macros |
101 | * @{ |
77 | * @{ |
102 | */ |
78 | */ |
103 | #define PCD_MIN(a, b) (((a) < (b)) ? (a) : (b)) |
79 | #define PCD_MIN(a, b) (((a) < (b)) ? (a) : (b)) |
104 | #define PCD_MAX(a, b) (((a) > (b)) ? (a) : (b)) |
80 | #define PCD_MAX(a, b) (((a) > (b)) ? (a) : (b)) |
105 | /** |
81 | /** |
106 | * @} |
82 | * @} |
107 | */ |
83 | */ |
108 | 84 | ||
109 | /* Private functions ---------------------------------------------------------*/ |
85 | /* Private functions prototypes ----------------------------------------------*/ |
110 | /** @defgroup PCD_Private_Functions PCD Private Functions |
86 | /** @defgroup PCD_Private_Functions PCD Private Functions |
111 | * @{ |
87 | * @{ |
112 | */ |
88 | */ |
113 | #if defined (USB_OTG_FS) |
89 | #if defined (USB_OTG_FS) |
114 | static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum); |
90 | static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum); |
- | 91 | static HAL_StatusTypeDef PCD_EP_OutXfrComplete_int(PCD_HandleTypeDef *hpcd, uint32_t epnum); |
|
- | 92 | static HAL_StatusTypeDef PCD_EP_OutSetupPacket_int(PCD_HandleTypeDef *hpcd, uint32_t epnum); |
|
115 | #endif /* USB_OTG_FS */ |
93 | #endif /* defined (USB_OTG_FS) */ |
116 | 94 | ||
117 | #if defined (USB) |
95 | #if defined (USB) |
118 | static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd); |
96 | static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd); |
- | 97 | static HAL_StatusTypeDef HAL_PCD_EP_DB_Transmit(PCD_HandleTypeDef *hpcd, PCD_EPTypeDef *ep, uint16_t wEPVal); |
|
- | 98 | static uint16_t HAL_PCD_EP_DB_Receive(PCD_HandleTypeDef *hpcd, PCD_EPTypeDef *ep, uint16_t wEPVal); |
|
119 | #endif /* USB */ |
99 | #endif /* defined (USB) */ |
120 | /** |
100 | /** |
121 | * @} |
101 | * @} |
122 | */ |
102 | */ |
123 | 103 | ||
124 | /* Exported functions --------------------------------------------------------*/ |
104 | /* Exported functions --------------------------------------------------------*/ |
125 | /** @defgroup PCD_Exported_Functions PCD Exported Functions |
105 | /** @defgroup PCD_Exported_Functions PCD Exported Functions |
126 | * @{ |
106 | * @{ |
127 | */ |
107 | */ |
128 | 108 | ||
129 | /** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions |
109 | /** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions |
130 | * @brief Initialization and Configuration functions |
110 | * @brief Initialization and Configuration functions |
131 | * |
111 | * |
132 | @verbatim |
112 | @verbatim |
133 | =============================================================================== |
113 | =============================================================================== |
134 | ##### Initialization and de-initialization functions ##### |
114 | ##### Initialization and de-initialization functions ##### |
135 | =============================================================================== |
115 | =============================================================================== |
136 | [..] This section provides functions allowing to: |
116 | [..] This section provides functions allowing to: |
137 | |
117 | |
138 | @endverbatim |
118 | @endverbatim |
139 | * @{ |
119 | * @{ |
140 | */ |
120 | */ |
141 | 121 | ||
142 | /** |
122 | /** |
143 | * @brief Initializes the PCD according to the specified |
123 | * @brief Initializes the PCD according to the specified |
144 | * parameters in the PCD_InitTypeDef and create the associated handle. |
124 | * parameters in the PCD_InitTypeDef and initialize the associated handle. |
145 | * @param hpcd: PCD handle |
125 | * @param hpcd PCD handle |
146 | * @retval HAL status |
126 | * @retval HAL status |
147 | */ |
127 | */ |
148 | HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd) |
128 | HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd) |
149 | { |
129 | { |
- | 130 | #if defined (USB_OTG_FS) |
|
- | 131 | USB_OTG_GlobalTypeDef *USBx; |
|
- | 132 | #endif /* defined (USB_OTG_FS) */ |
|
150 | uint32_t index = 0U; |
133 | uint8_t i; |
151 | 134 | ||
152 | /* Check the PCD handle allocation */ |
135 | /* Check the PCD handle allocation */ |
153 | if(hpcd == NULL) |
136 | if (hpcd == NULL) |
154 | { |
137 | { |
155 | return HAL_ERROR; |
138 | return HAL_ERROR; |
156 | } |
139 | } |
157 | 140 | ||
158 | /* Check the parameters */ |
141 | /* Check the parameters */ |
159 | assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance)); |
142 | assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance)); |
160 | 143 | ||
- | 144 | #if defined (USB_OTG_FS) |
|
- | 145 | USBx = hpcd->Instance; |
|
- | 146 | #endif /* defined (USB_OTG_FS) */ |
|
- | 147 | ||
161 | if(hpcd->State == HAL_PCD_STATE_RESET) |
148 | if (hpcd->State == HAL_PCD_STATE_RESET) |
162 | { |
149 | { |
163 | /* Allocate lock resource and initialize it */ |
150 | /* Allocate lock resource and initialize it */ |
164 | hpcd->Lock = HAL_UNLOCKED; |
151 | hpcd->Lock = HAL_UNLOCKED; |
165 | 152 | ||
- | 153 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 154 | hpcd->SOFCallback = HAL_PCD_SOFCallback; |
|
- | 155 | hpcd->SetupStageCallback = HAL_PCD_SetupStageCallback; |
|
- | 156 | hpcd->ResetCallback = HAL_PCD_ResetCallback; |
|
- | 157 | hpcd->SuspendCallback = HAL_PCD_SuspendCallback; |
|
- | 158 | hpcd->ResumeCallback = HAL_PCD_ResumeCallback; |
|
- | 159 | hpcd->ConnectCallback = HAL_PCD_ConnectCallback; |
|
- | 160 | hpcd->DisconnectCallback = HAL_PCD_DisconnectCallback; |
|
- | 161 | hpcd->DataOutStageCallback = HAL_PCD_DataOutStageCallback; |
|
- | 162 | hpcd->DataInStageCallback = HAL_PCD_DataInStageCallback; |
|
- | 163 | hpcd->ISOOUTIncompleteCallback = HAL_PCD_ISOOUTIncompleteCallback; |
|
- | 164 | hpcd->ISOINIncompleteCallback = HAL_PCD_ISOINIncompleteCallback; |
|
- | 165 | ||
- | 166 | if (hpcd->MspInitCallback == NULL) |
|
- | 167 | { |
|
- | 168 | hpcd->MspInitCallback = HAL_PCD_MspInit; |
|
- | 169 | } |
|
- | 170 | ||
- | 171 | /* Init the low level hardware */ |
|
- | 172 | hpcd->MspInitCallback(hpcd); |
|
- | 173 | #else |
|
166 | /* Init the low level hardware : GPIO, CLOCK, NVIC... */ |
174 | /* Init the low level hardware : GPIO, CLOCK, NVIC... */ |
167 | HAL_PCD_MspInit(hpcd); |
175 | HAL_PCD_MspInit(hpcd); |
- | 176 | #endif /* (USE_HAL_PCD_REGISTER_CALLBACKS) */ |
|
168 | } |
177 | } |
169 | 178 | ||
170 | hpcd->State = HAL_PCD_STATE_BUSY; |
179 | hpcd->State = HAL_PCD_STATE_BUSY; |
- | 180 | ||
- | 181 | #if defined (USB_OTG_FS) |
|
- | 182 | /* Disable DMA mode for FS instance */ |
|
- | 183 | if ((USBx->CID & (0x1U << 8)) == 0U) |
|
- | 184 | { |
|
- | 185 | hpcd->Init.dma_enable = 0U; |
|
171 | 186 | } |
|
- | 187 | #endif /* defined (USB_OTG_FS) */ |
|
- | 188 | ||
172 | /* Disable the Interrupts */ |
189 | /* Disable the Interrupts */ |
173 | __HAL_PCD_DISABLE(hpcd); |
190 | __HAL_PCD_DISABLE(hpcd); |
174 | 191 | ||
175 | /*Init the Core (common init.) */ |
192 | /*Init the Core (common init.) */ |
176 | USB_CoreInit(hpcd->Instance, hpcd->Init); |
193 | if (USB_CoreInit(hpcd->Instance, hpcd->Init) != HAL_OK) |
- | 194 | { |
|
- | 195 | hpcd->State = HAL_PCD_STATE_ERROR; |
|
- | 196 | return HAL_ERROR; |
|
- | 197 | } |
|
177 | 198 | ||
178 | /* Force Device Mode*/ |
199 | /* Force Device Mode*/ |
179 | USB_SetCurrentMode(hpcd->Instance , USB_DEVICE_MODE); |
200 | (void)USB_SetCurrentMode(hpcd->Instance, USB_DEVICE_MODE); |
180 | 201 | ||
181 | /* Init endpoints structures */ |
202 | /* Init endpoints structures */ |
182 | for (index = 0U; index < 15U ; index++) |
203 | for (i = 0U; i < hpcd->Init.dev_endpoints; i++) |
183 | { |
204 | { |
184 | /* Init ep structure */ |
205 | /* Init ep structure */ |
185 | hpcd->IN_ep[index].is_in = 1U; |
206 | hpcd->IN_ep[i].is_in = 1U; |
186 | hpcd->IN_ep[index].num = index; |
207 | hpcd->IN_ep[i].num = i; |
187 | hpcd->IN_ep[index].tx_fifo_num = index; |
208 | hpcd->IN_ep[i].tx_fifo_num = i; |
188 | /* Control until ep is actvated */ |
209 | /* Control until ep is activated */ |
189 | hpcd->IN_ep[index].type = EP_TYPE_CTRL; |
210 | hpcd->IN_ep[i].type = EP_TYPE_CTRL; |
190 | hpcd->IN_ep[index].maxpacket = 0U; |
211 | hpcd->IN_ep[i].maxpacket = 0U; |
191 | hpcd->IN_ep[index].xfer_buff = 0U; |
212 | hpcd->IN_ep[i].xfer_buff = 0U; |
192 | hpcd->IN_ep[index].xfer_len = 0U; |
213 | hpcd->IN_ep[i].xfer_len = 0U; |
193 | } |
214 | } |
194 | 215 | ||
195 | for (index = 0U; index < 15U ; index++) |
216 | for (i = 0U; i < hpcd->Init.dev_endpoints; i++) |
196 | { |
217 | { |
197 | hpcd->OUT_ep[index].is_in = 0U; |
218 | hpcd->OUT_ep[i].is_in = 0U; |
198 | hpcd->OUT_ep[index].num = index; |
219 | hpcd->OUT_ep[i].num = i; |
199 | hpcd->IN_ep[index].tx_fifo_num = index; |
- | |
200 | /* Control until ep is activated */ |
220 | /* Control until ep is activated */ |
201 | hpcd->OUT_ep[index].type = EP_TYPE_CTRL; |
221 | hpcd->OUT_ep[i].type = EP_TYPE_CTRL; |
202 | hpcd->OUT_ep[index].maxpacket = 0U; |
222 | hpcd->OUT_ep[i].maxpacket = 0U; |
203 | hpcd->OUT_ep[index].xfer_buff = 0U; |
223 | hpcd->OUT_ep[i].xfer_buff = 0U; |
204 | hpcd->OUT_ep[index].xfer_len = 0U; |
224 | hpcd->OUT_ep[i].xfer_len = 0U; |
205 | } |
225 | } |
206 | 226 | ||
207 | /* Init Device */ |
227 | /* Init Device */ |
208 | USB_DevInit(hpcd->Instance, hpcd->Init); |
228 | if (USB_DevInit(hpcd->Instance, hpcd->Init) != HAL_OK) |
209 | 229 | { |
|
- | 230 | hpcd->State = HAL_PCD_STATE_ERROR; |
|
- | 231 | return HAL_ERROR; |
|
- | 232 | } |
|
- | 233 | ||
210 | hpcd->USB_Address = 0U; |
234 | hpcd->USB_Address = 0U; |
211 | hpcd->State= HAL_PCD_STATE_READY; |
235 | hpcd->State = HAL_PCD_STATE_READY; |
212 | - | ||
213 | USB_DevDisconnect (hpcd->Instance); |
236 | (void)USB_DevDisconnect(hpcd->Instance); |
- | 237 | ||
214 | return HAL_OK; |
238 | return HAL_OK; |
215 | } |
239 | } |
216 | 240 | ||
217 | /** |
241 | /** |
218 | * @brief DeInitializes the PCD peripheral |
242 | * @brief DeInitializes the PCD peripheral. |
219 | * @param hpcd: PCD handle |
243 | * @param hpcd PCD handle |
220 | * @retval HAL status |
244 | * @retval HAL status |
221 | */ |
245 | */ |
222 | HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd) |
246 | HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd) |
223 | { |
247 | { |
224 | /* Check the PCD handle allocation */ |
248 | /* Check the PCD handle allocation */ |
225 | if(hpcd == NULL) |
249 | if (hpcd == NULL) |
226 | { |
250 | { |
227 | return HAL_ERROR; |
251 | return HAL_ERROR; |
228 | } |
252 | } |
229 | 253 | ||
230 | hpcd->State = HAL_PCD_STATE_BUSY; |
254 | hpcd->State = HAL_PCD_STATE_BUSY; |
231 | 255 | ||
232 | /* Stop Device */ |
256 | /* Stop Device */ |
- | 257 | if (USB_StopDevice(hpcd->Instance) != HAL_OK) |
|
- | 258 | { |
|
233 | HAL_PCD_Stop(hpcd); |
259 | return HAL_ERROR; |
- | 260 | } |
|
- | 261 | ||
- | 262 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 263 | if (hpcd->MspDeInitCallback == NULL) |
|
- | 264 | { |
|
- | 265 | hpcd->MspDeInitCallback = HAL_PCD_MspDeInit; /* Legacy weak MspDeInit */ |
|
234 | 266 | } |
|
- | 267 | ||
235 | /* DeInit the low level hardware */ |
268 | /* DeInit the low level hardware */ |
- | 269 | hpcd->MspDeInitCallback(hpcd); |
|
- | 270 | #else |
|
- | 271 | /* DeInit the low level hardware: CLOCK, NVIC.*/ |
|
236 | HAL_PCD_MspDeInit(hpcd); |
272 | HAL_PCD_MspDeInit(hpcd); |
- | 273 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
237 | 274 | ||
238 | hpcd->State = HAL_PCD_STATE_RESET; |
275 | hpcd->State = HAL_PCD_STATE_RESET; |
239 | 276 | ||
240 | return HAL_OK; |
277 | return HAL_OK; |
241 | } |
278 | } |
242 | 279 | ||
243 | /** |
280 | /** |
244 | * @brief Initializes the PCD MSP. |
281 | * @brief Initializes the PCD MSP. |
245 | * @param hpcd: PCD handle |
282 | * @param hpcd PCD handle |
246 | * @retval None |
283 | * @retval None |
247 | */ |
284 | */ |
248 | __weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) |
285 | __weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) |
249 | { |
286 | { |
250 | /* Prevent unused argument(s) compilation warning */ |
287 | /* Prevent unused argument(s) compilation warning */ |
251 | UNUSED(hpcd); |
288 | UNUSED(hpcd); |
- | 289 | ||
252 | /* NOTE : This function should not be modified, when the callback is needed, |
290 | /* NOTE : This function should not be modified, when the callback is needed, |
253 | the HAL_PCD_MspInit could be implemented in the user file |
291 | the HAL_PCD_MspInit could be implemented in the user file |
254 | */ |
292 | */ |
255 | } |
293 | } |
256 | 294 | ||
257 | /** |
295 | /** |
258 | * @brief DeInitializes PCD MSP. |
296 | * @brief DeInitializes PCD MSP. |
259 | * @param hpcd: PCD handle |
297 | * @param hpcd PCD handle |
260 | * @retval None |
298 | * @retval None |
261 | */ |
299 | */ |
262 | __weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd) |
300 | __weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd) |
263 | { |
301 | { |
264 | /* Prevent unused argument(s) compilation warning */ |
302 | /* Prevent unused argument(s) compilation warning */ |
265 | UNUSED(hpcd); |
303 | UNUSED(hpcd); |
- | 304 | ||
266 | /* NOTE : This function should not be modified, when the callback is needed, |
305 | /* NOTE : This function should not be modified, when the callback is needed, |
267 | the HAL_PCD_MspDeInit could be implemented in the user file |
306 | the HAL_PCD_MspDeInit could be implemented in the user file |
268 | */ |
307 | */ |
269 | } |
308 | } |
270 | 309 | ||
- | 310 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 311 | /** |
|
- | 312 | * @brief Register a User USB PCD Callback |
|
- | 313 | * To be used instead of the weak predefined callback |
|
- | 314 | * @param hpcd USB PCD handle |
|
- | 315 | * @param CallbackID ID of the callback to be registered |
|
- | 316 | * This parameter can be one of the following values: |
|
- | 317 | * @arg @ref HAL_PCD_SOF_CB_ID USB PCD SOF callback ID |
|
- | 318 | * @arg @ref HAL_PCD_SETUPSTAGE_CB_ID USB PCD Setup callback ID |
|
- | 319 | * @arg @ref HAL_PCD_RESET_CB_ID USB PCD Reset callback ID |
|
- | 320 | * @arg @ref HAL_PCD_SUSPEND_CB_ID USB PCD Suspend callback ID |
|
- | 321 | * @arg @ref HAL_PCD_RESUME_CB_ID USB PCD Resume callback ID |
|
- | 322 | * @arg @ref HAL_PCD_CONNECT_CB_ID USB PCD Connect callback ID |
|
- | 323 | * @arg @ref HAL_PCD_DISCONNECT_CB_ID OTG PCD Disconnect callback ID |
|
- | 324 | * @arg @ref HAL_PCD_MSPINIT_CB_ID MspDeInit callback ID |
|
- | 325 | * @arg @ref HAL_PCD_MSPDEINIT_CB_ID MspDeInit callback ID |
|
- | 326 | * @param pCallback pointer to the Callback function |
|
- | 327 | * @retval HAL status |
|
- | 328 | */ |
|
- | 329 | HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd, |
|
- | 330 | HAL_PCD_CallbackIDTypeDef CallbackID, |
|
- | 331 | pPCD_CallbackTypeDef pCallback) |
|
- | 332 | { |
|
- | 333 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 334 | ||
- | 335 | if (pCallback == NULL) |
|
- | 336 | { |
|
- | 337 | /* Update the error code */ |
|
- | 338 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 339 | return HAL_ERROR; |
|
- | 340 | } |
|
- | 341 | /* Process locked */ |
|
- | 342 | __HAL_LOCK(hpcd); |
|
- | 343 | ||
- | 344 | if (hpcd->State == HAL_PCD_STATE_READY) |
|
- | 345 | { |
|
- | 346 | switch (CallbackID) |
|
- | 347 | { |
|
- | 348 | case HAL_PCD_SOF_CB_ID : |
|
- | 349 | hpcd->SOFCallback = pCallback; |
|
- | 350 | break; |
|
- | 351 | ||
- | 352 | case HAL_PCD_SETUPSTAGE_CB_ID : |
|
- | 353 | hpcd->SetupStageCallback = pCallback; |
|
- | 354 | break; |
|
- | 355 | ||
- | 356 | case HAL_PCD_RESET_CB_ID : |
|
- | 357 | hpcd->ResetCallback = pCallback; |
|
- | 358 | break; |
|
- | 359 | ||
- | 360 | case HAL_PCD_SUSPEND_CB_ID : |
|
- | 361 | hpcd->SuspendCallback = pCallback; |
|
- | 362 | break; |
|
- | 363 | ||
- | 364 | case HAL_PCD_RESUME_CB_ID : |
|
- | 365 | hpcd->ResumeCallback = pCallback; |
|
- | 366 | break; |
|
- | 367 | ||
- | 368 | case HAL_PCD_CONNECT_CB_ID : |
|
- | 369 | hpcd->ConnectCallback = pCallback; |
|
- | 370 | break; |
|
- | 371 | ||
- | 372 | case HAL_PCD_DISCONNECT_CB_ID : |
|
- | 373 | hpcd->DisconnectCallback = pCallback; |
|
- | 374 | break; |
|
- | 375 | ||
- | 376 | case HAL_PCD_MSPINIT_CB_ID : |
|
- | 377 | hpcd->MspInitCallback = pCallback; |
|
- | 378 | break; |
|
- | 379 | ||
- | 380 | case HAL_PCD_MSPDEINIT_CB_ID : |
|
- | 381 | hpcd->MspDeInitCallback = pCallback; |
|
- | 382 | break; |
|
- | 383 | ||
- | 384 | default : |
|
- | 385 | /* Update the error code */ |
|
- | 386 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 387 | /* Return error status */ |
|
- | 388 | status = HAL_ERROR; |
|
- | 389 | break; |
|
- | 390 | } |
|
- | 391 | } |
|
- | 392 | else if (hpcd->State == HAL_PCD_STATE_RESET) |
|
- | 393 | { |
|
- | 394 | switch (CallbackID) |
|
- | 395 | { |
|
- | 396 | case HAL_PCD_MSPINIT_CB_ID : |
|
- | 397 | hpcd->MspInitCallback = pCallback; |
|
- | 398 | break; |
|
- | 399 | ||
- | 400 | case HAL_PCD_MSPDEINIT_CB_ID : |
|
- | 401 | hpcd->MspDeInitCallback = pCallback; |
|
- | 402 | break; |
|
- | 403 | ||
- | 404 | default : |
|
- | 405 | /* Update the error code */ |
|
- | 406 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 407 | /* Return error status */ |
|
- | 408 | status = HAL_ERROR; |
|
- | 409 | break; |
|
- | 410 | } |
|
- | 411 | } |
|
- | 412 | else |
|
- | 413 | { |
|
- | 414 | /* Update the error code */ |
|
- | 415 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 416 | /* Return error status */ |
|
- | 417 | status = HAL_ERROR; |
|
- | 418 | } |
|
- | 419 | ||
- | 420 | /* Release Lock */ |
|
- | 421 | __HAL_UNLOCK(hpcd); |
|
- | 422 | return status; |
|
- | 423 | } |
|
- | 424 | ||
- | 425 | /** |
|
- | 426 | * @brief Unregister an USB PCD Callback |
|
- | 427 | * USB PCD callabck is redirected to the weak predefined callback |
|
- | 428 | * @param hpcd USB PCD handle |
|
- | 429 | * @param CallbackID ID of the callback to be unregistered |
|
- | 430 | * This parameter can be one of the following values: |
|
- | 431 | * @arg @ref HAL_PCD_SOF_CB_ID USB PCD SOF callback ID |
|
- | 432 | * @arg @ref HAL_PCD_SETUPSTAGE_CB_ID USB PCD Setup callback ID |
|
- | 433 | * @arg @ref HAL_PCD_RESET_CB_ID USB PCD Reset callback ID |
|
- | 434 | * @arg @ref HAL_PCD_SUSPEND_CB_ID USB PCD Suspend callback ID |
|
- | 435 | * @arg @ref HAL_PCD_RESUME_CB_ID USB PCD Resume callback ID |
|
- | 436 | * @arg @ref HAL_PCD_CONNECT_CB_ID USB PCD Connect callback ID |
|
- | 437 | * @arg @ref HAL_PCD_DISCONNECT_CB_ID OTG PCD Disconnect callback ID |
|
- | 438 | * @arg @ref HAL_PCD_MSPINIT_CB_ID MspDeInit callback ID |
|
- | 439 | * @arg @ref HAL_PCD_MSPDEINIT_CB_ID MspDeInit callback ID |
|
- | 440 | * @retval HAL status |
|
- | 441 | */ |
|
- | 442 | HAL_StatusTypeDef HAL_PCD_UnRegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID) |
|
- | 443 | { |
|
- | 444 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 445 | ||
- | 446 | /* Process locked */ |
|
- | 447 | __HAL_LOCK(hpcd); |
|
- | 448 | ||
- | 449 | /* Setup Legacy weak Callbacks */ |
|
- | 450 | if (hpcd->State == HAL_PCD_STATE_READY) |
|
- | 451 | { |
|
- | 452 | switch (CallbackID) |
|
- | 453 | { |
|
- | 454 | case HAL_PCD_SOF_CB_ID : |
|
- | 455 | hpcd->SOFCallback = HAL_PCD_SOFCallback; |
|
- | 456 | break; |
|
- | 457 | ||
- | 458 | case HAL_PCD_SETUPSTAGE_CB_ID : |
|
- | 459 | hpcd->SetupStageCallback = HAL_PCD_SetupStageCallback; |
|
- | 460 | break; |
|
- | 461 | ||
- | 462 | case HAL_PCD_RESET_CB_ID : |
|
- | 463 | hpcd->ResetCallback = HAL_PCD_ResetCallback; |
|
- | 464 | break; |
|
- | 465 | ||
- | 466 | case HAL_PCD_SUSPEND_CB_ID : |
|
- | 467 | hpcd->SuspendCallback = HAL_PCD_SuspendCallback; |
|
- | 468 | break; |
|
- | 469 | ||
- | 470 | case HAL_PCD_RESUME_CB_ID : |
|
- | 471 | hpcd->ResumeCallback = HAL_PCD_ResumeCallback; |
|
- | 472 | break; |
|
- | 473 | ||
- | 474 | case HAL_PCD_CONNECT_CB_ID : |
|
- | 475 | hpcd->ConnectCallback = HAL_PCD_ConnectCallback; |
|
- | 476 | break; |
|
- | 477 | ||
- | 478 | case HAL_PCD_DISCONNECT_CB_ID : |
|
- | 479 | hpcd->DisconnectCallback = HAL_PCD_DisconnectCallback; |
|
- | 480 | break; |
|
- | 481 | ||
- | 482 | case HAL_PCD_MSPINIT_CB_ID : |
|
- | 483 | hpcd->MspInitCallback = HAL_PCD_MspInit; |
|
- | 484 | break; |
|
- | 485 | ||
- | 486 | case HAL_PCD_MSPDEINIT_CB_ID : |
|
- | 487 | hpcd->MspDeInitCallback = HAL_PCD_MspDeInit; |
|
- | 488 | break; |
|
- | 489 | ||
- | 490 | default : |
|
- | 491 | /* Update the error code */ |
|
- | 492 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 493 | ||
- | 494 | /* Return error status */ |
|
- | 495 | status = HAL_ERROR; |
|
- | 496 | break; |
|
- | 497 | } |
|
- | 498 | } |
|
- | 499 | else if (hpcd->State == HAL_PCD_STATE_RESET) |
|
- | 500 | { |
|
- | 501 | switch (CallbackID) |
|
- | 502 | { |
|
- | 503 | case HAL_PCD_MSPINIT_CB_ID : |
|
- | 504 | hpcd->MspInitCallback = HAL_PCD_MspInit; |
|
- | 505 | break; |
|
- | 506 | ||
- | 507 | case HAL_PCD_MSPDEINIT_CB_ID : |
|
- | 508 | hpcd->MspDeInitCallback = HAL_PCD_MspDeInit; |
|
- | 509 | break; |
|
- | 510 | ||
- | 511 | default : |
|
- | 512 | /* Update the error code */ |
|
- | 513 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 514 | ||
- | 515 | /* Return error status */ |
|
- | 516 | status = HAL_ERROR; |
|
- | 517 | break; |
|
- | 518 | } |
|
- | 519 | } |
|
- | 520 | else |
|
- | 521 | { |
|
- | 522 | /* Update the error code */ |
|
- | 523 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 524 | ||
- | 525 | /* Return error status */ |
|
- | 526 | status = HAL_ERROR; |
|
- | 527 | } |
|
- | 528 | ||
- | 529 | /* Release Lock */ |
|
- | 530 | __HAL_UNLOCK(hpcd); |
|
- | 531 | return status; |
|
- | 532 | } |
|
- | 533 | ||
- | 534 | /** |
|
- | 535 | * @brief Register USB PCD Data OUT Stage Callback |
|
- | 536 | * To be used instead of the weak HAL_PCD_DataOutStageCallback() predefined callback |
|
- | 537 | * @param hpcd PCD handle |
|
- | 538 | * @param pCallback pointer to the USB PCD Data OUT Stage Callback function |
|
- | 539 | * @retval HAL status |
|
- | 540 | */ |
|
- | 541 | HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd, |
|
- | 542 | pPCD_DataOutStageCallbackTypeDef pCallback) |
|
- | 543 | { |
|
- | 544 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 545 | ||
- | 546 | if (pCallback == NULL) |
|
- | 547 | { |
|
- | 548 | /* Update the error code */ |
|
- | 549 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 550 | ||
- | 551 | return HAL_ERROR; |
|
- | 552 | } |
|
- | 553 | ||
- | 554 | /* Process locked */ |
|
- | 555 | __HAL_LOCK(hpcd); |
|
- | 556 | ||
- | 557 | if (hpcd->State == HAL_PCD_STATE_READY) |
|
- | 558 | { |
|
- | 559 | hpcd->DataOutStageCallback = pCallback; |
|
- | 560 | } |
|
- | 561 | else |
|
- | 562 | { |
|
- | 563 | /* Update the error code */ |
|
- | 564 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 565 | ||
- | 566 | /* Return error status */ |
|
- | 567 | status = HAL_ERROR; |
|
- | 568 | } |
|
- | 569 | ||
- | 570 | /* Release Lock */ |
|
- | 571 | __HAL_UNLOCK(hpcd); |
|
- | 572 | ||
- | 573 | return status; |
|
- | 574 | } |
|
- | 575 | ||
- | 576 | /** |
|
- | 577 | * @brief Unregister the USB PCD Data OUT Stage Callback |
|
- | 578 | * USB PCD Data OUT Stage Callback is redirected to the weak HAL_PCD_DataOutStageCallback() predefined callback |
|
- | 579 | * @param hpcd PCD handle |
|
- | 580 | * @retval HAL status |
|
- | 581 | */ |
|
- | 582 | HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd) |
|
- | 583 | { |
|
- | 584 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 585 | ||
- | 586 | /* Process locked */ |
|
- | 587 | __HAL_LOCK(hpcd); |
|
- | 588 | ||
- | 589 | if (hpcd->State == HAL_PCD_STATE_READY) |
|
- | 590 | { |
|
- | 591 | hpcd->DataOutStageCallback = HAL_PCD_DataOutStageCallback; /* Legacy weak DataOutStageCallback */ |
|
- | 592 | } |
|
- | 593 | else |
|
- | 594 | { |
|
- | 595 | /* Update the error code */ |
|
- | 596 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 597 | ||
- | 598 | /* Return error status */ |
|
- | 599 | status = HAL_ERROR; |
|
- | 600 | } |
|
- | 601 | ||
- | 602 | /* Release Lock */ |
|
- | 603 | __HAL_UNLOCK(hpcd); |
|
- | 604 | ||
- | 605 | return status; |
|
- | 606 | } |
|
- | 607 | ||
- | 608 | /** |
|
- | 609 | * @brief Register USB PCD Data IN Stage Callback |
|
- | 610 | * To be used instead of the weak HAL_PCD_DataInStageCallback() predefined callback |
|
- | 611 | * @param hpcd PCD handle |
|
- | 612 | * @param pCallback pointer to the USB PCD Data IN Stage Callback function |
|
- | 613 | * @retval HAL status |
|
- | 614 | */ |
|
- | 615 | HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd, |
|
- | 616 | pPCD_DataInStageCallbackTypeDef pCallback) |
|
- | 617 | { |
|
- | 618 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 619 | ||
- | 620 | if (pCallback == NULL) |
|
- | 621 | { |
|
- | 622 | /* Update the error code */ |
|
- | 623 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 624 | ||
- | 625 | return HAL_ERROR; |
|
- | 626 | } |
|
- | 627 | ||
- | 628 | /* Process locked */ |
|
- | 629 | __HAL_LOCK(hpcd); |
|
- | 630 | ||
- | 631 | if (hpcd->State == HAL_PCD_STATE_READY) |
|
- | 632 | { |
|
- | 633 | hpcd->DataInStageCallback = pCallback; |
|
- | 634 | } |
|
- | 635 | else |
|
- | 636 | { |
|
- | 637 | /* Update the error code */ |
|
- | 638 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 639 | ||
- | 640 | /* Return error status */ |
|
- | 641 | status = HAL_ERROR; |
|
- | 642 | } |
|
- | 643 | ||
- | 644 | /* Release Lock */ |
|
- | 645 | __HAL_UNLOCK(hpcd); |
|
- | 646 | ||
- | 647 | return status; |
|
- | 648 | } |
|
- | 649 | ||
- | 650 | /** |
|
- | 651 | * @brief Unregister the USB PCD Data IN Stage Callback |
|
- | 652 | * USB PCD Data OUT Stage Callback is redirected to the weak HAL_PCD_DataInStageCallback() predefined callback |
|
- | 653 | * @param hpcd PCD handle |
|
- | 654 | * @retval HAL status |
|
- | 655 | */ |
|
- | 656 | HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd) |
|
- | 657 | { |
|
- | 658 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 659 | ||
- | 660 | /* Process locked */ |
|
- | 661 | __HAL_LOCK(hpcd); |
|
- | 662 | ||
- | 663 | if (hpcd->State == HAL_PCD_STATE_READY) |
|
- | 664 | { |
|
- | 665 | hpcd->DataInStageCallback = HAL_PCD_DataInStageCallback; /* Legacy weak DataInStageCallback */ |
|
- | 666 | } |
|
- | 667 | else |
|
- | 668 | { |
|
- | 669 | /* Update the error code */ |
|
- | 670 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 671 | ||
- | 672 | /* Return error status */ |
|
- | 673 | status = HAL_ERROR; |
|
- | 674 | } |
|
- | 675 | ||
- | 676 | /* Release Lock */ |
|
- | 677 | __HAL_UNLOCK(hpcd); |
|
- | 678 | ||
- | 679 | return status; |
|
- | 680 | } |
|
- | 681 | ||
- | 682 | /** |
|
- | 683 | * @brief Register USB PCD Iso OUT incomplete Callback |
|
- | 684 | * To be used instead of the weak HAL_PCD_ISOOUTIncompleteCallback() predefined callback |
|
- | 685 | * @param hpcd PCD handle |
|
- | 686 | * @param pCallback pointer to the USB PCD Iso OUT incomplete Callback function |
|
- | 687 | * @retval HAL status |
|
- | 688 | */ |
|
- | 689 | HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd, |
|
- | 690 | pPCD_IsoOutIncpltCallbackTypeDef pCallback) |
|
- | 691 | { |
|
- | 692 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 693 | ||
- | 694 | if (pCallback == NULL) |
|
- | 695 | { |
|
- | 696 | /* Update the error code */ |
|
- | 697 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 698 | ||
- | 699 | return HAL_ERROR; |
|
- | 700 | } |
|
- | 701 | ||
- | 702 | /* Process locked */ |
|
- | 703 | __HAL_LOCK(hpcd); |
|
- | 704 | ||
- | 705 | if (hpcd->State == HAL_PCD_STATE_READY) |
|
- | 706 | { |
|
- | 707 | hpcd->ISOOUTIncompleteCallback = pCallback; |
|
- | 708 | } |
|
- | 709 | else |
|
- | 710 | { |
|
- | 711 | /* Update the error code */ |
|
- | 712 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 713 | ||
- | 714 | /* Return error status */ |
|
- | 715 | status = HAL_ERROR; |
|
- | 716 | } |
|
- | 717 | ||
- | 718 | /* Release Lock */ |
|
- | 719 | __HAL_UNLOCK(hpcd); |
|
- | 720 | ||
- | 721 | return status; |
|
- | 722 | } |
|
- | 723 | ||
- | 724 | /** |
|
- | 725 | * @brief Unregister the USB PCD Iso OUT incomplete Callback |
|
- | 726 | * USB PCD Iso OUT incomplete Callback is redirected to the weak HAL_PCD_ISOOUTIncompleteCallback() predefined callback |
|
- | 727 | * @param hpcd PCD handle |
|
- | 728 | * @retval HAL status |
|
- | 729 | */ |
|
- | 730 | HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd) |
|
- | 731 | { |
|
- | 732 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 733 | ||
- | 734 | /* Process locked */ |
|
- | 735 | __HAL_LOCK(hpcd); |
|
- | 736 | ||
- | 737 | if (hpcd->State == HAL_PCD_STATE_READY) |
|
- | 738 | { |
|
- | 739 | hpcd->ISOOUTIncompleteCallback = HAL_PCD_ISOOUTIncompleteCallback; /* Legacy weak ISOOUTIncompleteCallback */ |
|
- | 740 | } |
|
- | 741 | else |
|
- | 742 | { |
|
- | 743 | /* Update the error code */ |
|
- | 744 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 745 | ||
- | 746 | /* Return error status */ |
|
- | 747 | status = HAL_ERROR; |
|
- | 748 | } |
|
- | 749 | ||
- | 750 | /* Release Lock */ |
|
- | 751 | __HAL_UNLOCK(hpcd); |
|
- | 752 | ||
- | 753 | return status; |
|
- | 754 | } |
|
- | 755 | ||
- | 756 | /** |
|
- | 757 | * @brief Register USB PCD Iso IN incomplete Callback |
|
- | 758 | * To be used instead of the weak HAL_PCD_ISOINIncompleteCallback() predefined callback |
|
- | 759 | * @param hpcd PCD handle |
|
- | 760 | * @param pCallback pointer to the USB PCD Iso IN incomplete Callback function |
|
- | 761 | * @retval HAL status |
|
- | 762 | */ |
|
- | 763 | HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd, |
|
- | 764 | pPCD_IsoInIncpltCallbackTypeDef pCallback) |
|
- | 765 | { |
|
- | 766 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 767 | ||
- | 768 | if (pCallback == NULL) |
|
- | 769 | { |
|
- | 770 | /* Update the error code */ |
|
- | 771 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 772 | ||
- | 773 | return HAL_ERROR; |
|
- | 774 | } |
|
- | 775 | ||
- | 776 | /* Process locked */ |
|
- | 777 | __HAL_LOCK(hpcd); |
|
- | 778 | ||
- | 779 | if (hpcd->State == HAL_PCD_STATE_READY) |
|
- | 780 | { |
|
- | 781 | hpcd->ISOINIncompleteCallback = pCallback; |
|
- | 782 | } |
|
- | 783 | else |
|
- | 784 | { |
|
- | 785 | /* Update the error code */ |
|
- | 786 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 787 | ||
- | 788 | /* Return error status */ |
|
- | 789 | status = HAL_ERROR; |
|
- | 790 | } |
|
- | 791 | ||
- | 792 | /* Release Lock */ |
|
- | 793 | __HAL_UNLOCK(hpcd); |
|
- | 794 | ||
- | 795 | return status; |
|
- | 796 | } |
|
- | 797 | ||
- | 798 | /** |
|
- | 799 | * @brief Unregister the USB PCD Iso IN incomplete Callback |
|
- | 800 | * USB PCD Iso IN incomplete Callback is redirected to the weak HAL_PCD_ISOINIncompleteCallback() predefined callback |
|
- | 801 | * @param hpcd PCD handle |
|
- | 802 | * @retval HAL status |
|
- | 803 | */ |
|
- | 804 | HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd) |
|
- | 805 | { |
|
- | 806 | HAL_StatusTypeDef status = HAL_OK; |
|
- | 807 | ||
- | 808 | /* Process locked */ |
|
- | 809 | __HAL_LOCK(hpcd); |
|
- | 810 | ||
- | 811 | if (hpcd->State == HAL_PCD_STATE_READY) |
|
- | 812 | { |
|
- | 813 | hpcd->ISOINIncompleteCallback = HAL_PCD_ISOINIncompleteCallback; /* Legacy weak ISOINIncompleteCallback */ |
|
- | 814 | } |
|
- | 815 | else |
|
- | 816 | { |
|
- | 817 | /* Update the error code */ |
|
- | 818 | hpcd->ErrorCode |= HAL_PCD_ERROR_INVALID_CALLBACK; |
|
- | 819 | ||
- | 820 | /* Return error status */ |
|
- | 821 | status = HAL_ERROR; |
|
- | 822 | } |
|
- | 823 | ||
- | 824 | /* Release Lock */ |
|
- | 825 | __HAL_UNLOCK(hpcd); |
|
- | 826 | ||
- | 827 | return status; |
|
- | 828 | } |
|
- | 829 | ||
- | 830 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 831 | ||
271 | /** |
832 | /** |
272 | * @} |
833 | * @} |
273 | */ |
834 | */ |
274 | 835 | ||
275 | /** @defgroup PCD_Exported_Functions_Group2 IO operation functions |
836 | /** @defgroup PCD_Exported_Functions_Group2 Input and Output operation functions |
276 | * @brief Data transfers functions |
837 | * @brief Data transfers functions |
277 | * |
838 | * |
278 | @verbatim |
839 | @verbatim |
279 | =============================================================================== |
840 | =============================================================================== |
280 | ##### IO operation functions ##### |
841 | ##### IO operation functions ##### |
281 | =============================================================================== |
842 | =============================================================================== |
282 | [..] |
843 | [..] |
283 | This subsection provides a set of functions allowing to manage the PCD data |
844 | This subsection provides a set of functions allowing to manage the PCD data |
284 | transfers. |
845 | transfers. |
285 | 846 | ||
286 | @endverbatim |
847 | @endverbatim |
287 | * @{ |
848 | * @{ |
288 | */ |
849 | */ |
289 | 850 | ||
290 | /** |
851 | /** |
291 | * @brief Start The USB Device. |
852 | * @brief Start the USB device |
292 | * @param hpcd: PCD handle |
853 | * @param hpcd PCD handle |
293 | * @retval HAL status |
854 | * @retval HAL status |
294 | */ |
855 | */ |
295 | HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd) |
856 | HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd) |
296 | { |
857 | { |
297 | __HAL_LOCK(hpcd); |
858 | __HAL_LOCK(hpcd); |
298 | HAL_PCDEx_SetConnectionState (hpcd, 1); |
- | |
299 | USB_DevConnect (hpcd->Instance); |
- | |
300 | __HAL_PCD_ENABLE(hpcd); |
859 | __HAL_PCD_ENABLE(hpcd); |
- | 860 | ||
- | 861 | #if defined (USB) |
|
- | 862 | HAL_PCDEx_SetConnectionState(hpcd, 1U); |
|
- | 863 | #endif /* defined (USB) */ |
|
- | 864 | ||
- | 865 | (void)USB_DevConnect(hpcd->Instance); |
|
301 | __HAL_UNLOCK(hpcd); |
866 | __HAL_UNLOCK(hpcd); |
- | 867 | ||
302 | return HAL_OK; |
868 | return HAL_OK; |
303 | } |
869 | } |
304 | 870 | ||
305 | /** |
871 | /** |
306 | * @brief Stop The USB Device. |
872 | * @brief Stop the USB device. |
307 | * @param hpcd: PCD handle |
873 | * @param hpcd PCD handle |
308 | * @retval HAL status |
874 | * @retval HAL status |
309 | */ |
875 | */ |
310 | HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd) |
876 | HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd) |
311 | { |
877 | { |
312 | __HAL_LOCK(hpcd); |
878 | __HAL_LOCK(hpcd); |
313 | __HAL_PCD_DISABLE(hpcd); |
879 | __HAL_PCD_DISABLE(hpcd); |
- | 880 | ||
- | 881 | #if defined (USB) |
|
314 | USB_StopDevice(hpcd->Instance); |
882 | HAL_PCDEx_SetConnectionState(hpcd, 0U); |
- | 883 | #endif /* defined (USB) */ |
|
- | 884 | ||
315 | USB_DevDisconnect (hpcd->Instance); |
885 | (void)USB_DevDisconnect(hpcd->Instance); |
- | 886 | ||
- | 887 | #if defined (USB_OTG_FS) |
|
- | 888 | (void)USB_FlushTxFifo(hpcd->Instance, 0x10U); |
|
- | 889 | #endif /* defined (USB_OTG_FS) */ |
|
- | 890 | ||
316 | __HAL_UNLOCK(hpcd); |
891 | __HAL_UNLOCK(hpcd); |
- | 892 | ||
317 | return HAL_OK; |
893 | return HAL_OK; |
318 | } |
894 | } |
319 | 895 | ||
320 | #if defined (USB_OTG_FS) |
896 | #if defined (USB_OTG_FS) |
321 | /** |
897 | /** |
322 | * @brief This function handles PCD interrupt request. |
898 | * @brief Handles PCD interrupt request. |
323 | * @param hpcd: PCD handle |
899 | * @param hpcd PCD handle |
324 | * @retval HAL status |
900 | * @retval HAL status |
325 | */ |
901 | */ |
326 | void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd) |
902 | void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd) |
327 | { |
903 | { |
328 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; |
904 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; |
- | 905 | uint32_t USBx_BASE = (uint32_t)USBx; |
|
329 | uint32_t index = 0U, ep_intr = 0U, epint = 0U, epnum = 0U; |
906 | uint32_t i, ep_intr, epint, epnum; |
330 | uint32_t fifoemptymsk = 0U, temp = 0U; |
907 | uint32_t fifoemptymsk, temp; |
331 | USB_OTG_EPTypeDef *ep = NULL; |
908 | USB_OTG_EPTypeDef *ep; |
332 | 909 | ||
333 | /* ensure that we are in device mode */ |
910 | /* ensure that we are in device mode */ |
334 | if (USB_GetMode(hpcd->Instance) == USB_OTG_MODE_DEVICE) |
911 | if (USB_GetMode(hpcd->Instance) == USB_OTG_MODE_DEVICE) |
335 | { |
912 | { |
336 | /* avoid spurious interrupt */ |
913 | /* avoid spurious interrupt */ |
337 | if(__HAL_PCD_IS_INVALID_INTERRUPT(hpcd)) |
914 | if (__HAL_PCD_IS_INVALID_INTERRUPT(hpcd)) |
338 | { |
915 | { |
339 | return; |
916 | return; |
340 | } |
917 | } |
341 | 918 | ||
342 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_MMIS)) |
919 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_MMIS)) |
343 | { |
920 | { |
344 | /* incorrect mode, acknowledge the interrupt */ |
921 | /* incorrect mode, acknowledge the interrupt */ |
345 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_MMIS); |
922 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_MMIS); |
346 | } |
923 | } |
- | 924 | ||
- | 925 | /* Handle RxQLevel Interrupt */ |
|
- | 926 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_RXFLVL)) |
|
347 | 927 | { |
|
- | 928 | USB_MASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL); |
|
- | 929 | ||
- | 930 | temp = USBx->GRXSTSP; |
|
- | 931 | ||
- | 932 | ep = &hpcd->OUT_ep[temp & USB_OTG_GRXSTSP_EPNUM]; |
|
- | 933 | ||
- | 934 | if (((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_DATA_UPDT) |
|
- | 935 | { |
|
- | 936 | if ((temp & USB_OTG_GRXSTSP_BCNT) != 0U) |
|
- | 937 | { |
|
- | 938 | (void)USB_ReadPacket(USBx, ep->xfer_buff, |
|
- | 939 | (uint16_t)((temp & USB_OTG_GRXSTSP_BCNT) >> 4)); |
|
- | 940 | ||
- | 941 | ep->xfer_buff += (temp & USB_OTG_GRXSTSP_BCNT) >> 4; |
|
- | 942 | ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4; |
|
- | 943 | } |
|
- | 944 | } |
|
- | 945 | else if (((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_SETUP_UPDT) |
|
- | 946 | { |
|
- | 947 | (void)USB_ReadPacket(USBx, (uint8_t *)hpcd->Setup, 8U); |
|
- | 948 | ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4; |
|
- | 949 | } |
|
- | 950 | else |
|
- | 951 | { |
|
- | 952 | /* ... */ |
|
- | 953 | } |
|
- | 954 | USB_UNMASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL); |
|
- | 955 | } |
|
- | 956 | ||
348 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OEPINT)) |
957 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OEPINT)) |
349 | { |
958 | { |
350 | epnum = 0U; |
959 | epnum = 0U; |
351 | 960 | ||
352 | /* Read in the device interrupt bits */ |
961 | /* Read in the device interrupt bits */ |
353 | ep_intr = USB_ReadDevAllOutEpInterrupt(hpcd->Instance); |
962 | ep_intr = USB_ReadDevAllOutEpInterrupt(hpcd->Instance); |
354 | 963 | ||
355 | while ( ep_intr ) |
964 | while (ep_intr != 0U) |
356 | { |
965 | { |
357 | if (ep_intr & 0x1U) |
966 | if ((ep_intr & 0x1U) != 0U) |
358 | { |
967 | { |
359 | epint = USB_ReadDevOutEPInterrupt(hpcd->Instance, epnum); |
968 | epint = USB_ReadDevOutEPInterrupt(hpcd->Instance, (uint8_t)epnum); |
360 | 969 | ||
361 | if(( epint & USB_OTG_DOEPINT_XFRC) == USB_OTG_DOEPINT_XFRC) |
970 | if ((epint & USB_OTG_DOEPINT_XFRC) == USB_OTG_DOEPINT_XFRC) |
362 | { |
971 | { |
363 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_XFRC); |
972 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_XFRC); |
364 | - | ||
365 | HAL_PCD_DataOutStageCallback(hpcd, epnum); |
973 | (void)PCD_EP_OutXfrComplete_int(hpcd, epnum); |
366 | } |
974 | } |
367 | 975 | ||
368 | if(( epint & USB_OTG_DOEPINT_STUP) == USB_OTG_DOEPINT_STUP) |
976 | if ((epint & USB_OTG_DOEPINT_STUP) == USB_OTG_DOEPINT_STUP) |
369 | { |
977 | { |
370 | /* Inform the upper layer that a setup packet is available */ |
- | |
371 | HAL_PCD_SetupStageCallback(hpcd); |
- | |
372 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_STUP); |
978 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_STUP); |
- | 979 | /* Class B setup phase done for previous decoded setup */ |
|
- | 980 | (void)PCD_EP_OutSetupPacket_int(hpcd, epnum); |
|
373 | } |
981 | } |
374 | 982 | ||
375 | if(( epint & USB_OTG_DOEPINT_OTEPDIS) == USB_OTG_DOEPINT_OTEPDIS) |
983 | if ((epint & USB_OTG_DOEPINT_OTEPDIS) == USB_OTG_DOEPINT_OTEPDIS) |
376 | { |
984 | { |
377 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPDIS); |
985 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPDIS); |
378 | } |
986 | } |
- | 987 | ||
- | 988 | /* Clear Status Phase Received interrupt */ |
|
- | 989 | if ((epint & USB_OTG_DOEPINT_OTEPSPR) == USB_OTG_DOEPINT_OTEPSPR) |
|
- | 990 | { |
|
- | 991 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPSPR); |
|
- | 992 | } |
|
- | 993 | ||
- | 994 | /* Clear OUT NAK interrupt */ |
|
- | 995 | if ((epint & USB_OTG_DOEPINT_NAK) == USB_OTG_DOEPINT_NAK) |
|
- | 996 | { |
|
- | 997 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_NAK); |
|
- | 998 | } |
|
379 | } |
999 | } |
380 | epnum++; |
1000 | epnum++; |
381 | ep_intr >>= 1U; |
1001 | ep_intr >>= 1U; |
382 | } |
1002 | } |
383 | } |
1003 | } |
384 | 1004 | ||
385 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IEPINT)) |
1005 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IEPINT)) |
386 | { |
1006 | { |
387 | /* Read in the device interrupt bits */ |
1007 | /* Read in the device interrupt bits */ |
388 | ep_intr = USB_ReadDevAllInEpInterrupt(hpcd->Instance); |
1008 | ep_intr = USB_ReadDevAllInEpInterrupt(hpcd->Instance); |
389 | 1009 | ||
390 | epnum = 0U; |
1010 | epnum = 0U; |
391 | 1011 | ||
392 | while ( ep_intr ) |
1012 | while (ep_intr != 0U) |
393 | { |
1013 | { |
394 | if (ep_intr & 0x1U) /* In ITR */ |
1014 | if ((ep_intr & 0x1U) != 0U) /* In ITR */ |
395 | { |
1015 | { |
396 | epint = USB_ReadDevInEPInterrupt(hpcd->Instance, epnum); |
1016 | epint = USB_ReadDevInEPInterrupt(hpcd->Instance, (uint8_t)epnum); |
397 | 1017 | ||
398 | if(( epint & USB_OTG_DIEPINT_XFRC) == USB_OTG_DIEPINT_XFRC) |
1018 | if ((epint & USB_OTG_DIEPINT_XFRC) == USB_OTG_DIEPINT_XFRC) |
399 | { |
1019 | { |
400 | fifoemptymsk = 0x1U << epnum; |
1020 | fifoemptymsk = (uint32_t)(0x1UL << (epnum & EP_ADDR_MSK)); |
401 | USBx_DEVICE->DIEPEMPMSK &= ~fifoemptymsk; |
1021 | USBx_DEVICE->DIEPEMPMSK &= ~fifoemptymsk; |
402 | 1022 | ||
403 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_XFRC); |
1023 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_XFRC); |
- | 1024 | ||
- | 1025 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1026 | hpcd->DataInStageCallback(hpcd, (uint8_t)epnum); |
|
404 | 1027 | #else |
|
405 | HAL_PCD_DataInStageCallback(hpcd, epnum); |
1028 | HAL_PCD_DataInStageCallback(hpcd, (uint8_t)epnum); |
- | 1029 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
406 | } |
1030 | } |
407 | if(( epint & USB_OTG_DIEPINT_TOC) == USB_OTG_DIEPINT_TOC) |
1031 | if ((epint & USB_OTG_DIEPINT_TOC) == USB_OTG_DIEPINT_TOC) |
408 | { |
1032 | { |
409 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_TOC); |
1033 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_TOC); |
410 | } |
1034 | } |
411 | if(( epint & USB_OTG_DIEPINT_ITTXFE) == USB_OTG_DIEPINT_ITTXFE) |
1035 | if ((epint & USB_OTG_DIEPINT_ITTXFE) == USB_OTG_DIEPINT_ITTXFE) |
412 | { |
1036 | { |
413 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_ITTXFE); |
1037 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_ITTXFE); |
414 | } |
1038 | } |
415 | if(( epint & USB_OTG_DIEPINT_INEPNE) == USB_OTG_DIEPINT_INEPNE) |
1039 | if ((epint & USB_OTG_DIEPINT_INEPNE) == USB_OTG_DIEPINT_INEPNE) |
416 | { |
1040 | { |
417 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_INEPNE); |
1041 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_INEPNE); |
418 | } |
1042 | } |
419 | if(( epint & USB_OTG_DIEPINT_EPDISD) == USB_OTG_DIEPINT_EPDISD) |
1043 | if ((epint & USB_OTG_DIEPINT_EPDISD) == USB_OTG_DIEPINT_EPDISD) |
420 | { |
1044 | { |
421 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_EPDISD); |
1045 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_EPDISD); |
422 | } |
1046 | } |
423 | if(( epint & USB_OTG_DIEPINT_TXFE) == USB_OTG_DIEPINT_TXFE) |
1047 | if ((epint & USB_OTG_DIEPINT_TXFE) == USB_OTG_DIEPINT_TXFE) |
424 | { |
1048 | { |
425 | PCD_WriteEmptyTxFifo(hpcd , epnum); |
1049 | (void)PCD_WriteEmptyTxFifo(hpcd, epnum); |
426 | } |
1050 | } |
427 | } |
1051 | } |
428 | epnum++; |
1052 | epnum++; |
429 | ep_intr >>= 1U; |
1053 | ep_intr >>= 1U; |
430 | } |
1054 | } |
431 | } |
1055 | } |
432 | 1056 | ||
433 | /* Handle Resume Interrupt */ |
1057 | /* Handle Resume Interrupt */ |
434 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT)) |
1058 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT)) |
435 | { |
1059 | { |
436 | /* Clear the Remote Wake-up signalling */ |
1060 | /* Clear the Remote Wake-up Signaling */ |
437 | USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG; |
1061 | USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG; |
- | 1062 | ||
- | 1063 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1064 | hpcd->ResumeCallback(hpcd); |
|
438 | 1065 | #else |
|
439 | HAL_PCD_ResumeCallback(hpcd); |
1066 | HAL_PCD_ResumeCallback(hpcd); |
- | 1067 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
440 | 1068 | ||
441 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT); |
1069 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT); |
442 | } |
1070 | } |
443 | 1071 | ||
444 | /* Handle Suspend Interrupt */ |
1072 | /* Handle Suspend Interrupt */ |
445 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP)) |
1073 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP)) |
446 | { |
1074 | { |
447 | if((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS) |
1075 | if ((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS) |
448 | { |
1076 | { |
- | 1077 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1078 | hpcd->SuspendCallback(hpcd); |
|
449 | 1079 | #else |
|
450 | HAL_PCD_SuspendCallback(hpcd); |
1080 | HAL_PCD_SuspendCallback(hpcd); |
- | 1081 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
451 | } |
1082 | } |
452 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP); |
1083 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP); |
453 | } |
1084 | } |
454 | - | ||
455 | /* Handle Reset Interrupt */ |
1085 | /* Handle Reset Interrupt */ |
456 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBRST)) |
1086 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBRST)) |
457 | { |
1087 | { |
458 | USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG; |
1088 | USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG; |
459 | USB_FlushTxFifo(hpcd->Instance , 0x10U); |
1089 | (void)USB_FlushTxFifo(hpcd->Instance, 0x10U); |
460 | 1090 | ||
461 | for (index = 0U; index < hpcd->Init.dev_endpoints ; index++) |
1091 | for (i = 0U; i < hpcd->Init.dev_endpoints; i++) |
462 | { |
1092 | { |
463 | USBx_INEP(index)->DIEPINT = 0xFFU; |
1093 | USBx_INEP(i)->DIEPINT = 0xFB7FU; |
- | 1094 | USBx_INEP(i)->DIEPCTL &= ~USB_OTG_DIEPCTL_STALL; |
|
- | 1095 | USBx_INEP(i)->DIEPCTL |= USB_OTG_DIEPCTL_SNAK; |
|
464 | USBx_OUTEP(index)->DOEPINT = 0xFFU; |
1096 | USBx_OUTEP(i)->DOEPINT = 0xFB7FU; |
- | 1097 | USBx_OUTEP(i)->DOEPCTL &= ~USB_OTG_DOEPCTL_STALL; |
|
- | 1098 | USBx_OUTEP(i)->DOEPCTL |= USB_OTG_DOEPCTL_SNAK; |
|
465 | } |
1099 | } |
466 | USBx_DEVICE->DAINT = 0xFFFFFFFFU; |
- | |
467 | USBx_DEVICE->DAINTMSK |= 0x10001U; |
1100 | USBx_DEVICE->DAINTMSK |= 0x10001U; |
- | 1101 | ||
- | 1102 | if (hpcd->Init.use_dedicated_ep1 != 0U) |
|
468 | 1103 | { |
|
- | 1104 | USBx_DEVICE->DOUTEP1MSK |= USB_OTG_DOEPMSK_STUPM | |
|
- | 1105 | USB_OTG_DOEPMSK_XFRCM | |
|
- | 1106 | USB_OTG_DOEPMSK_EPDM; |
|
- | 1107 | ||
- | 1108 | USBx_DEVICE->DINEP1MSK |= USB_OTG_DIEPMSK_TOM | |
|
- | 1109 | USB_OTG_DIEPMSK_XFRCM | |
|
- | 1110 | USB_OTG_DIEPMSK_EPDM; |
|
- | 1111 | } |
|
- | 1112 | else |
|
- | 1113 | { |
|
469 | USBx_DEVICE->DOEPMSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM); |
1114 | USBx_DEVICE->DOEPMSK |= USB_OTG_DOEPMSK_STUPM | |
- | 1115 | USB_OTG_DOEPMSK_XFRCM | |
|
- | 1116 | USB_OTG_DOEPMSK_EPDM | |
|
- | 1117 | USB_OTG_DOEPMSK_OTEPSPRM | |
|
- | 1118 | USB_OTG_DOEPMSK_NAKM; |
|
- | 1119 | ||
470 | USBx_DEVICE->DIEPMSK |= (USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM | USB_OTG_DIEPMSK_EPDM); |
1120 | USBx_DEVICE->DIEPMSK |= USB_OTG_DIEPMSK_TOM | |
- | 1121 | USB_OTG_DIEPMSK_XFRCM | |
|
- | 1122 | USB_OTG_DIEPMSK_EPDM; |
|
471 | 1123 | } |
|
- | 1124 | ||
472 | /* Set Default Address to 0 */ |
1125 | /* Set Default Address to 0 */ |
473 | USBx_DEVICE->DCFG &= ~USB_OTG_DCFG_DAD; |
1126 | USBx_DEVICE->DCFG &= ~USB_OTG_DCFG_DAD; |
474 | 1127 | ||
475 | /* setup EP0 to receive SETUP packets */ |
1128 | /* setup EP0 to receive SETUP packets */ |
476 | USB_EP0_OutStart(hpcd->Instance, (uint8_t *)hpcd->Setup); |
1129 | (void)USB_EP0_OutStart(hpcd->Instance, (uint8_t *)hpcd->Setup); |
477 | 1130 | ||
478 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBRST); |
1131 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBRST); |
479 | } |
1132 | } |
480 | 1133 | ||
481 | /* Handle Enumeration done Interrupt */ |
1134 | /* Handle Enumeration done Interrupt */ |
482 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE)) |
1135 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE)) |
483 | { |
1136 | { |
484 | USB_ActivateSetup(hpcd->Instance); |
1137 | (void)USB_ActivateSetup(hpcd->Instance); |
485 | hpcd->Instance->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT; |
1138 | hpcd->Init.speed = USB_GetDevSpeed(hpcd->Instance); |
486 | 1139 | ||
- | 1140 | /* Set USB Turnaround time */ |
|
- | 1141 | (void)USB_SetTurnaroundTime(hpcd->Instance, |
|
487 | hpcd->Init.speed = USB_OTG_SPEED_FULL; |
1142 | HAL_RCC_GetHCLKFreq(), |
488 | hpcd->Init.ep0_mps = USB_OTG_FS_MAX_PACKET_SIZE ; |
1143 | (uint8_t)hpcd->Init.speed); |
- | 1144 | ||
- | 1145 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
489 | hpcd->Instance->GUSBCFG |= (uint32_t)((USBD_FS_TRDT_VALUE << 10U) & USB_OTG_GUSBCFG_TRDT); |
1146 | hpcd->ResetCallback(hpcd); |
490 | 1147 | #else |
|
491 | HAL_PCD_ResetCallback(hpcd); |
1148 | HAL_PCD_ResetCallback(hpcd); |
- | 1149 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
492 | 1150 | ||
493 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE); |
1151 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE); |
494 | } |
1152 | } |
495 | 1153 | ||
496 | /* Handle RxQLevel Interrupt */ |
- | |
497 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_RXFLVL)) |
- | |
498 | { |
- | |
499 | USB_MASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL); |
- | |
500 | temp = USBx->GRXSTSP; |
- | |
501 | ep = &hpcd->OUT_ep[temp & USB_OTG_GRXSTSP_EPNUM]; |
- | |
502 | - | ||
503 | if(((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17U) == STS_DATA_UPDT) |
- | |
504 | { |
- | |
505 | if((temp & USB_OTG_GRXSTSP_BCNT) != 0U) |
- | |
506 | { |
- | |
507 | USB_ReadPacket(USBx, ep->xfer_buff, (temp & USB_OTG_GRXSTSP_BCNT) >> 4U); |
- | |
508 | ep->xfer_buff += (temp & USB_OTG_GRXSTSP_BCNT) >> 4U; |
- | |
509 | ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4U; |
- | |
510 | } |
- | |
511 | } |
- | |
512 | else if (((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17U) == STS_SETUP_UPDT) |
- | |
513 | { |
- | |
514 | USB_ReadPacket(USBx, (uint8_t *)hpcd->Setup, 8U); |
- | |
515 | ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4U; |
- | |
516 | } |
- | |
517 | USB_UNMASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL); |
- | |
518 | } |
- | |
519 | - | ||
520 | /* Handle SOF Interrupt */ |
1154 | /* Handle SOF Interrupt */ |
521 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SOF)) |
1155 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SOF)) |
522 | { |
1156 | { |
- | 1157 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1158 | hpcd->SOFCallback(hpcd); |
|
- | 1159 | #else |
|
523 | HAL_PCD_SOFCallback(hpcd); |
1160 | HAL_PCD_SOFCallback(hpcd); |
- | 1161 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 1162 | ||
524 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SOF); |
1163 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SOF); |
525 | } |
1164 | } |
526 | 1165 | ||
527 | /* Handle Incomplete ISO IN Interrupt */ |
1166 | /* Handle Incomplete ISO IN Interrupt */ |
528 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR)) |
1167 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR)) |
529 | { |
1168 | { |
- | 1169 | /* Keep application checking the corresponding Iso IN endpoint |
|
- | 1170 | causing the incomplete Interrupt */ |
|
- | 1171 | epnum = 0U; |
|
- | 1172 | ||
- | 1173 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1174 | hpcd->ISOINIncompleteCallback(hpcd, (uint8_t)epnum); |
|
- | 1175 | #else |
|
530 | HAL_PCD_ISOINIncompleteCallback(hpcd, epnum); |
1176 | HAL_PCD_ISOINIncompleteCallback(hpcd, (uint8_t)epnum); |
- | 1177 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 1178 | ||
531 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR); |
1179 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR); |
532 | } |
1180 | } |
533 | 1181 | ||
534 | /* Handle Incomplete ISO OUT Interrupt */ |
1182 | /* Handle Incomplete ISO OUT Interrupt */ |
535 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT)) |
1183 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT)) |
536 | { |
1184 | { |
- | 1185 | /* Keep application checking the corresponding Iso OUT endpoint |
|
- | 1186 | causing the incomplete Interrupt */ |
|
- | 1187 | epnum = 0U; |
|
- | 1188 | ||
- | 1189 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1190 | hpcd->ISOOUTIncompleteCallback(hpcd, (uint8_t)epnum); |
|
- | 1191 | #else |
|
537 | HAL_PCD_ISOOUTIncompleteCallback(hpcd, epnum); |
1192 | HAL_PCD_ISOOUTIncompleteCallback(hpcd, (uint8_t)epnum); |
- | 1193 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 1194 | ||
538 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT); |
1195 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT); |
539 | } |
1196 | } |
540 | 1197 | ||
541 | /* Handle Connection event Interrupt */ |
1198 | /* Handle Connection event Interrupt */ |
542 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT)) |
1199 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT)) |
543 | { |
1200 | { |
- | 1201 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1202 | hpcd->ConnectCallback(hpcd); |
|
- | 1203 | #else |
|
544 | HAL_PCD_ConnectCallback(hpcd); |
1204 | HAL_PCD_ConnectCallback(hpcd); |
- | 1205 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 1206 | ||
545 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT); |
1207 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT); |
546 | } |
1208 | } |
547 | 1209 | ||
548 | /* Handle Disconnection event Interrupt */ |
1210 | /* Handle Disconnection event Interrupt */ |
549 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OTGINT)) |
1211 | if (__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OTGINT)) |
550 | { |
1212 | { |
551 | temp = hpcd->Instance->GOTGINT; |
1213 | temp = hpcd->Instance->GOTGINT; |
552 | 1214 | ||
553 | if((temp & USB_OTG_GOTGINT_SEDET) == USB_OTG_GOTGINT_SEDET) |
1215 | if ((temp & USB_OTG_GOTGINT_SEDET) == USB_OTG_GOTGINT_SEDET) |
554 | { |
1216 | { |
- | 1217 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1218 | hpcd->DisconnectCallback(hpcd); |
|
- | 1219 | #else |
|
555 | HAL_PCD_DisconnectCallback(hpcd); |
1220 | HAL_PCD_DisconnectCallback(hpcd); |
- | 1221 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
556 | } |
1222 | } |
557 | hpcd->Instance->GOTGINT |= temp; |
1223 | hpcd->Instance->GOTGINT |= temp; |
558 | } |
1224 | } |
559 | } |
1225 | } |
560 | } |
1226 | } |
- | 1227 | ||
- | 1228 | ||
- | 1229 | /** |
|
- | 1230 | * @brief Handles PCD Wakeup interrupt request. |
|
- | 1231 | * @param hpcd PCD handle |
|
- | 1232 | * @retval HAL status |
|
- | 1233 | */ |
|
- | 1234 | void HAL_PCD_WKUP_IRQHandler(PCD_HandleTypeDef *hpcd) |
|
- | 1235 | { |
|
- | 1236 | /* Clear EXTI pending Bit */ |
|
- | 1237 | __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG(); |
|
- | 1238 | } |
|
561 | #endif /* USB_OTG_FS */ |
1239 | #endif /* defined (USB_OTG_FS) */ |
562 | 1240 | ||
563 | #if defined (USB) |
1241 | #if defined (USB) |
564 | /** |
1242 | /** |
565 | * @brief This function handles PCD interrupt request. |
1243 | * @brief This function handles PCD interrupt request. |
566 | * @param hpcd: PCD handle |
1244 | * @param hpcd PCD handle |
567 | * @retval HAL status |
1245 | * @retval HAL status |
568 | */ |
1246 | */ |
569 | void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd) |
1247 | void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd) |
570 | { |
1248 | { |
- | 1249 | uint16_t store_ep[8]; |
|
- | 1250 | uint8_t i; |
|
- | 1251 | ||
571 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_CTR)) |
1252 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_CTR)) |
572 | { |
1253 | { |
573 | /* servicing of the endpoint correct transfer interrupt */ |
1254 | /* servicing of the endpoint correct transfer interrupt */ |
574 | /* clear of the CTR flag into the sub */ |
1255 | /* clear of the CTR flag into the sub */ |
575 | PCD_EP_ISR_Handler(hpcd); |
1256 | (void)PCD_EP_ISR_Handler(hpcd); |
576 | } |
1257 | } |
577 | 1258 | ||
578 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_RESET)) |
1259 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_RESET)) |
579 | { |
1260 | { |
580 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_RESET); |
1261 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_RESET); |
- | 1262 | ||
- | 1263 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1264 | hpcd->ResetCallback(hpcd); |
|
- | 1265 | #else |
|
581 | HAL_PCD_ResetCallback(hpcd); |
1266 | HAL_PCD_ResetCallback(hpcd); |
- | 1267 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 1268 | ||
582 | HAL_PCD_SetAddress(hpcd, 0U); |
1269 | (void)HAL_PCD_SetAddress(hpcd, 0U); |
583 | } |
1270 | } |
584 | 1271 | ||
585 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_PMAOVR)) |
1272 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_PMAOVR)) |
586 | { |
1273 | { |
587 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_PMAOVR); |
1274 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_PMAOVR); |
588 | } |
1275 | } |
- | 1276 | ||
589 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_ERR)) |
1277 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_ERR)) |
590 | { |
1278 | { |
591 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ERR); |
1279 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ERR); |
592 | } |
1280 | } |
593 | 1281 | ||
594 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP)) |
1282 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_WKUP)) |
595 | { |
1283 | { |
596 | hpcd->Instance->CNTR &= ~(USB_CNTR_LP_MODE); |
1284 | hpcd->Instance->CNTR &= (uint16_t) ~(USB_CNTR_LP_MODE); |
597 | hpcd->Instance->CNTR &= ~(USB_CNTR_FSUSP); |
1285 | hpcd->Instance->CNTR &= (uint16_t) ~(USB_CNTR_FSUSP); |
- | 1286 | ||
- | 1287 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1288 | hpcd->ResumeCallback(hpcd); |
|
598 | 1289 | #else |
|
599 | HAL_PCD_ResumeCallback(hpcd); |
1290 | HAL_PCD_ResumeCallback(hpcd); |
- | 1291 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
600 | 1292 | ||
601 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_WKUP); |
1293 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_WKUP); |
602 | } |
1294 | } |
603 | 1295 | ||
604 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_SUSP)) |
1296 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_SUSP)) |
605 | { |
1297 | { |
- | 1298 | /* WA: To Clear Wakeup flag if raised with suspend signal */ |
|
- | 1299 | ||
606 | /* Force low-power mode in the macrocell */ |
1300 | /* Store Endpoint register */ |
- | 1301 | for (i = 0U; i < 8U; i++) |
|
- | 1302 | { |
|
- | 1303 | store_ep[i] = PCD_GET_ENDPOINT(hpcd->Instance, i); |
|
- | 1304 | } |
|
- | 1305 | ||
- | 1306 | /* FORCE RESET */ |
|
607 | hpcd->Instance->CNTR |= USB_CNTR_FSUSP; |
1307 | hpcd->Instance->CNTR |= (uint16_t)(USB_CNTR_FRES); |
- | 1308 | ||
- | 1309 | /* CLEAR RESET */ |
|
- | 1310 | hpcd->Instance->CNTR &= (uint16_t)(~USB_CNTR_FRES); |
|
- | 1311 | ||
- | 1312 | /* wait for reset flag in ISTR */ |
|
- | 1313 | while ((hpcd->Instance->ISTR & USB_ISTR_RESET) == 0U) |
|
- | 1314 | { |
|
608 | 1315 | } |
|
- | 1316 | ||
609 | /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */ |
1317 | /* Clear Reset Flag */ |
610 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SUSP); |
1318 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_RESET); |
611 | 1319 | ||
612 | hpcd->Instance->CNTR |= USB_CNTR_LP_MODE; |
1320 | /* Restore Registre */ |
613 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP) == 0U) |
1321 | for (i = 0U; i < 8U; i++) |
614 | { |
1322 | { |
615 | HAL_PCD_SuspendCallback(hpcd); |
1323 | PCD_SET_ENDPOINT(hpcd->Instance, i, store_ep[i]); |
616 | } |
1324 | } |
- | 1325 | ||
- | 1326 | /* Force low-power mode in the macrocell */ |
|
- | 1327 | hpcd->Instance->CNTR |= (uint16_t)USB_CNTR_FSUSP; |
|
- | 1328 | ||
- | 1329 | /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */ |
|
- | 1330 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SUSP); |
|
- | 1331 | ||
- | 1332 | hpcd->Instance->CNTR |= (uint16_t)USB_CNTR_LP_MODE; |
|
- | 1333 | ||
- | 1334 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1335 | hpcd->SuspendCallback(hpcd); |
|
- | 1336 | #else |
|
- | 1337 | HAL_PCD_SuspendCallback(hpcd); |
|
- | 1338 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
617 | } |
1339 | } |
618 | 1340 | ||
619 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_SOF)) |
1341 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_SOF)) |
620 | { |
1342 | { |
621 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SOF); |
1343 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SOF); |
- | 1344 | ||
- | 1345 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 1346 | hpcd->SOFCallback(hpcd); |
|
- | 1347 | #else |
|
622 | HAL_PCD_SOFCallback(hpcd); |
1348 | HAL_PCD_SOFCallback(hpcd); |
- | 1349 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
623 | } |
1350 | } |
624 | 1351 | ||
625 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_ESOF)) |
1352 | if (__HAL_PCD_GET_FLAG(hpcd, USB_ISTR_ESOF)) |
626 | { |
1353 | { |
627 | /* clear ESOF flag in ISTR */ |
1354 | /* clear ESOF flag in ISTR */ |
628 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ESOF); |
1355 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ESOF); |
629 | } |
1356 | } |
630 | } |
1357 | } |
- | 1358 | ||
- | 1359 | ||
- | 1360 | /** |
|
- | 1361 | * @brief Handles PCD Wakeup interrupt request. |
|
- | 1362 | * @param hpcd PCD handle |
|
- | 1363 | * @retval HAL status |
|
- | 1364 | */ |
|
- | 1365 | void HAL_PCD_WKUP_IRQHandler(PCD_HandleTypeDef *hpcd) |
|
- | 1366 | { |
|
- | 1367 | /* Clear EXTI pending Bit */ |
|
- | 1368 | __HAL_USB_WAKEUP_EXTI_CLEAR_FLAG(); |
|
- | 1369 | } |
|
631 | #endif /* USB */ |
1370 | #endif /* defined (USB) */ |
632 | 1371 | ||
633 | /** |
1372 | /** |
634 | * @brief Data out stage callbacks |
1373 | * @brief Data OUT stage callback. |
635 | * @param hpcd: PCD handle |
1374 | * @param hpcd PCD handle |
636 | * @param epnum: endpoint number |
1375 | * @param epnum endpoint number |
637 | * @retval None |
1376 | * @retval None |
638 | */ |
1377 | */ |
639 | __weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
1378 | __weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
640 | { |
1379 | { |
641 | /* Prevent unused argument(s) compilation warning */ |
1380 | /* Prevent unused argument(s) compilation warning */ |
642 | UNUSED(hpcd); |
1381 | UNUSED(hpcd); |
643 | UNUSED(epnum); |
1382 | UNUSED(epnum); |
- | 1383 | ||
644 | /* NOTE : This function should not be modified, when the callback is needed, |
1384 | /* NOTE : This function should not be modified, when the callback is needed, |
645 | the HAL_PCD_DataOutStageCallback could be implemented in the user file |
1385 | the HAL_PCD_DataOutStageCallback could be implemented in the user file |
646 | */ |
1386 | */ |
647 | } |
1387 | } |
648 | 1388 | ||
649 | /** |
1389 | /** |
650 | * @brief Data IN stage callbacks |
1390 | * @brief Data IN stage callback |
651 | * @param hpcd: PCD handle |
1391 | * @param hpcd PCD handle |
652 | * @param epnum: endpoint number |
1392 | * @param epnum endpoint number |
653 | * @retval None |
1393 | * @retval None |
654 | */ |
1394 | */ |
655 | __weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
1395 | __weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
656 | { |
1396 | { |
657 | /* Prevent unused argument(s) compilation warning */ |
1397 | /* Prevent unused argument(s) compilation warning */ |
658 | UNUSED(hpcd); |
1398 | UNUSED(hpcd); |
659 | UNUSED(epnum); |
1399 | UNUSED(epnum); |
- | 1400 | ||
660 | /* NOTE : This function should not be modified, when the callback is needed, |
1401 | /* NOTE : This function should not be modified, when the callback is needed, |
661 | the HAL_PCD_DataInStageCallback could be implemented in the user file |
1402 | the HAL_PCD_DataInStageCallback could be implemented in the user file |
662 | */ |
1403 | */ |
663 | } |
1404 | } |
664 | /** |
1405 | /** |
665 | * @brief Setup stage callback |
1406 | * @brief Setup stage callback |
666 | * @param hpcd: PCD handle |
1407 | * @param hpcd PCD handle |
667 | * @retval None |
1408 | * @retval None |
668 | */ |
1409 | */ |
669 | __weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) |
1410 | __weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) |
670 | { |
1411 | { |
671 | /* Prevent unused argument(s) compilation warning */ |
1412 | /* Prevent unused argument(s) compilation warning */ |
672 | UNUSED(hpcd); |
1413 | UNUSED(hpcd); |
- | 1414 | ||
673 | /* NOTE : This function should not be modified, when the callback is needed, |
1415 | /* NOTE : This function should not be modified, when the callback is needed, |
674 | the HAL_PCD_SetupStageCallback could be implemented in the user file |
1416 | the HAL_PCD_SetupStageCallback could be implemented in the user file |
675 | */ |
1417 | */ |
676 | } |
1418 | } |
677 | 1419 | ||
678 | /** |
1420 | /** |
679 | * @brief USB Start Of Frame callbacks |
1421 | * @brief USB Start Of Frame callback. |
680 | * @param hpcd: PCD handle |
1422 | * @param hpcd PCD handle |
681 | * @retval None |
1423 | * @retval None |
682 | */ |
1424 | */ |
683 | __weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) |
1425 | __weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) |
684 | { |
1426 | { |
685 | /* Prevent unused argument(s) compilation warning */ |
1427 | /* Prevent unused argument(s) compilation warning */ |
686 | UNUSED(hpcd); |
1428 | UNUSED(hpcd); |
- | 1429 | ||
687 | /* NOTE : This function should not be modified, when the callback is needed, |
1430 | /* NOTE : This function should not be modified, when the callback is needed, |
688 | the HAL_PCD_SOFCallback could be implemented in the user file |
1431 | the HAL_PCD_SOFCallback could be implemented in the user file |
689 | */ |
1432 | */ |
690 | } |
1433 | } |
691 | 1434 | ||
692 | /** |
1435 | /** |
693 | * @brief USB Reset callbacks |
1436 | * @brief USB Reset callback. |
694 | * @param hpcd: PCD handle |
1437 | * @param hpcd PCD handle |
695 | * @retval None |
1438 | * @retval None |
696 | */ |
1439 | */ |
697 | __weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
1440 | __weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
698 | { |
1441 | { |
699 | /* Prevent unused argument(s) compilation warning */ |
1442 | /* Prevent unused argument(s) compilation warning */ |
700 | UNUSED(hpcd); |
1443 | UNUSED(hpcd); |
- | 1444 | ||
701 | /* NOTE : This function should not be modified, when the callback is needed, |
1445 | /* NOTE : This function should not be modified, when the callback is needed, |
702 | the HAL_PCD_ResetCallback could be implemented in the user file |
1446 | the HAL_PCD_ResetCallback could be implemented in the user file |
703 | */ |
1447 | */ |
704 | } |
1448 | } |
705 | 1449 | ||
706 | /** |
1450 | /** |
707 | * @brief Suspend event callbacks |
1451 | * @brief Suspend event callback. |
708 | * @param hpcd: PCD handle |
1452 | * @param hpcd PCD handle |
709 | * @retval None |
1453 | * @retval None |
710 | */ |
1454 | */ |
711 | __weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) |
1455 | __weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) |
712 | { |
1456 | { |
713 | /* Prevent unused argument(s) compilation warning */ |
1457 | /* Prevent unused argument(s) compilation warning */ |
714 | UNUSED(hpcd); |
1458 | UNUSED(hpcd); |
- | 1459 | ||
715 | /* NOTE : This function should not be modified, when the callback is needed, |
1460 | /* NOTE : This function should not be modified, when the callback is needed, |
716 | the HAL_PCD_SuspendCallback could be implemented in the user file |
1461 | the HAL_PCD_SuspendCallback could be implemented in the user file |
717 | */ |
1462 | */ |
718 | } |
1463 | } |
719 | 1464 | ||
720 | /** |
1465 | /** |
721 | * @brief Resume event callbacks |
1466 | * @brief Resume event callback. |
722 | * @param hpcd: PCD handle |
1467 | * @param hpcd PCD handle |
723 | * @retval None |
1468 | * @retval None |
724 | */ |
1469 | */ |
725 | __weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) |
1470 | __weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) |
726 | { |
1471 | { |
727 | /* Prevent unused argument(s) compilation warning */ |
1472 | /* Prevent unused argument(s) compilation warning */ |
728 | UNUSED(hpcd); |
1473 | UNUSED(hpcd); |
- | 1474 | ||
729 | /* NOTE : This function should not be modified, when the callback is needed, |
1475 | /* NOTE : This function should not be modified, when the callback is needed, |
730 | the HAL_PCD_ResumeCallback could be implemented in the user file |
1476 | the HAL_PCD_ResumeCallback could be implemented in the user file |
731 | */ |
1477 | */ |
732 | } |
1478 | } |
733 | 1479 | ||
734 | /** |
1480 | /** |
735 | * @brief Incomplete ISO OUT callbacks |
1481 | * @brief Incomplete ISO OUT callback. |
736 | * @param hpcd: PCD handle |
1482 | * @param hpcd PCD handle |
737 | * @param epnum: endpoint number |
1483 | * @param epnum endpoint number |
738 | * @retval None |
1484 | * @retval None |
739 | */ |
1485 | */ |
740 | __weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
1486 | __weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
741 | { |
1487 | { |
742 | /* Prevent unused argument(s) compilation warning */ |
1488 | /* Prevent unused argument(s) compilation warning */ |
743 | UNUSED(hpcd); |
1489 | UNUSED(hpcd); |
744 | UNUSED(epnum); |
1490 | UNUSED(epnum); |
- | 1491 | ||
745 | /* NOTE : This function should not be modified, when the callback is needed, |
1492 | /* NOTE : This function should not be modified, when the callback is needed, |
746 | the HAL_PCD_ISOOUTIncompleteCallback could be implemented in the user file |
1493 | the HAL_PCD_ISOOUTIncompleteCallback could be implemented in the user file |
747 | */ |
1494 | */ |
748 | } |
1495 | } |
749 | 1496 | ||
750 | /** |
1497 | /** |
751 | * @brief Incomplete ISO IN callbacks |
1498 | * @brief Incomplete ISO IN callback. |
752 | * @param hpcd: PCD handle |
1499 | * @param hpcd PCD handle |
753 | * @param epnum: endpoint number |
1500 | * @param epnum endpoint number |
754 | * @retval None |
1501 | * @retval None |
755 | */ |
1502 | */ |
756 | __weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
1503 | __weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
757 | { |
1504 | { |
758 | /* Prevent unused argument(s) compilation warning */ |
1505 | /* Prevent unused argument(s) compilation warning */ |
759 | UNUSED(hpcd); |
1506 | UNUSED(hpcd); |
760 | UNUSED(epnum); |
1507 | UNUSED(epnum); |
- | 1508 | ||
761 | /* NOTE : This function should not be modified, when the callback is needed, |
1509 | /* NOTE : This function should not be modified, when the callback is needed, |
762 | the HAL_PCD_ISOINIncompleteCallback could be implemented in the user file |
1510 | the HAL_PCD_ISOINIncompleteCallback could be implemented in the user file |
763 | */ |
1511 | */ |
764 | } |
1512 | } |
765 | 1513 | ||
766 | /** |
1514 | /** |
767 | * @brief Connection event callbacks |
1515 | * @brief Connection event callback. |
768 | * @param hpcd: PCD handle |
1516 | * @param hpcd PCD handle |
769 | * @retval None |
1517 | * @retval None |
770 | */ |
1518 | */ |
771 | __weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) |
1519 | __weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) |
772 | { |
1520 | { |
773 | /* Prevent unused argument(s) compilation warning */ |
1521 | /* Prevent unused argument(s) compilation warning */ |
774 | UNUSED(hpcd); |
1522 | UNUSED(hpcd); |
- | 1523 | ||
775 | /* NOTE : This function should not be modified, when the callback is needed, |
1524 | /* NOTE : This function should not be modified, when the callback is needed, |
776 | the HAL_PCD_ConnectCallback could be implemented in the user file |
1525 | the HAL_PCD_ConnectCallback could be implemented in the user file |
777 | */ |
1526 | */ |
778 | } |
1527 | } |
779 | 1528 | ||
780 | /** |
1529 | /** |
781 | * @brief Disconnection event callbacks |
1530 | * @brief Disconnection event callback. |
782 | * @param hpcd: PCD handle |
1531 | * @param hpcd PCD handle |
783 | * @retval None |
1532 | * @retval None |
784 | */ |
1533 | */ |
785 | __weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) |
1534 | __weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) |
786 | { |
1535 | { |
787 | /* Prevent unused argument(s) compilation warning */ |
1536 | /* Prevent unused argument(s) compilation warning */ |
788 | UNUSED(hpcd); |
1537 | UNUSED(hpcd); |
- | 1538 | ||
789 | /* NOTE : This function should not be modified, when the callback is needed, |
1539 | /* NOTE : This function should not be modified, when the callback is needed, |
790 | the HAL_PCD_DisconnectCallback could be implemented in the user file |
1540 | the HAL_PCD_DisconnectCallback could be implemented in the user file |
791 | */ |
1541 | */ |
792 | } |
1542 | } |
793 | 1543 | ||
794 | /** |
1544 | /** |
795 | * @} |
1545 | * @} |
796 | */ |
1546 | */ |
797 | 1547 | ||
798 | /** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions |
1548 | /** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions |
799 | * @brief management functions |
1549 | * @brief management functions |
800 | * |
1550 | * |
801 | @verbatim |
1551 | @verbatim |
802 | =============================================================================== |
1552 | =============================================================================== |
803 | ##### Peripheral Control functions ##### |
1553 | ##### Peripheral Control functions ##### |
804 | =============================================================================== |
1554 | =============================================================================== |
805 | [..] |
1555 | [..] |
806 | This subsection provides a set of functions allowing to control the PCD data |
1556 | This subsection provides a set of functions allowing to control the PCD data |
807 | transfers. |
1557 | transfers. |
808 | 1558 | ||
809 | @endverbatim |
1559 | @endverbatim |
810 | * @{ |
1560 | * @{ |
811 | */ |
1561 | */ |
812 | 1562 | ||
813 | /** |
1563 | /** |
814 | * @brief Connect the USB device |
1564 | * @brief Connect the USB device |
815 | * @param hpcd: PCD handle |
1565 | * @param hpcd PCD handle |
816 | * @retval HAL status |
1566 | * @retval HAL status |
817 | */ |
1567 | */ |
818 | HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd) |
1568 | HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd) |
819 | { |
1569 | { |
820 | __HAL_LOCK(hpcd); |
1570 | __HAL_LOCK(hpcd); |
- | 1571 | ||
- | 1572 | #if defined (USB) |
|
821 | HAL_PCDEx_SetConnectionState (hpcd, 1); |
1573 | HAL_PCDEx_SetConnectionState(hpcd, 1U); |
- | 1574 | #endif /* defined (USB) */ |
|
- | 1575 | ||
822 | USB_DevConnect(hpcd->Instance); |
1576 | (void)USB_DevConnect(hpcd->Instance); |
823 | __HAL_UNLOCK(hpcd); |
1577 | __HAL_UNLOCK(hpcd); |
- | 1578 | ||
824 | return HAL_OK; |
1579 | return HAL_OK; |
825 | } |
1580 | } |
826 | 1581 | ||
827 | /** |
1582 | /** |
828 | * @brief Disconnect the USB device |
1583 | * @brief Disconnect the USB device. |
829 | * @param hpcd: PCD handle |
1584 | * @param hpcd PCD handle |
830 | * @retval HAL status |
1585 | * @retval HAL status |
831 | */ |
1586 | */ |
832 | HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd) |
1587 | HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd) |
833 | { |
1588 | { |
834 | __HAL_LOCK(hpcd); |
1589 | __HAL_LOCK(hpcd); |
- | 1590 | ||
- | 1591 | #if defined (USB) |
|
835 | HAL_PCDEx_SetConnectionState (hpcd, 0U); |
1592 | HAL_PCDEx_SetConnectionState(hpcd, 0U); |
- | 1593 | #endif /* defined (USB) */ |
|
- | 1594 | ||
836 | USB_DevDisconnect(hpcd->Instance); |
1595 | (void)USB_DevDisconnect(hpcd->Instance); |
837 | __HAL_UNLOCK(hpcd); |
1596 | __HAL_UNLOCK(hpcd); |
- | 1597 | ||
838 | return HAL_OK; |
1598 | return HAL_OK; |
839 | } |
1599 | } |
840 | 1600 | ||
841 | /** |
1601 | /** |
842 | * @brief Set the USB Device address |
1602 | * @brief Set the USB Device address. |
843 | * @param hpcd: PCD handle |
1603 | * @param hpcd PCD handle |
844 | * @param address: new device address |
1604 | * @param address new device address |
845 | * @retval HAL status |
1605 | * @retval HAL status |
846 | */ |
1606 | */ |
847 | HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address) |
1607 | HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address) |
848 | { |
1608 | { |
849 | __HAL_LOCK(hpcd); |
1609 | __HAL_LOCK(hpcd); |
850 | hpcd->USB_Address = address; |
1610 | hpcd->USB_Address = address; |
851 | USB_SetDevAddress(hpcd->Instance, address); |
1611 | (void)USB_SetDevAddress(hpcd->Instance, address); |
852 | __HAL_UNLOCK(hpcd); |
1612 | __HAL_UNLOCK(hpcd); |
- | 1613 | ||
853 | return HAL_OK; |
1614 | return HAL_OK; |
854 | } |
1615 | } |
855 | /** |
1616 | /** |
856 | * @brief Open and configure an endpoint |
1617 | * @brief Open and configure an endpoint. |
857 | * @param hpcd: PCD handle |
1618 | * @param hpcd PCD handle |
858 | * @param ep_addr: endpoint address |
1619 | * @param ep_addr endpoint address |
859 | * @param ep_mps: endpoint max packet size |
1620 | * @param ep_mps endpoint max packet size |
860 | * @param ep_type: endpoint type |
1621 | * @param ep_type endpoint type |
861 | * @retval HAL status |
1622 | * @retval HAL status |
862 | */ |
1623 | */ |
863 | HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type) |
1624 | HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, |
- | 1625 | uint16_t ep_mps, uint8_t ep_type) |
|
864 | { |
1626 | { |
865 | HAL_StatusTypeDef ret = HAL_OK; |
1627 | HAL_StatusTypeDef ret = HAL_OK; |
866 | PCD_EPTypeDef *ep = NULL; |
1628 | PCD_EPTypeDef *ep; |
867 | 1629 | ||
868 | if ((ep_addr & 0x80U) == 0x80U) |
1630 | if ((ep_addr & 0x80U) == 0x80U) |
869 | { |
1631 | { |
870 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
1632 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
- | 1633 | ep->is_in = 1U; |
|
871 | } |
1634 | } |
872 | else |
1635 | else |
873 | { |
1636 | { |
874 | ep = &hpcd->OUT_ep[ep_addr & 0x7FU]; |
1637 | ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK]; |
- | 1638 | ep->is_in = 0U; |
|
875 | } |
1639 | } |
876 | ep->num = ep_addr & 0x7FU; |
- | |
877 | 1640 | ||
878 | ep->is_in = (0x80U & ep_addr) != 0U; |
1641 | ep->num = ep_addr & EP_ADDR_MSK; |
879 | ep->maxpacket = ep_mps; |
1642 | ep->maxpacket = ep_mps; |
880 | ep->type = ep_type; |
1643 | ep->type = ep_type; |
- | 1644 | ||
- | 1645 | if (ep->is_in != 0U) |
|
881 | 1646 | { |
|
- | 1647 | /* Assign a Tx FIFO */ |
|
- | 1648 | ep->tx_fifo_num = ep->num; |
|
- | 1649 | } |
|
- | 1650 | /* Set initial data PID. */ |
|
- | 1651 | if (ep_type == EP_TYPE_BULK) |
|
- | 1652 | { |
|
- | 1653 | ep->data_pid_start = 0U; |
|
- | 1654 | } |
|
- | 1655 | ||
882 | __HAL_LOCK(hpcd); |
1656 | __HAL_LOCK(hpcd); |
883 | USB_ActivateEndpoint(hpcd->Instance , ep); |
1657 | (void)USB_ActivateEndpoint(hpcd->Instance, ep); |
884 | __HAL_UNLOCK(hpcd); |
1658 | __HAL_UNLOCK(hpcd); |
- | 1659 | ||
885 | return ret; |
1660 | return ret; |
886 | } |
1661 | } |
887 | 1662 | ||
888 | /** |
1663 | /** |
889 | * @brief Deactivate an endpoint |
1664 | * @brief Deactivate an endpoint. |
890 | * @param hpcd: PCD handle |
1665 | * @param hpcd PCD handle |
891 | * @param ep_addr: endpoint address |
1666 | * @param ep_addr endpoint address |
892 | * @retval HAL status |
1667 | * @retval HAL status |
893 | */ |
1668 | */ |
894 | HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
1669 | HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
895 | { |
1670 | { |
896 | PCD_EPTypeDef *ep = NULL; |
1671 | PCD_EPTypeDef *ep; |
897 | 1672 | ||
898 | if ((ep_addr & 0x80U) == 0x80U) |
1673 | if ((ep_addr & 0x80U) == 0x80U) |
899 | { |
1674 | { |
900 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
1675 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
- | 1676 | ep->is_in = 1U; |
|
901 | } |
1677 | } |
902 | else |
1678 | else |
903 | { |
1679 | { |
904 | ep = &hpcd->OUT_ep[ep_addr & 0x7FU]; |
1680 | ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK]; |
- | 1681 | ep->is_in = 0U; |
|
905 | } |
1682 | } |
906 | ep->num = ep_addr & 0x7FU; |
1683 | ep->num = ep_addr & EP_ADDR_MSK; |
907 | - | ||
908 | ep->is_in = (0x80U & ep_addr) != 0U; |
- | |
909 | 1684 | ||
910 | __HAL_LOCK(hpcd); |
1685 | __HAL_LOCK(hpcd); |
911 | USB_DeactivateEndpoint(hpcd->Instance , ep); |
1686 | (void)USB_DeactivateEndpoint(hpcd->Instance, ep); |
912 | __HAL_UNLOCK(hpcd); |
1687 | __HAL_UNLOCK(hpcd); |
913 | return HAL_OK; |
1688 | return HAL_OK; |
914 | } |
1689 | } |
915 | 1690 | ||
916 | 1691 | ||
917 | /** |
1692 | /** |
918 | * @brief Receive an amount of data |
1693 | * @brief Receive an amount of data. |
919 | * @param hpcd: PCD handle |
1694 | * @param hpcd PCD handle |
920 | * @param ep_addr: endpoint address |
1695 | * @param ep_addr endpoint address |
921 | * @param pBuf: pointer to the reception buffer |
1696 | * @param pBuf pointer to the reception buffer |
922 | * @param len: amount of data to be received |
1697 | * @param len amount of data to be received |
923 | * @retval HAL status |
1698 | * @retval HAL status |
924 | */ |
1699 | */ |
925 | HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len) |
1700 | HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len) |
926 | { |
1701 | { |
927 | PCD_EPTypeDef *ep = NULL; |
1702 | PCD_EPTypeDef *ep; |
928 | 1703 | ||
929 | ep = &hpcd->OUT_ep[ep_addr & 0x7FU]; |
1704 | ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK]; |
930 | 1705 | ||
931 | /*setup and start the Xfer */ |
1706 | /*setup and start the Xfer */ |
932 | ep->xfer_buff = pBuf; |
1707 | ep->xfer_buff = pBuf; |
933 | ep->xfer_len = len; |
1708 | ep->xfer_len = len; |
934 | ep->xfer_count = 0U; |
1709 | ep->xfer_count = 0U; |
935 | ep->is_in = 0U; |
1710 | ep->is_in = 0U; |
936 | ep->num = ep_addr & 0x7FU; |
1711 | ep->num = ep_addr & EP_ADDR_MSK; |
937 | 1712 | ||
938 | if ((ep_addr & 0x7FU) == 0U) |
1713 | if ((ep_addr & EP_ADDR_MSK) == 0U) |
939 | { |
1714 | { |
940 | USB_EP0StartXfer(hpcd->Instance , ep); |
1715 | (void)USB_EP0StartXfer(hpcd->Instance, ep); |
941 | } |
1716 | } |
942 | else |
1717 | else |
943 | { |
1718 | { |
944 | USB_EPStartXfer(hpcd->Instance , ep); |
1719 | (void)USB_EPStartXfer(hpcd->Instance, ep); |
945 | } |
1720 | } |
946 | 1721 | ||
947 | return HAL_OK; |
1722 | return HAL_OK; |
948 | } |
1723 | } |
949 | 1724 | ||
950 | /** |
1725 | /** |
951 | * @brief Get Received Data Size |
1726 | * @brief Get Received Data Size |
952 | * @param hpcd: PCD handle |
1727 | * @param hpcd PCD handle |
953 | * @param ep_addr: endpoint address |
1728 | * @param ep_addr endpoint address |
954 | * @retval Data Size |
1729 | * @retval Data Size |
955 | */ |
1730 | */ |
956 | uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
1731 | uint32_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
957 | { |
1732 | { |
958 | return hpcd->OUT_ep[ep_addr & 0xF].xfer_count; |
1733 | return hpcd->OUT_ep[ep_addr & EP_ADDR_MSK].xfer_count; |
959 | } |
1734 | } |
960 | /** |
1735 | /** |
961 | * @brief Send an amount of data |
1736 | * @brief Send an amount of data |
962 | * @param hpcd: PCD handle |
1737 | * @param hpcd PCD handle |
963 | * @param ep_addr: endpoint address |
1738 | * @param ep_addr endpoint address |
964 | * @param pBuf: pointer to the transmission buffer |
1739 | * @param pBuf pointer to the transmission buffer |
965 | * @param len: amount of data to be sent |
1740 | * @param len amount of data to be sent |
966 | * @retval HAL status |
1741 | * @retval HAL status |
967 | */ |
1742 | */ |
968 | HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len) |
1743 | HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len) |
969 | { |
1744 | { |
970 | PCD_EPTypeDef *ep = NULL; |
1745 | PCD_EPTypeDef *ep; |
971 | 1746 | ||
972 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
1747 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
973 | 1748 | ||
974 | /*setup and start the Xfer */ |
1749 | /*setup and start the Xfer */ |
975 | ep->xfer_buff = pBuf; |
1750 | ep->xfer_buff = pBuf; |
976 | ep->xfer_len = len; |
1751 | ep->xfer_len = len; |
- | 1752 | #if defined (USB) |
|
- | 1753 | ep->xfer_fill_db = 1U; |
|
- | 1754 | ep->xfer_len_db = len; |
|
- | 1755 | #endif /* defined (USB) */ |
|
977 | ep->xfer_count = 0U; |
1756 | ep->xfer_count = 0U; |
978 | ep->is_in = 1U; |
1757 | ep->is_in = 1U; |
979 | ep->num = ep_addr & 0x7FU; |
1758 | ep->num = ep_addr & EP_ADDR_MSK; |
980 | 1759 | ||
981 | if ((ep_addr & 0x7FU) == 0U) |
1760 | if ((ep_addr & EP_ADDR_MSK) == 0U) |
982 | { |
1761 | { |
983 | USB_EP0StartXfer(hpcd->Instance , ep); |
1762 | (void)USB_EP0StartXfer(hpcd->Instance, ep); |
984 | } |
1763 | } |
985 | else |
1764 | else |
986 | { |
1765 | { |
987 | USB_EPStartXfer(hpcd->Instance , ep); |
1766 | (void)USB_EPStartXfer(hpcd->Instance, ep); |
988 | } |
1767 | } |
989 | 1768 | ||
990 | return HAL_OK; |
1769 | return HAL_OK; |
991 | } |
1770 | } |
992 | 1771 | ||
993 | /** |
1772 | /** |
994 | * @brief Set a STALL condition over an endpoint |
1773 | * @brief Set a STALL condition over an endpoint |
995 | * @param hpcd: PCD handle |
1774 | * @param hpcd PCD handle |
996 | * @param ep_addr: endpoint address |
1775 | * @param ep_addr endpoint address |
997 | * @retval HAL status |
1776 | * @retval HAL status |
998 | */ |
1777 | */ |
999 | HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
1778 | HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
1000 | { |
1779 | { |
1001 | PCD_EPTypeDef *ep = NULL; |
1780 | PCD_EPTypeDef *ep; |
- | 1781 | ||
- | 1782 | if (((uint32_t)ep_addr & EP_ADDR_MSK) > hpcd->Init.dev_endpoints) |
|
- | 1783 | { |
|
- | 1784 | return HAL_ERROR; |
|
1002 | 1785 | } |
|
- | 1786 | ||
1003 | if ((0x80U & ep_addr) == 0x80U) |
1787 | if ((0x80U & ep_addr) == 0x80U) |
1004 | { |
1788 | { |
1005 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
1789 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
- | 1790 | ep->is_in = 1U; |
|
1006 | } |
1791 | } |
1007 | else |
1792 | else |
1008 | { |
1793 | { |
1009 | ep = &hpcd->OUT_ep[ep_addr]; |
1794 | ep = &hpcd->OUT_ep[ep_addr]; |
- | 1795 | ep->is_in = 0U; |
|
1010 | } |
1796 | } |
1011 | 1797 | ||
1012 | ep->is_stall = 1U; |
1798 | ep->is_stall = 1U; |
1013 | ep->num = ep_addr & 0x7FU; |
1799 | ep->num = ep_addr & EP_ADDR_MSK; |
1014 | ep->is_in = ((ep_addr & 0x80U) == 0x80U); |
- | |
1015 | 1800 | ||
1016 | __HAL_LOCK(hpcd); |
1801 | __HAL_LOCK(hpcd); |
- | 1802 | ||
1017 | USB_EPSetStall(hpcd->Instance , ep); |
1803 | (void)USB_EPSetStall(hpcd->Instance, ep); |
- | 1804 | ||
1018 | if((ep_addr & 0x7FU) == 0U) |
1805 | if ((ep_addr & EP_ADDR_MSK) == 0U) |
1019 | { |
1806 | { |
1020 | USB_EP0_OutStart(hpcd->Instance, (uint8_t *)hpcd->Setup); |
1807 | (void)USB_EP0_OutStart(hpcd->Instance, (uint8_t *)hpcd->Setup); |
1021 | } |
1808 | } |
- | 1809 | ||
1022 | __HAL_UNLOCK(hpcd); |
1810 | __HAL_UNLOCK(hpcd); |
1023 | 1811 | ||
1024 | return HAL_OK; |
1812 | return HAL_OK; |
1025 | } |
1813 | } |
1026 | 1814 | ||
1027 | /** |
1815 | /** |
1028 | * @brief Clear a STALL condition over in an endpoint |
1816 | * @brief Clear a STALL condition over in an endpoint |
1029 | * @param hpcd: PCD handle |
1817 | * @param hpcd PCD handle |
1030 | * @param ep_addr: endpoint address |
1818 | * @param ep_addr endpoint address |
1031 | * @retval HAL status |
1819 | * @retval HAL status |
1032 | */ |
1820 | */ |
1033 | HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
1821 | HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
1034 | { |
1822 | { |
1035 | PCD_EPTypeDef *ep = NULL; |
1823 | PCD_EPTypeDef *ep; |
- | 1824 | ||
- | 1825 | if (((uint32_t)ep_addr & 0x0FU) > hpcd->Init.dev_endpoints) |
|
- | 1826 | { |
|
- | 1827 | return HAL_ERROR; |
|
1036 | 1828 | } |
|
- | 1829 | ||
1037 | if ((0x80U & ep_addr) == 0x80U) |
1830 | if ((0x80U & ep_addr) == 0x80U) |
1038 | { |
1831 | { |
1039 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
1832 | ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK]; |
- | 1833 | ep->is_in = 1U; |
|
1040 | } |
1834 | } |
1041 | else |
1835 | else |
1042 | { |
1836 | { |
1043 | ep = &hpcd->OUT_ep[ep_addr]; |
1837 | ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK]; |
- | 1838 | ep->is_in = 0U; |
|
1044 | } |
1839 | } |
1045 | 1840 | ||
1046 | ep->is_stall = 0U; |
1841 | ep->is_stall = 0U; |
1047 | ep->num = ep_addr & 0x7FU; |
1842 | ep->num = ep_addr & EP_ADDR_MSK; |
1048 | ep->is_in = ((ep_addr & 0x80U) == 0x80U); |
- | |
1049 | 1843 | ||
1050 | __HAL_LOCK(hpcd); |
1844 | __HAL_LOCK(hpcd); |
1051 | USB_EPClearStall(hpcd->Instance , ep); |
1845 | (void)USB_EPClearStall(hpcd->Instance, ep); |
1052 | __HAL_UNLOCK(hpcd); |
1846 | __HAL_UNLOCK(hpcd); |
1053 | 1847 | ||
1054 | return HAL_OK; |
1848 | return HAL_OK; |
1055 | } |
1849 | } |
1056 | 1850 | ||
1057 | /** |
1851 | /** |
1058 | * @brief Flush an endpoint |
1852 | * @brief Flush an endpoint |
1059 | * @param hpcd: PCD handle |
1853 | * @param hpcd PCD handle |
1060 | * @param ep_addr: endpoint address |
1854 | * @param ep_addr endpoint address |
1061 | * @retval HAL status |
1855 | * @retval HAL status |
1062 | */ |
1856 | */ |
1063 | HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
1857 | HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
1064 | { |
1858 | { |
1065 | __HAL_LOCK(hpcd); |
1859 | __HAL_LOCK(hpcd); |
1066 | 1860 | ||
1067 | if ((ep_addr & 0x80U) == 0x80U) |
1861 | if ((ep_addr & 0x80U) == 0x80U) |
1068 | { |
1862 | { |
1069 | USB_FlushTxFifo(hpcd->Instance, ep_addr & 0x7FU); |
1863 | (void)USB_FlushTxFifo(hpcd->Instance, (uint32_t)ep_addr & EP_ADDR_MSK); |
1070 | } |
1864 | } |
1071 | else |
1865 | else |
1072 | { |
1866 | { |
1073 | USB_FlushRxFifo(hpcd->Instance); |
1867 | (void)USB_FlushRxFifo(hpcd->Instance); |
1074 | } |
1868 | } |
1075 | 1869 | ||
1076 | __HAL_UNLOCK(hpcd); |
1870 | __HAL_UNLOCK(hpcd); |
1077 | 1871 | ||
1078 | return HAL_OK; |
1872 | return HAL_OK; |
1079 | } |
1873 | } |
1080 | 1874 | ||
1081 | /** |
1875 | /** |
1082 | * @brief HAL_PCD_ActivateRemoteWakeup : active remote wakeup signalling |
1876 | * @brief Activate remote wakeup signalling |
1083 | * @param hpcd: PCD handle |
1877 | * @param hpcd PCD handle |
1084 | * @retval HAL status |
1878 | * @retval HAL status |
1085 | */ |
1879 | */ |
1086 | HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd) |
1880 | HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd) |
1087 | { |
1881 | { |
1088 | return(USB_ActivateRemoteWakeup(hpcd->Instance)); |
1882 | return (USB_ActivateRemoteWakeup(hpcd->Instance)); |
1089 | } |
1883 | } |
1090 | 1884 | ||
1091 | /** |
1885 | /** |
1092 | * @brief HAL_PCD_DeActivateRemoteWakeup : de-active remote wakeup signalling |
1886 | * @brief De-activate remote wakeup signalling. |
1093 | * @param hpcd: PCD handle |
1887 | * @param hpcd PCD handle |
1094 | * @retval HAL status |
1888 | * @retval HAL status |
1095 | */ |
1889 | */ |
1096 | HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd) |
1890 | HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd) |
1097 | { |
1891 | { |
1098 | return(USB_DeActivateRemoteWakeup(hpcd->Instance)); |
1892 | return (USB_DeActivateRemoteWakeup(hpcd->Instance)); |
1099 | } |
1893 | } |
- | 1894 | ||
1100 | /** |
1895 | /** |
1101 | * @} |
1896 | * @} |
1102 | */ |
1897 | */ |
1103 | 1898 | ||
1104 | /** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions |
1899 | /** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions |
1105 | * @brief Peripheral State functions |
1900 | * @brief Peripheral State functions |
1106 | * |
1901 | * |
1107 | @verbatim |
1902 | @verbatim |
1108 | =============================================================================== |
1903 | =============================================================================== |
1109 | ##### Peripheral State functions ##### |
1904 | ##### Peripheral State functions ##### |
1110 | =============================================================================== |
1905 | =============================================================================== |
1111 | [..] |
1906 | [..] |
1112 | This subsection permits to get in run-time the status of the peripheral |
1907 | This subsection permits to get in run-time the status of the peripheral |
1113 | and the data flow. |
1908 | and the data flow. |
1114 | 1909 | ||
1115 | @endverbatim |
1910 | @endverbatim |
1116 | * @{ |
1911 | * @{ |
1117 | */ |
1912 | */ |
1118 | 1913 | ||
1119 | /** |
1914 | /** |
1120 | * @brief Return the PCD state |
1915 | * @brief Return the PCD handle state. |
1121 | * @param hpcd: PCD handle |
1916 | * @param hpcd PCD handle |
1122 | * @retval HAL state |
1917 | * @retval HAL state |
1123 | */ |
1918 | */ |
1124 | PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd) |
1919 | PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd) |
1125 | { |
1920 | { |
1126 | return hpcd->State; |
1921 | return hpcd->State; |
Line 1132... | Line 1927... | ||
1132 | 1927 | ||
1133 | /** |
1928 | /** |
1134 | * @} |
1929 | * @} |
1135 | */ |
1930 | */ |
1136 | 1931 | ||
- | 1932 | /* Private functions ---------------------------------------------------------*/ |
|
1137 | /** @addtogroup PCD_Private_Functions |
1933 | /** @addtogroup PCD_Private_Functions |
1138 | * @{ |
1934 | * @{ |
1139 | */ |
1935 | */ |
1140 | #if defined (USB_OTG_FS) |
1936 | #if defined (USB_OTG_FS) |
1141 | /** |
1937 | /** |
1142 | * @brief DCD_WriteEmptyTxFifo |
- | |
1143 | * check FIFO for the next packet to be loaded |
1938 | * @brief Check FIFO for the next packet to be loaded. |
1144 | * @param hpcd: PCD handle |
1939 | * @param hpcd PCD handle |
1145 | * @param epnum : endpoint number |
1940 | * @param epnum endpoint number |
1146 | * This parameter can be a value from 0 to 15 |
- | |
1147 | * @retval HAL status |
1941 | * @retval HAL status |
1148 | */ |
1942 | */ |
1149 | static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum) |
1943 | static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum) |
1150 | { |
1944 | { |
1151 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; |
1945 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; |
- | 1946 | uint32_t USBx_BASE = (uint32_t)USBx; |
|
1152 | USB_OTG_EPTypeDef *ep = NULL; |
1947 | USB_OTG_EPTypeDef *ep; |
1153 | int32_t len = 0; |
1948 | uint32_t len; |
1154 | uint32_t len32b = 0U; |
1949 | uint32_t len32b; |
1155 | uint32_t fifoemptymsk = 0U; |
1950 | uint32_t fifoemptymsk; |
1156 | 1951 | ||
1157 | ep = &hpcd->IN_ep[epnum]; |
1952 | ep = &hpcd->IN_ep[epnum]; |
- | 1953 | ||
- | 1954 | if (ep->xfer_count > ep->xfer_len) |
|
- | 1955 | { |
|
- | 1956 | return HAL_ERROR; |
|
- | 1957 | } |
|
- | 1958 | ||
1158 | len = ep->xfer_len - ep->xfer_count; |
1959 | len = ep->xfer_len - ep->xfer_count; |
1159 | 1960 | ||
1160 | if (len > ep->maxpacket) |
1961 | if (len > ep->maxpacket) |
1161 | { |
1962 | { |
1162 | len = ep->maxpacket; |
1963 | len = ep->maxpacket; |
1163 | } |
1964 | } |
1164 | 1965 | ||
1165 | len32b = (len + 3U) / 4U; |
1966 | len32b = (len + 3U) / 4U; |
1166 | 1967 | ||
1167 | while ((USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) > len32b && |
1968 | while (((USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) >= len32b) && |
1168 | ep->xfer_count < ep->xfer_len && |
1969 | (ep->xfer_count < ep->xfer_len) && (ep->xfer_len != 0U)) |
1169 | ep->xfer_len != 0U) |
- | |
1170 | { |
1970 | { |
1171 | /* Write the FIFO */ |
1971 | /* Write the FIFO */ |
1172 | len = ep->xfer_len - ep->xfer_count; |
1972 | len = ep->xfer_len - ep->xfer_count; |
1173 | 1973 | ||
1174 | if ((uint32_t)len > ep->maxpacket) |
1974 | if (len > ep->maxpacket) |
1175 | { |
1975 | { |
1176 | len = ep->maxpacket; |
1976 | len = ep->maxpacket; |
1177 | } |
1977 | } |
1178 | len32b = (len + 3U) / 4U; |
1978 | len32b = (len + 3U) / 4U; |
1179 | 1979 | ||
1180 | USB_WritePacket(USBx, ep->xfer_buff, epnum, len); |
1980 | (void)USB_WritePacket(USBx, ep->xfer_buff, (uint8_t)epnum, (uint16_t)len); |
1181 | 1981 | ||
1182 | ep->xfer_buff += len; |
1982 | ep->xfer_buff += len; |
1183 | ep->xfer_count += len; |
1983 | ep->xfer_count += len; |
1184 | } |
1984 | } |
1185 | 1985 | ||
1186 | if(len <= 0) |
1986 | if (ep->xfer_len <= ep->xfer_count) |
1187 | { |
1987 | { |
1188 | fifoemptymsk = 0x01U << epnum; |
1988 | fifoemptymsk = (uint32_t)(0x1UL << (epnum & EP_ADDR_MSK)); |
1189 | USBx_DEVICE->DIEPEMPMSK &= ~fifoemptymsk; |
1989 | USBx_DEVICE->DIEPEMPMSK &= ~fifoemptymsk; |
1190 | - | ||
1191 | } |
1990 | } |
1192 | 1991 | ||
1193 | return HAL_OK; |
1992 | return HAL_OK; |
1194 | } |
1993 | } |
- | 1994 | ||
- | 1995 | ||
- | 1996 | /** |
|
- | 1997 | * @brief process EP OUT transfer complete interrupt. |
|
- | 1998 | * @param hpcd PCD handle |
|
- | 1999 | * @param epnum endpoint number |
|
- | 2000 | * @retval HAL status |
|
- | 2001 | */ |
|
- | 2002 | static HAL_StatusTypeDef PCD_EP_OutXfrComplete_int(PCD_HandleTypeDef *hpcd, uint32_t epnum) |
|
- | 2003 | { |
|
- | 2004 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; |
|
- | 2005 | uint32_t USBx_BASE = (uint32_t)USBx; |
|
- | 2006 | uint32_t gSNPSiD = *(__IO uint32_t *)(&USBx->CID + 0x1U); |
|
- | 2007 | uint32_t DoepintReg = USBx_OUTEP(epnum)->DOEPINT; |
|
- | 2008 | ||
- | 2009 | if (gSNPSiD == USB_OTG_CORE_ID_310A) |
|
- | 2010 | { |
|
- | 2011 | /* StupPktRcvd = 1 this is a setup packet */ |
|
- | 2012 | if ((DoepintReg & USB_OTG_DOEPINT_STPKTRX) == USB_OTG_DOEPINT_STPKTRX) |
|
- | 2013 | { |
|
- | 2014 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_STPKTRX); |
|
- | 2015 | } |
|
- | 2016 | else |
|
- | 2017 | { |
|
- | 2018 | if ((DoepintReg & USB_OTG_DOEPINT_OTEPSPR) == USB_OTG_DOEPINT_OTEPSPR) |
|
- | 2019 | { |
|
- | 2020 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPSPR); |
|
- | 2021 | } |
|
- | 2022 | ||
- | 2023 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2024 | hpcd->DataOutStageCallback(hpcd, (uint8_t)epnum); |
|
- | 2025 | #else |
|
- | 2026 | HAL_PCD_DataOutStageCallback(hpcd, (uint8_t)epnum); |
|
- | 2027 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 2028 | } |
|
- | 2029 | } |
|
- | 2030 | else |
|
- | 2031 | { |
|
- | 2032 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2033 | hpcd->DataOutStageCallback(hpcd, (uint8_t)epnum); |
|
- | 2034 | #else |
|
- | 2035 | HAL_PCD_DataOutStageCallback(hpcd, (uint8_t)epnum); |
|
- | 2036 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 2037 | } |
|
- | 2038 | ||
- | 2039 | return HAL_OK; |
|
- | 2040 | } |
|
- | 2041 | ||
- | 2042 | ||
- | 2043 | /** |
|
- | 2044 | * @brief process EP OUT setup packet received interrupt. |
|
- | 2045 | * @param hpcd PCD handle |
|
- | 2046 | * @param epnum endpoint number |
|
- | 2047 | * @retval HAL status |
|
- | 2048 | */ |
|
- | 2049 | static HAL_StatusTypeDef PCD_EP_OutSetupPacket_int(PCD_HandleTypeDef *hpcd, uint32_t epnum) |
|
- | 2050 | { |
|
- | 2051 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; |
|
- | 2052 | uint32_t USBx_BASE = (uint32_t)USBx; |
|
- | 2053 | uint32_t gSNPSiD = *(__IO uint32_t *)(&USBx->CID + 0x1U); |
|
- | 2054 | uint32_t DoepintReg = USBx_OUTEP(epnum)->DOEPINT; |
|
- | 2055 | ||
- | 2056 | if ((gSNPSiD > USB_OTG_CORE_ID_300A) && |
|
- | 2057 | ((DoepintReg & USB_OTG_DOEPINT_STPKTRX) == USB_OTG_DOEPINT_STPKTRX)) |
|
- | 2058 | { |
|
- | 2059 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_STPKTRX); |
|
- | 2060 | } |
|
- | 2061 | ||
- | 2062 | /* Inform the upper layer that a setup packet is available */ |
|
- | 2063 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2064 | hpcd->SetupStageCallback(hpcd); |
|
- | 2065 | #else |
|
- | 2066 | HAL_PCD_SetupStageCallback(hpcd); |
|
- | 2067 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 2068 | ||
- | 2069 | return HAL_OK; |
|
- | 2070 | } |
|
1195 | #endif /* USB_OTG_FS */ |
2071 | #endif /* defined (USB_OTG_FS) */ |
1196 | 2072 | ||
1197 | #if defined (USB) |
2073 | #if defined (USB) |
1198 | /** |
2074 | /** |
1199 | * @brief This function handles PCD Endpoint interrupt request. |
2075 | * @brief This function handles PCD Endpoint interrupt request. |
1200 | * @param hpcd: PCD handle |
2076 | * @param hpcd PCD handle |
1201 | * @retval HAL status |
2077 | * @retval HAL status |
1202 | */ |
2078 | */ |
1203 | static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd) |
2079 | static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd) |
1204 | { |
2080 | { |
1205 | PCD_EPTypeDef *ep = NULL; |
2081 | PCD_EPTypeDef *ep; |
1206 | uint16_t count = 0; |
2082 | uint16_t count, wIstr, wEPVal, TxByteNbre; |
1207 | uint8_t epindex = 0; |
2083 | uint8_t epindex; |
1208 | __IO uint16_t wIstr = 0; |
- | |
1209 | __IO uint16_t wEPVal = 0; |
- | |
1210 | 2084 | ||
1211 | /* stay in loop while pending interrupts */ |
2085 | /* stay in loop while pending interrupts */ |
1212 | while (((wIstr = hpcd->Instance->ISTR) & USB_ISTR_CTR) != 0) |
2086 | while ((hpcd->Instance->ISTR & USB_ISTR_CTR) != 0U) |
1213 | { |
2087 | { |
- | 2088 | wIstr = hpcd->Instance->ISTR; |
|
- | 2089 | ||
1214 | /* extract highest priority endpoint number */ |
2090 | /* extract highest priority endpoint number */ |
1215 | epindex = (uint8_t)(wIstr & USB_ISTR_EP_ID); |
2091 | epindex = (uint8_t)(wIstr & USB_ISTR_EP_ID); |
1216 | 2092 | ||
1217 | if (epindex == 0) |
2093 | if (epindex == 0U) |
1218 | { |
2094 | { |
1219 | /* Decode and service control endpoint interrupt */ |
2095 | /* Decode and service control endpoint interrupt */ |
1220 | 2096 | ||
1221 | /* DIR bit = origin of the interrupt */ |
2097 | /* DIR bit = origin of the interrupt */ |
1222 | if ((wIstr & USB_ISTR_DIR) == 0) |
2098 | if ((wIstr & USB_ISTR_DIR) == 0U) |
1223 | { |
2099 | { |
1224 | /* DIR = 0 */ |
2100 | /* DIR = 0 */ |
1225 | 2101 | ||
1226 | /* DIR = 0 => IN int */ |
2102 | /* DIR = 0 => IN int */ |
1227 | /* DIR = 0 implies that (EP_CTR_TX = 1) always */ |
2103 | /* DIR = 0 implies that (EP_CTR_TX = 1) always */ |
1228 | PCD_CLEAR_TX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
2104 | PCD_CLEAR_TX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
1229 | ep = &hpcd->IN_ep[0]; |
2105 | ep = &hpcd->IN_ep[0]; |
1230 | 2106 | ||
1231 | ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
2107 | ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
1232 | ep->xfer_buff += ep->xfer_count; |
2108 | ep->xfer_buff += ep->xfer_count; |
1233 | 2109 | ||
1234 | /* TX COMPLETE */ |
2110 | /* TX COMPLETE */ |
- | 2111 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2112 | hpcd->DataInStageCallback(hpcd, 0U); |
|
- | 2113 | #else |
|
1235 | HAL_PCD_DataInStageCallback(hpcd, 0U); |
2114 | HAL_PCD_DataInStageCallback(hpcd, 0U); |
1236 | 2115 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
1237 | 2116 | ||
1238 | if((hpcd->USB_Address > 0U)&& ( ep->xfer_len == 0U)) |
2117 | if ((hpcd->USB_Address > 0U) && (ep->xfer_len == 0U)) |
1239 | { |
2118 | { |
1240 | hpcd->Instance->DADDR = (hpcd->USB_Address | USB_DADDR_EF); |
2119 | hpcd->Instance->DADDR = ((uint16_t)hpcd->USB_Address | USB_DADDR_EF); |
1241 | hpcd->USB_Address = 0U; |
2120 | hpcd->USB_Address = 0U; |
1242 | } |
2121 | } |
1243 | - | ||
1244 | } |
2122 | } |
1245 | else |
2123 | else |
1246 | { |
2124 | { |
1247 | /* DIR = 1 */ |
2125 | /* DIR = 1 */ |
1248 | 2126 | ||
1249 | /* DIR = 1 & CTR_RX => SETUP or OUT int */ |
2127 | /* DIR = 1 & CTR_RX => SETUP or OUT int */ |
1250 | /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */ |
2128 | /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */ |
1251 | ep = &hpcd->OUT_ep[0U]; |
2129 | ep = &hpcd->OUT_ep[0]; |
1252 | wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0); |
2130 | wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0); |
1253 | 2131 | ||
1254 | if ((wEPVal & USB_EP_SETUP) != 0U) |
2132 | if ((wEPVal & USB_EP_SETUP) != 0U) |
1255 | { |
2133 | { |
1256 | /* Get SETUP Packet*/ |
2134 | /* Get SETUP Packet */ |
1257 | ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
2135 | ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
- | 2136 | ||
1258 | USB_ReadPMA(hpcd->Instance, (uint8_t*)hpcd->Setup ,ep->pmaadress , ep->xfer_count); |
2137 | USB_ReadPMA(hpcd->Instance, (uint8_t *)hpcd->Setup, |
- | 2138 | ep->pmaadress, (uint16_t)ep->xfer_count); |
|
- | 2139 | ||
1259 | /* SETUP bit kept frozen while CTR_RX = 1*/ |
2140 | /* SETUP bit kept frozen while CTR_RX = 1 */ |
1260 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
2141 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
1261 | 2142 | ||
1262 | /* Process SETUP Packet*/ |
2143 | /* Process SETUP Packet*/ |
- | 2144 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2145 | hpcd->SetupStageCallback(hpcd); |
|
- | 2146 | #else |
|
1263 | HAL_PCD_SetupStageCallback(hpcd); |
2147 | HAL_PCD_SetupStageCallback(hpcd); |
- | 2148 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
1264 | } |
2149 | } |
1265 | - | ||
1266 | else if ((wEPVal & USB_EP_CTR_RX) != 0U) |
2150 | else if ((wEPVal & USB_EP_CTR_RX) != 0U) |
1267 | { |
2151 | { |
1268 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
2152 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
- | 2153 | ||
1269 | /* Get Control Data OUT Packet*/ |
2154 | /* Get Control Data OUT Packet */ |
1270 | ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
2155 | ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
1271 | 2156 | ||
1272 | if (ep->xfer_count != 0U) |
2157 | if ((ep->xfer_count != 0U) && (ep->xfer_buff != 0U)) |
1273 | { |
2158 | { |
1274 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count); |
2159 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, |
- | 2160 | ep->pmaadress, (uint16_t)ep->xfer_count); |
|
- | 2161 | ||
1275 | ep->xfer_buff+=ep->xfer_count; |
2162 | ep->xfer_buff += ep->xfer_count; |
- | 2163 | ||
- | 2164 | /* Process Control Data OUT Packet */ |
|
- | 2165 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2166 | hpcd->DataOutStageCallback(hpcd, 0U); |
|
- | 2167 | #else |
|
- | 2168 | HAL_PCD_DataOutStageCallback(hpcd, 0U); |
|
- | 2169 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
1276 | } |
2170 | } |
1277 | - | ||
1278 | /* Process Control Data OUT Packet*/ |
- | |
1279 | HAL_PCD_DataOutStageCallback(hpcd, 0U); |
- | |
1280 | 2171 | ||
1281 | PCD_SET_EP_RX_CNT(hpcd->Instance, PCD_ENDP0, ep->maxpacket); |
2172 | PCD_SET_EP_RX_CNT(hpcd->Instance, PCD_ENDP0, ep->maxpacket); |
1282 | PCD_SET_EP_RX_STATUS(hpcd->Instance, PCD_ENDP0, USB_EP_RX_VALID); |
2173 | PCD_SET_EP_RX_STATUS(hpcd->Instance, PCD_ENDP0, USB_EP_RX_VALID); |
1283 | } |
2174 | } |
1284 | } |
2175 | } |
1285 | } |
2176 | } |
1286 | else |
2177 | else |
1287 | { |
2178 | { |
1288 | /* Decode and service non control endpoints interrupt */ |
2179 | /* Decode and service non control endpoints interrupt */ |
1289 | - | ||
1290 | /* process related endpoint register */ |
2180 | /* process related endpoint register */ |
1291 | wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, epindex); |
2181 | wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, epindex); |
- | 2182 | ||
1292 | if ((wEPVal & USB_EP_CTR_RX) != 0U) |
2183 | if ((wEPVal & USB_EP_CTR_RX) != 0U) |
1293 | { |
2184 | { |
1294 | /* clear int flag */ |
2185 | /* clear int flag */ |
1295 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, epindex); |
2186 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, epindex); |
1296 | ep = &hpcd->OUT_ep[epindex]; |
2187 | ep = &hpcd->OUT_ep[epindex]; |
1297 | 2188 | ||
1298 | /* OUT double Buffering*/ |
2189 | /* OUT Single Buffering */ |
1299 | if (ep->doublebuffer == 0U) |
2190 | if (ep->doublebuffer == 0U) |
1300 | { |
2191 | { |
1301 | count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
2192 | count = (uint16_t)PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
- | 2193 | ||
1302 | if (count != 0U) |
2194 | if (count != 0U) |
1303 | { |
2195 | { |
1304 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count); |
2196 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count); |
1305 | } |
2197 | } |
1306 | } |
2198 | } |
1307 | else |
2199 | else |
1308 | { |
2200 | { |
- | 2201 | /* manage double buffer bulk out */ |
|
1309 | if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX) |
2202 | if (ep->type == EP_TYPE_BULK) |
1310 | { |
2203 | { |
1311 | /*read from endpoint BUF0Addr buffer*/ |
- | |
1312 | count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
2204 | count = HAL_PCD_EP_DB_Receive(hpcd, ep, wEPVal); |
1313 | if (count != 0U) |
- | |
1314 | { |
- | |
1315 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count); |
- | |
1316 | } |
- | |
1317 | } |
2205 | } |
1318 | else |
2206 | else /* manage double buffer iso out */ |
1319 | { |
2207 | { |
1320 | /*read from endpoint BUF1Addr buffer*/ |
2208 | /* free EP OUT Buffer */ |
1321 | count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
2209 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 0U); |
- | 2210 | ||
1322 | if (count != 0U) |
2211 | if ((PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX) != 0U) |
1323 | { |
2212 | { |
- | 2213 | /* read from endpoint BUF0Addr buffer */ |
|
- | 2214 | count = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
|
- | 2215 | ||
- | 2216 | if (count != 0U) |
|
- | 2217 | { |
|
- | 2218 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count); |
|
- | 2219 | } |
|
- | 2220 | } |
|
- | 2221 | else |
|
- | 2222 | { |
|
- | 2223 | /* read from endpoint BUF1Addr buffer */ |
|
- | 2224 | count = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
|
- | 2225 | ||
- | 2226 | if (count != 0U) |
|
- | 2227 | { |
|
1324 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count); |
2228 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count); |
- | 2229 | } |
|
1325 | } |
2230 | } |
1326 | } |
2231 | } |
1327 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_OUT); |
- | |
1328 | } |
2232 | } |
1329 | /*multi-packet on the NON control OUT endpoint*/ |
2233 | /* multi-packet on the NON control OUT endpoint */ |
1330 | ep->xfer_count+=count; |
2234 | ep->xfer_count += count; |
1331 | ep->xfer_buff+=count; |
2235 | ep->xfer_buff += count; |
1332 | 2236 | ||
1333 | if ((ep->xfer_len == 0U) || (count < ep->maxpacket)) |
2237 | if ((ep->xfer_len == 0U) || (count < ep->maxpacket)) |
1334 | { |
2238 | { |
1335 | /* RX COMPLETE */ |
2239 | /* RX COMPLETE */ |
- | 2240 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2241 | hpcd->DataOutStageCallback(hpcd, ep->num); |
|
- | 2242 | #else |
|
1336 | HAL_PCD_DataOutStageCallback(hpcd, ep->num); |
2243 | HAL_PCD_DataOutStageCallback(hpcd, ep->num); |
- | 2244 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
1337 | } |
2245 | } |
1338 | else |
2246 | else |
1339 | { |
2247 | { |
1340 | HAL_PCD_EP_Receive(hpcd, ep->num, ep->xfer_buff, ep->xfer_len); |
2248 | (void) USB_EPStartXfer(hpcd->Instance, ep); |
1341 | } |
2249 | } |
- | 2250 | ||
1342 | 2251 | } |
|
1343 | } /* if((wEPVal & EP_CTR_RX) */ |
- | |
1344 | 2252 | ||
1345 | if ((wEPVal & USB_EP_CTR_TX) != 0U) |
2253 | if ((wEPVal & USB_EP_CTR_TX) != 0U) |
1346 | { |
2254 | { |
1347 | ep = &hpcd->IN_ep[epindex]; |
2255 | ep = &hpcd->IN_ep[epindex]; |
1348 | 2256 | ||
1349 | /* clear int flag */ |
2257 | /* clear int flag */ |
1350 | PCD_CLEAR_TX_EP_CTR(hpcd->Instance, epindex); |
2258 | PCD_CLEAR_TX_EP_CTR(hpcd->Instance, epindex); |
1351 | 2259 | ||
1352 | /* IN double Buffering*/ |
2260 | /* Manage all non bulk transaction or Bulk Single Buffer Transaction */ |
1353 | if (ep->doublebuffer == 0U) |
2261 | if ((ep->type != EP_TYPE_BULK) || |
- | 2262 | ((ep->type == EP_TYPE_BULK) && ((wEPVal & USB_EP_KIND) == 0U))) |
|
1354 | { |
2263 | { |
- | 2264 | /* multi-packet on the NON control IN endpoint */ |
|
1355 | ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
2265 | TxByteNbre = (uint16_t)PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
- | 2266 | ||
1356 | if (ep->xfer_count != 0U) |
2267 | if (ep->xfer_len > TxByteNbre) |
1357 | { |
2268 | { |
1358 | USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count); |
2269 | ep->xfer_len -= TxByteNbre; |
1359 | } |
2270 | } |
1360 | } |
- | |
1361 | else |
2271 | else |
1362 | { |
- | |
1363 | if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_TX) |
- | |
1364 | { |
2272 | { |
1365 | /*read from endpoint BUF0Addr buffer*/ |
2273 | ep->xfer_len = 0U; |
- | 2274 | } |
|
- | 2275 | ||
1366 | ep->xfer_count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
2276 | /* Zero Length Packet? */ |
1367 | if (ep->xfer_count != 0U) |
2277 | if (ep->xfer_len == 0U) |
1368 | { |
2278 | { |
- | 2279 | /* TX COMPLETE */ |
|
- | 2280 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
1369 | USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, ep->xfer_count); |
2281 | hpcd->DataInStageCallback(hpcd, ep->num); |
1370 | } |
2282 | #else |
- | 2283 | HAL_PCD_DataInStageCallback(hpcd, ep->num); |
|
- | 2284 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
1371 | } |
2285 | } |
1372 | else |
2286 | else |
1373 | { |
2287 | { |
1374 | /*read from endpoint BUF1Addr buffer*/ |
2288 | /* Transfer is not yet Done */ |
1375 | ep->xfer_count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
2289 | ep->xfer_buff += TxByteNbre; |
1376 | if (ep->xfer_count != 0U) |
2290 | ep->xfer_count += TxByteNbre; |
1377 | { |
- | |
1378 | USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, ep->xfer_count); |
2291 | (void)USB_EPStartXfer(hpcd->Instance, ep); |
1379 | } |
- | |
1380 | } |
2292 | } |
1381 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_IN); |
- | |
1382 | } |
2293 | } |
- | 2294 | /* bulk in double buffer enable in case of transferLen> Ep_Mps */ |
|
- | 2295 | else |
|
- | 2296 | { |
|
- | 2297 | (void)HAL_PCD_EP_DB_Transmit(hpcd, ep, wEPVal); |
|
- | 2298 | } |
|
- | 2299 | } |
|
- | 2300 | } |
|
- | 2301 | } |
|
- | 2302 | ||
- | 2303 | return HAL_OK; |
|
- | 2304 | } |
|
- | 2305 | ||
- | 2306 | ||
- | 2307 | /** |
|
- | 2308 | * @brief Manage double buffer bulk out transaction from ISR |
|
- | 2309 | * @param hpcd PCD handle |
|
- | 2310 | * @param ep current endpoint handle |
|
- | 2311 | * @param wEPVal Last snapshot of EPRx register value taken in ISR |
|
- | 2312 | * @retval HAL status |
|
- | 2313 | */ |
|
- | 2314 | static uint16_t HAL_PCD_EP_DB_Receive(PCD_HandleTypeDef *hpcd, |
|
- | 2315 | PCD_EPTypeDef *ep, uint16_t wEPVal) |
|
- | 2316 | { |
|
- | 2317 | uint16_t count; |
|
- | 2318 | ||
- | 2319 | /* Manage Buffer0 OUT */ |
|
- | 2320 | if ((wEPVal & USB_EP_DTOG_RX) != 0U) |
|
- | 2321 | { |
|
- | 2322 | /* Get count of received Data on buffer0 */ |
|
- | 2323 | count = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
|
- | 2324 | ||
- | 2325 | if (ep->xfer_len >= count) |
|
- | 2326 | { |
|
- | 2327 | ep->xfer_len -= count; |
|
- | 2328 | } |
|
- | 2329 | else |
|
- | 2330 | { |
|
- | 2331 | ep->xfer_len = 0U; |
|
- | 2332 | } |
|
- | 2333 | ||
- | 2334 | if (ep->xfer_len == 0U) |
|
- | 2335 | { |
|
- | 2336 | /* set NAK to OUT endpoint since double buffer is enabled */ |
|
- | 2337 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_NAK); |
|
- | 2338 | } |
|
- | 2339 | ||
- | 2340 | /* Check if Buffer1 is in blocked sate which requires to toggle */ |
|
- | 2341 | if ((wEPVal & USB_EP_DTOG_TX) != 0U) |
|
- | 2342 | { |
|
- | 2343 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 0U); |
|
- | 2344 | } |
|
- | 2345 | ||
- | 2346 | if (count != 0U) |
|
- | 2347 | { |
|
- | 2348 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count); |
|
- | 2349 | } |
|
- | 2350 | } |
|
- | 2351 | /* Manage Buffer 1 DTOG_RX=0 */ |
|
- | 2352 | else |
|
- | 2353 | { |
|
- | 2354 | /* Get count of received data */ |
|
- | 2355 | count = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
|
- | 2356 | ||
- | 2357 | if (ep->xfer_len >= count) |
|
- | 2358 | { |
|
- | 2359 | ep->xfer_len -= count; |
|
- | 2360 | } |
|
- | 2361 | else |
|
- | 2362 | { |
|
- | 2363 | ep->xfer_len = 0U; |
|
- | 2364 | } |
|
- | 2365 | ||
- | 2366 | if (ep->xfer_len == 0U) |
|
- | 2367 | { |
|
- | 2368 | /* set NAK on the current endpoint */ |
|
- | 2369 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_NAK); |
|
- | 2370 | } |
|
- | 2371 | ||
- | 2372 | /*Need to FreeUser Buffer*/ |
|
- | 2373 | if ((wEPVal & USB_EP_DTOG_TX) == 0U) |
|
- | 2374 | { |
|
- | 2375 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 0U); |
|
- | 2376 | } |
|
- | 2377 | ||
- | 2378 | if (count != 0U) |
|
- | 2379 | { |
|
- | 2380 | USB_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count); |
|
- | 2381 | } |
|
- | 2382 | } |
|
- | 2383 | ||
- | 2384 | return count; |
|
- | 2385 | } |
|
- | 2386 | ||
- | 2387 | ||
- | 2388 | /** |
|
- | 2389 | * @brief Manage double buffer bulk IN transaction from ISR |
|
- | 2390 | * @param hpcd PCD handle |
|
- | 2391 | * @param ep current endpoint handle |
|
- | 2392 | * @param wEPVal Last snapshot of EPRx register value taken in ISR |
|
- | 2393 | * @retval HAL status |
|
- | 2394 | */ |
|
- | 2395 | static HAL_StatusTypeDef HAL_PCD_EP_DB_Transmit(PCD_HandleTypeDef *hpcd, |
|
- | 2396 | PCD_EPTypeDef *ep, uint16_t wEPVal) |
|
- | 2397 | { |
|
- | 2398 | uint32_t len; |
|
- | 2399 | uint16_t TxByteNbre; |
|
- | 2400 | ||
- | 2401 | /* Data Buffer0 ACK received */ |
|
- | 2402 | if ((wEPVal & USB_EP_DTOG_TX) != 0U) |
|
- | 2403 | { |
|
1383 | /*multi-packet on the NON control IN endpoint*/ |
2404 | /* multi-packet on the NON control IN endpoint */ |
1384 | ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
2405 | TxByteNbre = (uint16_t)PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
- | 2406 | ||
- | 2407 | if (ep->xfer_len > TxByteNbre) |
|
- | 2408 | { |
|
1385 | ep->xfer_buff+=ep->xfer_count; |
2409 | ep->xfer_len -= TxByteNbre; |
- | 2410 | } |
|
- | 2411 | else |
|
- | 2412 | { |
|
- | 2413 | ep->xfer_len = 0U; |
|
- | 2414 | } |
|
- | 2415 | /* Transfer is completed */ |
|
- | 2416 | if (ep->xfer_len == 0U) |
|
- | 2417 | { |
|
- | 2418 | /* TX COMPLETE */ |
|
- | 2419 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2420 | hpcd->DataInStageCallback(hpcd, ep->num); |
|
- | 2421 | #else |
|
- | 2422 | HAL_PCD_DataInStageCallback(hpcd, ep->num); |
|
- | 2423 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 2424 | ||
- | 2425 | if ((wEPVal & USB_EP_DTOG_RX) != 0U) |
|
1386 | 2426 | { |
|
- | 2427 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U); |
|
- | 2428 | } |
|
- | 2429 | } |
|
- | 2430 | else /* Transfer is not yet Done */ |
|
- | 2431 | { |
|
1387 | /* Zero Length Packet? */ |
2432 | /* need to Free USB Buff */ |
- | 2433 | if ((wEPVal & USB_EP_DTOG_RX) != 0U) |
|
- | 2434 | { |
|
- | 2435 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U); |
|
- | 2436 | } |
|
- | 2437 | ||
- | 2438 | /* Still there is data to Fill in the next Buffer */ |
|
1388 | if (ep->xfer_len == 0U) |
2439 | if (ep->xfer_fill_db == 1U) |
- | 2440 | { |
|
- | 2441 | ep->xfer_buff += TxByteNbre; |
|
- | 2442 | ep->xfer_count += TxByteNbre; |
|
- | 2443 | ||
- | 2444 | /* Calculate the len of the new buffer to fill */ |
|
- | 2445 | if (ep->xfer_len_db >= ep->maxpacket) |
|
1389 | { |
2446 | { |
- | 2447 | len = ep->maxpacket; |
|
- | 2448 | ep->xfer_len_db -= len; |
|
- | 2449 | } |
|
- | 2450 | else if (ep->xfer_len_db == 0U) |
|
- | 2451 | { |
|
1390 | /* TX COMPLETE */ |
2452 | len = TxByteNbre; |
1391 | HAL_PCD_DataInStageCallback(hpcd, ep->num); |
2453 | ep->xfer_fill_db = 0U; |
1392 | } |
2454 | } |
1393 | else |
2455 | else |
1394 | { |
2456 | { |
- | 2457 | ep->xfer_fill_db = 0U; |
|
1395 | HAL_PCD_EP_Transmit(hpcd, ep->num, ep->xfer_buff, ep->xfer_len); |
2458 | len = ep->xfer_len_db; |
- | 2459 | ep->xfer_len_db = 0U; |
|
1396 | } |
2460 | } |
- | 2461 | ||
- | 2462 | /* Write remaining Data to Buffer */ |
|
- | 2463 | /* Set the Double buffer counter for pma buffer1 */ |
|
- | 2464 | PCD_SET_EP_DBUF0_CNT(hpcd->Instance, ep->num, ep->is_in, len); |
|
- | 2465 | ||
- | 2466 | /* Copy user buffer to USB PMA */ |
|
- | 2467 | USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, (uint16_t)len); |
|
1397 | } |
2468 | } |
1398 | } |
2469 | } |
1399 | } |
2470 | } |
- | 2471 | else /* Data Buffer1 ACK received */ |
|
- | 2472 | { |
|
- | 2473 | /* multi-packet on the NON control IN endpoint */ |
|
- | 2474 | TxByteNbre = (uint16_t)PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
|
- | 2475 | ||
- | 2476 | if (ep->xfer_len >= TxByteNbre) |
|
- | 2477 | { |
|
- | 2478 | ep->xfer_len -= TxByteNbre; |
|
- | 2479 | } |
|
- | 2480 | else |
|
- | 2481 | { |
|
- | 2482 | ep->xfer_len = 0U; |
|
- | 2483 | } |
|
- | 2484 | ||
- | 2485 | /* Transfer is completed */ |
|
- | 2486 | if (ep->xfer_len == 0U) |
|
- | 2487 | { |
|
- | 2488 | /* TX COMPLETE */ |
|
- | 2489 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U) |
|
- | 2490 | hpcd->DataInStageCallback(hpcd, ep->num); |
|
- | 2491 | #else |
|
- | 2492 | HAL_PCD_DataInStageCallback(hpcd, ep->num); |
|
- | 2493 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */ |
|
- | 2494 | ||
- | 2495 | /*need to Free USB Buff*/ |
|
- | 2496 | if ((wEPVal & USB_EP_DTOG_RX) == 0U) |
|
- | 2497 | { |
|
- | 2498 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U); |
|
- | 2499 | } |
|
- | 2500 | } |
|
- | 2501 | else /* Transfer is not yet Done */ |
|
- | 2502 | { |
|
- | 2503 | /* need to Free USB Buff */ |
|
- | 2504 | if ((wEPVal & USB_EP_DTOG_RX) == 0U) |
|
- | 2505 | { |
|
- | 2506 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, 1U); |
|
- | 2507 | } |
|
- | 2508 | ||
- | 2509 | /* Still there is data to Fill in the next Buffer */ |
|
- | 2510 | if (ep->xfer_fill_db == 1U) |
|
- | 2511 | { |
|
- | 2512 | ep->xfer_buff += TxByteNbre; |
|
- | 2513 | ep->xfer_count += TxByteNbre; |
|
- | 2514 | ||
- | 2515 | /* Calculate the len of the new buffer to fill */ |
|
- | 2516 | if (ep->xfer_len_db >= ep->maxpacket) |
|
- | 2517 | { |
|
- | 2518 | len = ep->maxpacket; |
|
- | 2519 | ep->xfer_len_db -= len; |
|
- | 2520 | } |
|
- | 2521 | else if (ep->xfer_len_db == 0U) |
|
- | 2522 | { |
|
- | 2523 | len = TxByteNbre; |
|
- | 2524 | ep->xfer_fill_db = 0U; |
|
- | 2525 | } |
|
- | 2526 | else |
|
- | 2527 | { |
|
- | 2528 | len = ep->xfer_len_db; |
|
- | 2529 | ep->xfer_len_db = 0U; |
|
- | 2530 | ep->xfer_fill_db = 0; |
|
- | 2531 | } |
|
- | 2532 | ||
- | 2533 | /* Set the Double buffer counter for pmabuffer1 */ |
|
- | 2534 | PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, len); |
|
- | 2535 | ||
- | 2536 | /* Copy the user buffer to USB PMA */ |
|
- | 2537 | USB_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, (uint16_t)len); |
|
- | 2538 | } |
|
- | 2539 | } |
|
- | 2540 | } |
|
- | 2541 | ||
- | 2542 | /*enable endpoint IN*/ |
|
- | 2543 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_VALID); |
|
- | 2544 | ||
1400 | return HAL_OK; |
2545 | return HAL_OK; |
1401 | } |
2546 | } |
- | 2547 | ||
1402 | #endif /* USB */ |
2548 | #endif /* defined (USB) */ |
1403 | 2549 | ||
1404 | /** |
2550 | /** |
1405 | * @} |
2551 | * @} |
1406 | */ |
2552 | */ |
- | 2553 | #endif /* defined (USB) || defined (USB_OTG_FS) */ |
|
- | 2554 | #endif /* HAL_PCD_MODULE_ENABLED */ |
|
1407 | 2555 | ||
1408 | /** |
2556 | /** |
1409 | * @} |
2557 | * @} |
1410 | */ |
2558 | */ |
1411 | - | ||
1412 | #endif /* STM32F102x6 || STM32F102xB || */ |
- | |
1413 | /* STM32F103x6 || STM32F103xB || */ |
- | |
1414 | /* STM32F103xE || STM32F103xG || */ |
- | |
1415 | /* STM32F105xC || STM32F107xC */ |
- | |
1416 | - | ||
1417 | #endif /* HAL_PCD_MODULE_ENABLED */ |
- | |
1418 | - | ||
1419 | 2559 | ||
1420 | /** |
2560 | /** |
1421 | * @} |
2561 | * @} |
1422 | */ |
2562 | */ |
1423 | 2563 |