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 usbd_core.c |
3 | * @file usbd_core.c |
| 4 | * @author MCD Application Team |
4 | * @author MCD Application Team |
| 5 | * @version V2.4.2 |
- | |
| 6 | * @date 11-December-2015 |
- | |
| 7 | * @brief This file provides all the USBD core functions. |
5 | * @brief This file provides all the USBD core functions. |
| 8 | ****************************************************************************** |
6 | ****************************************************************************** |
| 9 | * @attention |
7 | * @attention |
| 10 | * |
8 | * |
| 11 | * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> |
9 | * <h2><center>© Copyright (c) 2015 STMicroelectronics. |
| - | 10 | * All rights reserved.</center></h2> |
|
| 12 | * |
11 | * |
| 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
12 | * This software component is licensed by ST under Ultimate Liberty license |
| 14 | * You may not use this file except in compliance with the License. |
13 | * SLA0044, the "License"; You may not use this file except in compliance with |
| 15 | * You may obtain a copy of the License at: |
14 | * the License. You may obtain a copy of the License at: |
| 16 | * |
- | |
| 17 | * http://www.st.com/software_license_agreement_liberty_v2 |
- | |
| 18 | * |
- | |
| 19 | * Unless required by applicable law or agreed to in writing, software |
- | |
| 20 | * distributed under the License is distributed on an "AS IS" BASIS, |
- | |
| 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
- | |
| 22 | * See the License for the specific language governing permissions and |
- | |
| 23 | * limitations under the License. |
15 | * www.st.com/SLA0044 |
| 24 | * |
16 | * |
| 25 | ****************************************************************************** |
17 | ****************************************************************************** |
| 26 | */ |
18 | */ |
| 27 | 19 | ||
| 28 | /* Includes ------------------------------------------------------------------*/ |
20 | /* Includes ------------------------------------------------------------------*/ |
| 29 | #include "usbd_core.h" |
21 | #include "usbd_core.h" |
| 30 | 22 | ||
| 31 | /** @addtogroup STM32_USBD_DEVICE_LIBRARY |
23 | /** @addtogroup STM32_USBD_DEVICE_LIBRARY |
| 32 | * @{ |
24 | * @{ |
| 33 | */ |
25 | */ |
| 34 | 26 | ||
| 35 | 27 | ||
| 36 | /** @defgroup USBD_CORE |
28 | /** @defgroup USBD_CORE |
| 37 | * @brief usbd core module |
29 | * @brief usbd core module |
| 38 | * @{ |
30 | * @{ |
| 39 | */ |
31 | */ |
| 40 | 32 | ||
| 41 | /** @defgroup USBD_CORE_Private_TypesDefinitions |
33 | /** @defgroup USBD_CORE_Private_TypesDefinitions |
| 42 | * @{ |
34 | * @{ |
| 43 | */ |
35 | */ |
| - | 36 | ||
| 44 | /** |
37 | /** |
| 45 | * @} |
38 | * @} |
| 46 | */ |
39 | */ |
| 47 | 40 | ||
| 48 | 41 | ||
| 49 | /** @defgroup USBD_CORE_Private_Defines |
42 | /** @defgroup USBD_CORE_Private_Defines |
| 50 | * @{ |
43 | * @{ |
| 51 | */ |
44 | */ |
| 52 | 45 | ||
| 53 | /** |
46 | /** |
| 54 | * @} |
47 | * @} |
| 55 | */ |
48 | */ |
| 56 | 49 | ||
| 57 | 50 | ||
| 58 | /** @defgroup USBD_CORE_Private_Macros |
51 | /** @defgroup USBD_CORE_Private_Macros |
| 59 | * @{ |
52 | * @{ |
| 60 | */ |
53 | */ |
| - | 54 | ||
| 61 | /** |
55 | /** |
| 62 | * @} |
56 | * @} |
| 63 | */ |
57 | */ |
| 64 | - | ||
| 65 | - | ||
| 66 | 58 | ||
| 67 | 59 | ||
| 68 | /** @defgroup USBD_CORE_Private_FunctionPrototypes |
60 | /** @defgroup USBD_CORE_Private_FunctionPrototypes |
| 69 | * @{ |
61 | * @{ |
| 70 | */ |
62 | */ |
| 71 | 63 | ||
| 72 | /** |
64 | /** |
| 73 | * @} |
65 | * @} |
| 74 | */ |
66 | */ |
| 75 | 67 | ||
| 76 | /** @defgroup USBD_CORE_Private_Variables |
68 | /** @defgroup USBD_CORE_Private_Variables |
| 77 | * @{ |
69 | * @{ |
| 78 | */ |
70 | */ |
| 79 | 71 | ||
| 80 | /** |
72 | /** |
| 81 | * @} |
73 | * @} |
| 82 | */ |
74 | */ |
| - | 75 | ||
| 83 | 76 | ||
| 84 | /** @defgroup USBD_CORE_Private_Functions |
77 | /** @defgroup USBD_CORE_Private_Functions |
| 85 | * @{ |
78 | * @{ |
| 86 | */ |
79 | */ |
| 87 | 80 | ||
| 88 | /** |
81 | /** |
| 89 | * @brief USBD_Init |
82 | * @brief USBD_Init |
| 90 | * Initializes the device stack and load the class driver |
83 | * Initializes the device stack and load the class driver |
| 91 | * @param pdev: device instance |
84 | * @param pdev: device instance |
| 92 | * @param pdesc: Descriptor structure address |
85 | * @param pdesc: Descriptor structure address |
| 93 | * @param id: Low level core index |
86 | * @param id: Low level core index |
| 94 | * @retval None |
87 | * @retval None |
| 95 | */ |
88 | */ |
| 96 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id) |
89 | USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, |
| - | 90 | USBD_DescriptorsTypeDef *pdesc, uint8_t id) |
|
| 97 | { |
91 | { |
| 98 | /* Check whether the USB Host handle is valid */ |
92 | /* Check whether the USB Host handle is valid */ |
| 99 | if(pdev == NULL) |
93 | if (pdev == NULL) |
| 100 | { |
94 | { |
| - | 95 | #if (USBD_DEBUG_LEVEL > 1U) |
|
| 101 | USBD_ErrLog("Invalid Device handle"); |
96 | USBD_ErrLog("Invalid Device handle"); |
| - | 97 | #endif |
|
| 102 | return USBD_FAIL; |
98 | return USBD_FAIL; |
| 103 | } |
99 | } |
| 104 | 100 | ||
| 105 | /* Unlink previous class*/ |
101 | /* Unlink previous class*/ |
| 106 | if(pdev->pClass != NULL) |
102 | if (pdev->pClass != NULL) |
| 107 | { |
103 | { |
| 108 | pdev->pClass = NULL; |
104 | pdev->pClass = NULL; |
| 109 | } |
105 | } |
| 110 | 106 | ||
| 111 | /* Assign USBD Descriptors */ |
107 | /* Assign USBD Descriptors */ |
| 112 | if(pdesc != NULL) |
108 | if (pdesc != NULL) |
| 113 | { |
109 | { |
| 114 | pdev->pDesc = pdesc; |
110 | pdev->pDesc = pdesc; |
| 115 | } |
111 | } |
| 116 | 112 | ||
| 117 | /* Set Device initial State */ |
113 | /* Set Device initial State */ |
| 118 | pdev->dev_state = USBD_STATE_DEFAULT; |
114 | pdev->dev_state = USBD_STATE_DEFAULT; |
| 119 | pdev->id = id; |
115 | pdev->id = id; |
| 120 | /* Initialize low level driver */ |
116 | /* Initialize low level driver */ |
| 121 | USBD_LL_Init(pdev); |
117 | USBD_LL_Init(pdev); |
| 122 | 118 | ||
| 123 | return USBD_OK; |
119 | return USBD_OK; |
| 124 | } |
120 | } |
| 125 | 121 | ||
| 126 | /** |
122 | /** |
| 127 | * @brief USBD_DeInit |
123 | * @brief USBD_DeInit |
| 128 | * Re-Initialize th device library |
124 | * Re-Initialize th device library |
| 129 | * @param pdev: device instance |
125 | * @param pdev: device instance |
| 130 | * @retval status: status |
126 | * @retval status: status |
| 131 | */ |
127 | */ |
| 132 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev) |
128 | USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev) |
| 133 | { |
129 | { |
| 134 | /* Set Default State */ |
130 | /* Set Default State */ |
| 135 | pdev->dev_state = USBD_STATE_DEFAULT; |
131 | pdev->dev_state = USBD_STATE_DEFAULT; |
| 136 | 132 | ||
| 137 | /* Free Class Resources */ |
133 | /* Free Class Resources */ |
| 138 | pdev->pClass->DeInit(pdev, pdev->dev_config); |
134 | pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); |
| 139 | 135 | ||
| 140 | /* Stop the low level driver */ |
136 | /* Stop the low level driver */ |
| 141 | USBD_LL_Stop(pdev); |
137 | USBD_LL_Stop(pdev); |
| 142 | 138 | ||
| 143 | /* Initialize low level driver */ |
139 | /* Initialize low level driver */ |
| 144 | USBD_LL_DeInit(pdev); |
140 | USBD_LL_DeInit(pdev); |
| 145 | 141 | ||
| 146 | return USBD_OK; |
142 | return USBD_OK; |
| 147 | } |
143 | } |
| 148 | 144 | ||
| 149 | - | ||
| 150 | /** |
145 | /** |
| 151 | * @brief USBD_RegisterClass |
146 | * @brief USBD_RegisterClass |
| 152 | * Link class driver to Device Core. |
147 | * Link class driver to Device Core. |
| 153 | * @param pDevice : Device Handle |
148 | * @param pDevice : Device Handle |
| 154 | * @param pclass: Class handle |
149 | * @param pclass: Class handle |
| 155 | * @retval USBD Status |
150 | * @retval USBD Status |
| 156 | */ |
151 | */ |
| 157 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass) |
152 | USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass) |
| 158 | { |
153 | { |
| 159 | USBD_StatusTypeDef status = USBD_OK; |
154 | USBD_StatusTypeDef status = USBD_OK; |
| 160 | if(pclass != 0) |
155 | if (pclass != NULL) |
| 161 | { |
156 | { |
| 162 | /* link the class to the USB Device handle */ |
157 | /* link the class to the USB Device handle */ |
| 163 | pdev->pClass = pclass; |
158 | pdev->pClass = pclass; |
| 164 | status = USBD_OK; |
159 | status = USBD_OK; |
| 165 | } |
160 | } |
| 166 | else |
161 | else |
| 167 | { |
162 | { |
| - | 163 | #if (USBD_DEBUG_LEVEL > 1U) |
|
| 168 | USBD_ErrLog("Invalid Class handle"); |
164 | USBD_ErrLog("Invalid Class handle"); |
| - | 165 | #endif |
|
| 169 | status = USBD_FAIL; |
166 | status = USBD_FAIL; |
| 170 | } |
167 | } |
| 171 | 168 | ||
| 172 | return status; |
169 | return status; |
| 173 | } |
170 | } |
| 174 | 171 | ||
| 175 | /** |
172 | /** |
| 176 | * @brief USBD_Start |
173 | * @brief USBD_Start |
| 177 | * Start the USB Device Core. |
174 | * Start the USB Device Core. |
| 178 | * @param pdev: Device Handle |
175 | * @param pdev: Device Handle |
| 179 | * @retval USBD Status |
176 | * @retval USBD Status |
| 180 | */ |
177 | */ |
| 181 | USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev) |
178 | USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev) |
| 182 | { |
179 | { |
| 183 | - | ||
| 184 | /* Start the low level driver */ |
180 | /* Start the low level driver */ |
| 185 | USBD_LL_Start(pdev); |
181 | USBD_LL_Start(pdev); |
| 186 | 182 | ||
| 187 | return USBD_OK; |
183 | return USBD_OK; |
| 188 | } |
184 | } |
| 189 | 185 | ||
| 190 | /** |
186 | /** |
| 191 | * @brief USBD_Stop |
187 | * @brief USBD_Stop |
| 192 | * Stop the USB Device Core. |
188 | * Stop the USB Device Core. |
| 193 | * @param pdev: Device Handle |
189 | * @param pdev: Device Handle |
| 194 | * @retval USBD Status |
190 | * @retval USBD Status |
| 195 | */ |
191 | */ |
| 196 | USBD_StatusTypeDef USBD_Stop (USBD_HandleTypeDef *pdev) |
192 | USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev) |
| 197 | { |
193 | { |
| 198 | /* Free Class Resources */ |
194 | /* Free Class Resources */ |
| 199 | pdev->pClass->DeInit(pdev, pdev->dev_config); |
195 | pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); |
| 200 | 196 | ||
| 201 | /* Stop the low level driver */ |
197 | /* Stop the low level driver */ |
| 202 | USBD_LL_Stop(pdev); |
198 | USBD_LL_Stop(pdev); |
| 203 | 199 | ||
| 204 | return USBD_OK; |
200 | return USBD_OK; |
| 205 | } |
201 | } |
| 206 | 202 | ||
| 207 | /** |
203 | /** |
| 208 | * @brief USBD_RunTestMode |
204 | * @brief USBD_RunTestMode |
| 209 | * Launch test mode process |
205 | * Launch test mode process |
| 210 | * @param pdev: device instance |
206 | * @param pdev: device instance |
| 211 | * @retval status |
207 | * @retval status |
| 212 | */ |
208 | */ |
| 213 | USBD_StatusTypeDef USBD_RunTestMode (USBD_HandleTypeDef *pdev) |
209 | USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev) |
| 214 | { |
210 | { |
| - | 211 | /* Prevent unused argument compilation warning */ |
|
| - | 212 | UNUSED(pdev); |
|
| - | 213 | ||
| 215 | return USBD_OK; |
214 | return USBD_OK; |
| 216 | } |
215 | } |
| 217 | 216 | ||
| 218 | - | ||
| 219 | /** |
217 | /** |
| 220 | * @brief USBD_SetClassConfig |
218 | * @brief USBD_SetClassConfig |
| 221 | * Configure device and start the interface |
219 | * Configure device and start the interface |
| 222 | * @param pdev: device instance |
220 | * @param pdev: device instance |
| 223 | * @param cfgidx: configuration index |
221 | * @param cfgidx: configuration index |
| 224 | * @retval status |
222 | * @retval status |
| 225 | */ |
223 | */ |
| 226 | 224 | ||
| 227 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
225 | USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
| 228 | { |
226 | { |
| 229 | USBD_StatusTypeDef ret = USBD_FAIL; |
227 | USBD_StatusTypeDef ret = USBD_FAIL; |
| 230 | 228 | ||
| 231 | if(pdev->pClass != NULL) |
229 | if (pdev->pClass != NULL) |
| 232 | { |
230 | { |
| 233 | /* Set configuration and Start the Class*/ |
231 | /* Set configuration and Start the Class*/ |
| 234 | if(pdev->pClass->Init(pdev, cfgidx) == 0) |
232 | if (pdev->pClass->Init(pdev, cfgidx) == 0U) |
| 235 | { |
233 | { |
| 236 | ret = USBD_OK; |
234 | ret = USBD_OK; |
| 237 | } |
235 | } |
| 238 | } |
236 | } |
| - | 237 | ||
| 239 | return ret; |
238 | return ret; |
| 240 | } |
239 | } |
| 241 | 240 | ||
| 242 | /** |
241 | /** |
| 243 | * @brief USBD_ClrClassConfig |
242 | * @brief USBD_ClrClassConfig |
| 244 | * Clear current configuration |
243 | * Clear current configuration |
| 245 | * @param pdev: device instance |
244 | * @param pdev: device instance |
| 246 | * @param cfgidx: configuration index |
245 | * @param cfgidx: configuration index |
| 247 | * @retval status: USBD_StatusTypeDef |
246 | * @retval status: USBD_StatusTypeDef |
| 248 | */ |
247 | */ |
| 249 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
248 | USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) |
| 250 | { |
249 | { |
| 251 | /* Clear configuration and De-initialize the Class process*/ |
250 | /* Clear configuration and De-initialize the Class process*/ |
| 252 | pdev->pClass->DeInit(pdev, cfgidx); |
251 | pdev->pClass->DeInit(pdev, cfgidx); |
| - | 252 | ||
| 253 | return USBD_OK; |
253 | return USBD_OK; |
| 254 | } |
254 | } |
| 255 | 255 | ||
| 256 | 256 | ||
| 257 | /** |
257 | /** |
| 258 | * @brief USBD_SetupStage |
258 | * @brief USBD_SetupStage |
| 259 | * Handle the setup stage |
259 | * Handle the setup stage |
| 260 | * @param pdev: device instance |
260 | * @param pdev: device instance |
| 261 | * @retval status |
261 | * @retval status |
| 262 | */ |
262 | */ |
| 263 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup) |
263 | USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup) |
| 264 | { |
264 | { |
| 265 | - | ||
| 266 | USBD_ParseSetupRequest(&pdev->request, psetup); |
265 | USBD_ParseSetupRequest(&pdev->request, psetup); |
| 267 | 266 | ||
| 268 | pdev->ep0_state = USBD_EP0_SETUP; |
267 | pdev->ep0_state = USBD_EP0_SETUP; |
| - | 268 | ||
| 269 | pdev->ep0_data_len = pdev->request.wLength; |
269 | pdev->ep0_data_len = pdev->request.wLength; |
| 270 | 270 | ||
| 271 | switch (pdev->request.bmRequest & 0x1F) |
271 | switch (pdev->request.bmRequest & 0x1FU) |
| 272 | { |
272 | { |
| 273 | case USB_REQ_RECIPIENT_DEVICE: |
273 | case USB_REQ_RECIPIENT_DEVICE: |
| 274 | USBD_StdDevReq (pdev, &pdev->request); |
274 | USBD_StdDevReq(pdev, &pdev->request); |
| 275 | break; |
275 | break; |
| 276 | 276 | ||
| 277 | case USB_REQ_RECIPIENT_INTERFACE: |
277 | case USB_REQ_RECIPIENT_INTERFACE: |
| 278 | USBD_StdItfReq(pdev, &pdev->request); |
278 | USBD_StdItfReq(pdev, &pdev->request); |
| 279 | break; |
279 | break; |
| 280 | 280 | ||
| 281 | case USB_REQ_RECIPIENT_ENDPOINT: |
281 | case USB_REQ_RECIPIENT_ENDPOINT: |
| 282 | USBD_StdEPReq(pdev, &pdev->request); |
282 | USBD_StdEPReq(pdev, &pdev->request); |
| 283 | break; |
283 | break; |
| 284 | 284 | ||
| 285 | default: |
285 | default: |
| 286 | USBD_LL_StallEP(pdev , pdev->request.bmRequest & 0x80); |
286 | USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U)); |
| 287 | break; |
287 | break; |
| 288 | } |
288 | } |
| - | 289 | ||
| 289 | return USBD_OK; |
290 | return USBD_OK; |
| 290 | } |
291 | } |
| 291 | 292 | ||
| 292 | /** |
293 | /** |
| 293 | * @brief USBD_DataOutStage |
294 | * @brief USBD_DataOutStage |
| 294 | * Handle data OUT stage |
295 | * Handle data OUT stage |
| 295 | * @param pdev: device instance |
296 | * @param pdev: device instance |
| 296 | * @param epnum: endpoint index |
297 | * @param epnum: endpoint index |
| 297 | * @retval status |
298 | * @retval status |
| 298 | */ |
299 | */ |
| 299 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata) |
300 | USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, |
| - | 301 | uint8_t epnum, uint8_t *pdata) |
|
| 300 | { |
302 | { |
| 301 | USBD_EndpointTypeDef *pep; |
303 | USBD_EndpointTypeDef *pep; |
| 302 | 304 | ||
| 303 | if(epnum == 0) |
305 | if (epnum == 0U) |
| 304 | { |
306 | { |
| 305 | pep = &pdev->ep_out[0]; |
307 | pep = &pdev->ep_out[0]; |
| 306 | 308 | ||
| 307 | if ( pdev->ep0_state == USBD_EP0_DATA_OUT) |
309 | if (pdev->ep0_state == USBD_EP0_DATA_OUT) |
| 308 | { |
310 | { |
| 309 | if(pep->rem_length > pep->maxpacket) |
311 | if (pep->rem_length > pep->maxpacket) |
| 310 | { |
312 | { |
| 311 | pep->rem_length -= pep->maxpacket; |
313 | pep->rem_length -= pep->maxpacket; |
| 312 | 314 | ||
| 313 | USBD_CtlContinueRx (pdev, |
315 | USBD_CtlContinueRx(pdev, pdata, |
| 314 | pdata, |
- | |
| 315 | MIN(pep->rem_length ,pep->maxpacket)); |
316 | (uint16_t)MIN(pep->rem_length, pep->maxpacket)); |
| 316 | } |
317 | } |
| 317 | else |
318 | else |
| 318 | { |
319 | { |
| 319 | if((pdev->pClass->EP0_RxReady != NULL)&& |
320 | if ((pdev->pClass->EP0_RxReady != NULL) && |
| 320 | (pdev->dev_state == USBD_STATE_CONFIGURED)) |
321 | (pdev->dev_state == USBD_STATE_CONFIGURED)) |
| 321 | { |
322 | { |
| 322 | pdev->pClass->EP0_RxReady(pdev); |
323 | pdev->pClass->EP0_RxReady(pdev); |
| 323 | } |
324 | } |
| 324 | USBD_CtlSendStatus(pdev); |
325 | USBD_CtlSendStatus(pdev); |
| 325 | } |
326 | } |
| 326 | } |
327 | } |
| - | 328 | else |
|
| - | 329 | { |
|
| - | 330 | if (pdev->ep0_state == USBD_EP0_STATUS_OUT) |
|
| - | 331 | { |
|
| - | 332 | /* |
|
| - | 333 | * STATUS PHASE completed, update ep0_state to idle |
|
| - | 334 | */ |
|
| - | 335 | pdev->ep0_state = USBD_EP0_IDLE; |
|
| - | 336 | USBD_LL_StallEP(pdev, 0U); |
|
| - | 337 | } |
|
| - | 338 | } |
|
| - | 339 | } |
|
| - | 340 | else if ((pdev->pClass->DataOut != NULL) && |
|
| - | 341 | (pdev->dev_state == USBD_STATE_CONFIGURED)) |
|
| - | 342 | { |
|
| - | 343 | pdev->pClass->DataOut(pdev, epnum); |
|
| 327 | } |
344 | } |
| 328 | else if((pdev->pClass->DataOut != NULL)&& |
345 | else |
| 329 | (pdev->dev_state == USBD_STATE_CONFIGURED)) |
- | |
| 330 | { |
346 | { |
| 331 | pdev->pClass->DataOut(pdev, epnum); |
347 | /* should never be in this condition */ |
| - | 348 | return USBD_FAIL; |
|
| 332 | } |
349 | } |
| - | 350 | ||
| 333 | return USBD_OK; |
351 | return USBD_OK; |
| 334 | } |
352 | } |
| 335 | 353 | ||
| 336 | /** |
354 | /** |
| 337 | * @brief USBD_DataInStage |
355 | * @brief USBD_DataInStage |
| 338 | * Handle data in stage |
356 | * Handle data in stage |
| 339 | * @param pdev: device instance |
357 | * @param pdev: device instance |
| 340 | * @param epnum: endpoint index |
358 | * @param epnum: endpoint index |
| 341 | * @retval status |
359 | * @retval status |
| 342 | */ |
360 | */ |
| 343 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev ,uint8_t epnum, uint8_t *pdata) |
361 | USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, |
| - | 362 | uint8_t epnum, uint8_t *pdata) |
|
| 344 | { |
363 | { |
| 345 | USBD_EndpointTypeDef *pep; |
364 | USBD_EndpointTypeDef *pep; |
| 346 | 365 | ||
| 347 | if(epnum == 0) |
366 | if (epnum == 0U) |
| 348 | { |
367 | { |
| 349 | pep = &pdev->ep_in[0]; |
368 | pep = &pdev->ep_in[0]; |
| 350 | 369 | ||
| 351 | if ( pdev->ep0_state == USBD_EP0_DATA_IN) |
370 | if (pdev->ep0_state == USBD_EP0_DATA_IN) |
| 352 | { |
371 | { |
| 353 | if(pep->rem_length > pep->maxpacket) |
372 | if (pep->rem_length > pep->maxpacket) |
| 354 | { |
373 | { |
| 355 | pep->rem_length -= pep->maxpacket; |
374 | pep->rem_length -= pep->maxpacket; |
| 356 | 375 | ||
| 357 | USBD_CtlContinueSendData (pdev, |
376 | USBD_CtlContinueSendData(pdev, pdata, (uint16_t)pep->rem_length); |
| 358 | pdata, |
- | |
| 359 | pep->rem_length); |
- | |
| 360 | 377 | ||
| 361 | /* Prepare endpoint for premature end of transfer */ |
378 | /* Prepare endpoint for premature end of transfer */ |
| 362 | USBD_LL_PrepareReceive (pdev, |
379 | USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); |
| 363 | 0, |
- | |
| 364 | NULL, |
- | |
| 365 | 0); |
- | |
| 366 | } |
380 | } |
| 367 | else |
381 | else |
| - | 382 | { |
|
| 368 | { /* last packet is MPS multiple, so send ZLP packet */ |
383 | /* last packet is MPS multiple, so send ZLP packet */ |
| 369 | if((pep->total_length % pep->maxpacket == 0) && |
384 | if ((pep->total_length % pep->maxpacket == 0U) && |
| 370 | (pep->total_length >= pep->maxpacket) && |
385 | (pep->total_length >= pep->maxpacket) && |
| 371 | (pep->total_length < pdev->ep0_data_len )) |
386 | (pep->total_length < pdev->ep0_data_len)) |
| 372 | { |
387 | { |
| 373 | - | ||
| 374 | USBD_CtlContinueSendData(pdev , NULL, 0); |
388 | USBD_CtlContinueSendData(pdev, NULL, 0U); |
| 375 | pdev->ep0_data_len = 0; |
389 | pdev->ep0_data_len = 0U; |
| 376 | 390 | ||
| 377 | /* Prepare endpoint for premature end of transfer */ |
391 | /* Prepare endpoint for premature end of transfer */ |
| 378 | USBD_LL_PrepareReceive (pdev, |
392 | USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U); |
| 379 | 0, |
- | |
| 380 | NULL, |
- | |
| 381 | 0); |
- | |
| 382 | } |
393 | } |
| 383 | else |
394 | else |
| 384 | { |
395 | { |
| 385 | if((pdev->pClass->EP0_TxSent != NULL)&& |
396 | if ((pdev->pClass->EP0_TxSent != NULL) && |
| 386 | (pdev->dev_state == USBD_STATE_CONFIGURED)) |
397 | (pdev->dev_state == USBD_STATE_CONFIGURED)) |
| 387 | { |
398 | { |
| 388 | pdev->pClass->EP0_TxSent(pdev); |
399 | pdev->pClass->EP0_TxSent(pdev); |
| 389 | } |
400 | } |
| - | 401 | USBD_LL_StallEP(pdev, 0x80U); |
|
| 390 | USBD_CtlReceiveStatus(pdev); |
402 | USBD_CtlReceiveStatus(pdev); |
| 391 | } |
403 | } |
| 392 | } |
404 | } |
| 393 | } |
405 | } |
| 394 | if (pdev->dev_test_mode == 1) |
406 | else |
| 395 | { |
407 | { |
| - | 408 | if ((pdev->ep0_state == USBD_EP0_STATUS_IN) || |
|
| 396 | USBD_RunTestMode(pdev); |
409 | (pdev->ep0_state == USBD_EP0_IDLE)) |
| - | 410 | { |
|
| 397 | pdev->dev_test_mode = 0; |
411 | USBD_LL_StallEP(pdev, 0x80U); |
| - | 412 | } |
|
| 398 | } |
413 | } |
| - | 414 | ||
| - | 415 | if (pdev->dev_test_mode == 1U) |
|
| - | 416 | { |
|
| - | 417 | USBD_RunTestMode(pdev); |
|
| - | 418 | pdev->dev_test_mode = 0U; |
|
| - | 419 | } |
|
| - | 420 | } |
|
| - | 421 | else if ((pdev->pClass->DataIn != NULL) && |
|
| - | 422 | (pdev->dev_state == USBD_STATE_CONFIGURED)) |
|
| - | 423 | { |
|
| - | 424 | pdev->pClass->DataIn(pdev, epnum); |
|
| 399 | } |
425 | } |
| 400 | else if((pdev->pClass->DataIn != NULL)&& |
426 | else |
| 401 | (pdev->dev_state == USBD_STATE_CONFIGURED)) |
- | |
| 402 | { |
427 | { |
| 403 | pdev->pClass->DataIn(pdev, epnum); |
428 | /* should never be in this condition */ |
| - | 429 | return USBD_FAIL; |
|
| 404 | } |
430 | } |
| - | 431 | ||
| 405 | return USBD_OK; |
432 | return USBD_OK; |
| 406 | } |
433 | } |
| 407 | 434 | ||
| 408 | /** |
435 | /** |
| 409 | * @brief USBD_LL_Reset |
436 | * @brief USBD_LL_Reset |
| 410 | * Handle Reset event |
437 | * Handle Reset event |
| 411 | * @param pdev: device instance |
438 | * @param pdev: device instance |
| 412 | * @retval status |
439 | * @retval status |
| 413 | */ |
440 | */ |
| 414 | 441 | ||
| 415 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev) |
442 | USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev) |
| 416 | { |
443 | { |
| 417 | /* Open EP0 OUT */ |
444 | /* Open EP0 OUT */ |
| 418 | USBD_LL_OpenEP(pdev, |
- | |
| 419 | 0x00, |
- | |
| 420 | USBD_EP_TYPE_CTRL, |
445 | USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); |
| 421 | USB_MAX_EP0_SIZE); |
446 | pdev->ep_out[0x00U & 0xFU].is_used = 1U; |
| 422 | 447 | ||
| 423 | pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE; |
448 | pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE; |
| 424 | 449 | ||
| 425 | /* Open EP0 IN */ |
450 | /* Open EP0 IN */ |
| 426 | USBD_LL_OpenEP(pdev, |
- | |
| 427 | 0x80, |
- | |
| 428 | USBD_EP_TYPE_CTRL, |
451 | USBD_LL_OpenEP(pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE); |
| 429 | USB_MAX_EP0_SIZE); |
452 | pdev->ep_in[0x80U & 0xFU].is_used = 1U; |
| 430 | 453 | ||
| 431 | pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE; |
454 | pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE; |
| - | 455 | ||
| 432 | /* Upon Reset call user call back */ |
456 | /* Upon Reset call user call back */ |
| 433 | pdev->dev_state = USBD_STATE_DEFAULT; |
457 | pdev->dev_state = USBD_STATE_DEFAULT; |
| 434 | - | ||
| 435 | if (pdev->pClassData) |
458 | pdev->ep0_state = USBD_EP0_IDLE; |
| 436 | pdev->pClass->DeInit(pdev, pdev->dev_config); |
459 | pdev->dev_config = 0U; |
| 437 | - | ||
| 438 | - | ||
| 439 | return USBD_OK; |
460 | pdev->dev_remote_wakeup = 0U; |
| 440 | } |
- | |
| 441 | - | ||
| 442 | 461 | ||
| - | 462 | if (pdev->pClassData) |
|
| - | 463 | { |
|
| - | 464 | pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); |
|
| - | 465 | } |
|
| 443 | 466 | ||
| - | 467 | return USBD_OK; |
|
| - | 468 | } |
|
| 444 | 469 | ||
| 445 | /** |
470 | /** |
| 446 | * @brief USBD_LL_Reset |
471 | * @brief USBD_LL_Reset |
| 447 | * Handle Reset event |
472 | * Handle Reset event |
| 448 | * @param pdev: device instance |
473 | * @param pdev: device instance |
| 449 | * @retval status |
474 | * @retval status |
| 450 | */ |
475 | */ |
| 451 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed) |
476 | USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, |
| - | 477 | USBD_SpeedTypeDef speed) |
|
| 452 | { |
478 | { |
| 453 | pdev->dev_speed = speed; |
479 | pdev->dev_speed = speed; |
| - | 480 | ||
| 454 | return USBD_OK; |
481 | return USBD_OK; |
| 455 | } |
482 | } |
| 456 | 483 | ||
| 457 | /** |
484 | /** |
| 458 | * @brief USBD_Suspend |
485 | * @brief USBD_Suspend |
| 459 | * Handle Suspend event |
486 | * Handle Suspend event |
| 460 | * @param pdev: device instance |
487 | * @param pdev: device instance |
| 461 | * @retval status |
488 | * @retval status |
| 462 | */ |
489 | */ |
| 463 | 490 | ||
| 464 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev) |
491 | USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev) |
| 465 | { |
492 | { |
| 466 | pdev->dev_old_state = pdev->dev_state; |
493 | pdev->dev_old_state = pdev->dev_state; |
| 467 | pdev->dev_state = USBD_STATE_SUSPENDED; |
494 | pdev->dev_state = USBD_STATE_SUSPENDED; |
| - | 495 | ||
| 468 | return USBD_OK; |
496 | return USBD_OK; |
| 469 | } |
497 | } |
| 470 | 498 | ||
| 471 | /** |
499 | /** |
| 472 | * @brief USBD_Resume |
500 | * @brief USBD_Resume |
| 473 | * Handle Resume event |
501 | * Handle Resume event |
| 474 | * @param pdev: device instance |
502 | * @param pdev: device instance |
| 475 | * @retval status |
503 | * @retval status |
| 476 | */ |
504 | */ |
| 477 | 505 | ||
| 478 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev) |
506 | USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev) |
| 479 | { |
507 | { |
| - | 508 | if (pdev->dev_state == USBD_STATE_SUSPENDED) |
|
| - | 509 | { |
|
| 480 | pdev->dev_state = pdev->dev_old_state; |
510 | pdev->dev_state = pdev->dev_old_state; |
| - | 511 | } |
|
| - | 512 | ||
| 481 | return USBD_OK; |
513 | return USBD_OK; |
| 482 | } |
514 | } |
| 483 | 515 | ||
| 484 | /** |
516 | /** |
| 485 | * @brief USBD_SOF |
517 | * @brief USBD_SOF |
| 486 | * Handle SOF event |
518 | * Handle SOF event |
| 487 | * @param pdev: device instance |
519 | * @param pdev: device instance |
| 488 | * @retval status |
520 | * @retval status |
| 489 | */ |
521 | */ |
| 490 | 522 | ||
| 491 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev) |
523 | USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev) |
| 492 | { |
524 | { |
| 493 | if(pdev->dev_state == USBD_STATE_CONFIGURED) |
525 | if (pdev->dev_state == USBD_STATE_CONFIGURED) |
| 494 | { |
526 | { |
| 495 | if(pdev->pClass->SOF != NULL) |
527 | if (pdev->pClass->SOF != NULL) |
| 496 | { |
528 | { |
| 497 | pdev->pClass->SOF(pdev); |
529 | pdev->pClass->SOF(pdev); |
| 498 | } |
530 | } |
| 499 | } |
531 | } |
| - | 532 | ||
| 500 | return USBD_OK; |
533 | return USBD_OK; |
| 501 | } |
534 | } |
| 502 | 535 | ||
| 503 | /** |
536 | /** |
| 504 | * @brief USBD_IsoINIncomplete |
537 | * @brief USBD_IsoINIncomplete |
| 505 | * Handle iso in incomplete event |
538 | * Handle iso in incomplete event |
| 506 | * @param pdev: device instance |
539 | * @param pdev: device instance |
| 507 | * @retval status |
540 | * @retval status |
| 508 | */ |
541 | */ |
| 509 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) |
542 | USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, |
| - | 543 | uint8_t epnum) |
|
| 510 | { |
544 | { |
| - | 545 | /* Prevent unused arguments compilation warning */ |
|
| - | 546 | UNUSED(pdev); |
|
| - | 547 | UNUSED(epnum); |
|
| - | 548 | ||
| 511 | return USBD_OK; |
549 | return USBD_OK; |
| 512 | } |
550 | } |
| 513 | 551 | ||
| 514 | /** |
552 | /** |
| 515 | * @brief USBD_IsoOUTIncomplete |
553 | * @brief USBD_IsoOUTIncomplete |
| 516 | * Handle iso out incomplete event |
554 | * Handle iso out incomplete event |
| 517 | * @param pdev: device instance |
555 | * @param pdev: device instance |
| 518 | * @retval status |
556 | * @retval status |
| 519 | */ |
557 | */ |
| 520 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum) |
558 | USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, |
| - | 559 | uint8_t epnum) |
|
| 521 | { |
560 | { |
| - | 561 | /* Prevent unused arguments compilation warning */ |
|
| - | 562 | UNUSED(pdev); |
|
| - | 563 | UNUSED(epnum); |
|
| - | 564 | ||
| 522 | return USBD_OK; |
565 | return USBD_OK; |
| 523 | } |
566 | } |
| 524 | 567 | ||
| 525 | /** |
568 | /** |
| 526 | * @brief USBD_DevConnected |
569 | * @brief USBD_DevConnected |
| 527 | * Handle device connection event |
570 | * Handle device connection event |
| 528 | * @param pdev: device instance |
571 | * @param pdev: device instance |
| 529 | * @retval status |
572 | * @retval status |
| 530 | */ |
573 | */ |
| 531 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev) |
574 | USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev) |
| 532 | { |
575 | { |
| - | 576 | /* Prevent unused argument compilation warning */ |
|
| - | 577 | UNUSED(pdev); |
|
| - | 578 | ||
| 533 | return USBD_OK; |
579 | return USBD_OK; |
| 534 | } |
580 | } |
| 535 | 581 | ||
| 536 | /** |
582 | /** |
| 537 | * @brief USBD_DevDisconnected |
583 | * @brief USBD_DevDisconnected |
| 538 | * Handle device disconnection event |
584 | * Handle device disconnection event |
| 539 | * @param pdev: device instance |
585 | * @param pdev: device instance |
| 540 | * @retval status |
586 | * @retval status |
| 541 | */ |
587 | */ |
| 542 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev) |
588 | USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev) |
| 543 | { |
589 | { |
| 544 | /* Free Class Resources */ |
590 | /* Free Class Resources */ |
| 545 | pdev->dev_state = USBD_STATE_DEFAULT; |
591 | pdev->dev_state = USBD_STATE_DEFAULT; |
| 546 | pdev->pClass->DeInit(pdev, pdev->dev_config); |
592 | pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config); |
| 547 | 593 | ||
| 548 | return USBD_OK; |
594 | return USBD_OK; |
| 549 | } |
595 | } |
| 550 | /** |
596 | /** |
| 551 | * @} |
597 | * @} |
| 552 | */ |
598 | */ |
| 553 | 599 | ||
| 554 | 600 | ||
| 555 | /** |
601 | /** |
| 556 | * @} |
602 | * @} |
| 557 | */ |
603 | */ |
| 558 | 604 | ||
| 559 | 605 | ||
| 560 | /** |
606 | /** |
| 561 | * @} |
607 | * @} |
| 562 | */ |
608 | */ |
| 563 | 609 | ||
| 564 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
610 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
| 565 | 611 | ||