1 | /* USER CODE BEGIN Header */
|
---|
2 | /**
|
---|
3 | ******************************************************************************
|
---|
4 | * @file : Target/usbd_conf.c
|
---|
5 | * @version : v1.0_Cube
|
---|
6 | * @brief : This file implements the board support package for the USB device library
|
---|
7 | ******************************************************************************
|
---|
8 | * @attention
|
---|
9 | *
|
---|
10 | * <h2><center>© Copyright (c) 2021 STMicroelectronics.
|
---|
11 | * All rights reserved.</center></h2>
|
---|
12 | *
|
---|
13 | * This software component is licensed by ST under Ultimate Liberty license
|
---|
14 | * SLA0044, the "License"; You may not use this file except in compliance with
|
---|
15 | * the License. You may obtain a copy of the License at:
|
---|
16 | * www.st.com/SLA0044
|
---|
17 | *
|
---|
18 | ******************************************************************************
|
---|
19 | */
|
---|
20 | /* USER CODE END Header */
|
---|
21 |
|
---|
22 | /* Includes ------------------------------------------------------------------*/
|
---|
23 | #include "stm32f4xx.h"
|
---|
24 | #include "stm32f4xx_hal.h"
|
---|
25 | #include "usbd_def.h"
|
---|
26 | #include "usbd_core.h"
|
---|
27 |
|
---|
28 | #include "usbd_cdc.h"
|
---|
29 |
|
---|
30 | /* USER CODE BEGIN Includes */
|
---|
31 |
|
---|
32 | /* USER CODE END Includes */
|
---|
33 |
|
---|
34 | /* Private typedef -----------------------------------------------------------*/
|
---|
35 | /* Private define ------------------------------------------------------------*/
|
---|
36 | /* Private macro -------------------------------------------------------------*/
|
---|
37 |
|
---|
38 | /* USER CODE BEGIN PV */
|
---|
39 | /* Private variables ---------------------------------------------------------*/
|
---|
40 |
|
---|
41 | /* USER CODE END PV */
|
---|
42 |
|
---|
43 | PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
---|
44 | void Error_Handler(void);
|
---|
45 |
|
---|
46 | /* External functions --------------------------------------------------------*/
|
---|
47 | void SystemClock_Config(void);
|
---|
48 |
|
---|
49 | /* USER CODE BEGIN 0 */
|
---|
50 |
|
---|
51 | /* USER CODE END 0 */
|
---|
52 |
|
---|
53 | /* USER CODE BEGIN PFP */
|
---|
54 | /* Private function prototypes -----------------------------------------------*/
|
---|
55 | USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status);
|
---|
56 |
|
---|
57 | /* USER CODE END PFP */
|
---|
58 |
|
---|
59 | /* Private functions ---------------------------------------------------------*/
|
---|
60 |
|
---|
61 | /* USER CODE BEGIN 1 */
|
---|
62 |
|
---|
63 | /* USER CODE END 1 */
|
---|
64 |
|
---|
65 | /*******************************************************************************
|
---|
66 | LL Driver Callbacks (PCD -> USB Device Library)
|
---|
67 | *******************************************************************************/
|
---|
68 | /* MSP Init */
|
---|
69 |
|
---|
70 | void HAL_PCD_MspInit(PCD_HandleTypeDef* pcdHandle)
|
---|
71 | {
|
---|
72 | GPIO_InitTypeDef GPIO_InitStruct = {0};
|
---|
73 | if(pcdHandle->Instance==USB_OTG_FS)
|
---|
74 | {
|
---|
75 | /* USER CODE BEGIN USB_OTG_FS_MspInit 0 */
|
---|
76 |
|
---|
77 | /* USER CODE END USB_OTG_FS_MspInit 0 */
|
---|
78 |
|
---|
79 | __HAL_RCC_GPIOA_CLK_ENABLE();
|
---|
80 | /**USB_OTG_FS GPIO Configuration
|
---|
81 | PA11 ------> USB_OTG_FS_DM
|
---|
82 | PA12 ------> USB_OTG_FS_DP
|
---|
83 | */
|
---|
84 | GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12;
|
---|
85 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
---|
86 | GPIO_InitStruct.Pull = GPIO_NOPULL;
|
---|
87 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
---|
88 | GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
---|
89 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
---|
90 |
|
---|
91 | /* Peripheral clock enable */
|
---|
92 | __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
|
---|
93 |
|
---|
94 | /* Peripheral interrupt init */
|
---|
95 | HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0);
|
---|
96 | HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
|
---|
97 | /* USER CODE BEGIN USB_OTG_FS_MspInit 1 */
|
---|
98 |
|
---|
99 | /* USER CODE END USB_OTG_FS_MspInit 1 */
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | void HAL_PCD_MspDeInit(PCD_HandleTypeDef* pcdHandle)
|
---|
104 | {
|
---|
105 | if(pcdHandle->Instance==USB_OTG_FS)
|
---|
106 | {
|
---|
107 | /* USER CODE BEGIN USB_OTG_FS_MspDeInit 0 */
|
---|
108 |
|
---|
109 | /* USER CODE END USB_OTG_FS_MspDeInit 0 */
|
---|
110 | /* Peripheral clock disable */
|
---|
111 | __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
|
---|
112 |
|
---|
113 | /**USB_OTG_FS GPIO Configuration
|
---|
114 | PA11 ------> USB_OTG_FS_DM
|
---|
115 | PA12 ------> USB_OTG_FS_DP
|
---|
116 | */
|
---|
117 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);
|
---|
118 |
|
---|
119 | /* Peripheral interrupt Deinit*/
|
---|
120 | HAL_NVIC_DisableIRQ(OTG_FS_IRQn);
|
---|
121 |
|
---|
122 | /* USER CODE BEGIN USB_OTG_FS_MspDeInit 1 */
|
---|
123 |
|
---|
124 | /* USER CODE END USB_OTG_FS_MspDeInit 1 */
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * @brief Setup stage callback
|
---|
130 | * @param hpcd: PCD handle
|
---|
131 | * @retval None
|
---|
132 | */
|
---|
133 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
134 | static void PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
|
---|
135 | #else
|
---|
136 | void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
|
---|
137 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
138 | {
|
---|
139 | USBD_LL_SetupStage((USBD_HandleTypeDef*)hpcd->pData, (uint8_t *)hpcd->Setup);
|
---|
140 | }
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * @brief Data Out stage callback.
|
---|
144 | * @param hpcd: PCD handle
|
---|
145 | * @param epnum: Endpoint number
|
---|
146 | * @retval None
|
---|
147 | */
|
---|
148 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
149 | static void PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
---|
150 | #else
|
---|
151 | void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
---|
152 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
153 | {
|
---|
154 | USBD_LL_DataOutStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->OUT_ep[epnum].xfer_buff);
|
---|
155 | }
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * @brief Data In stage callback.
|
---|
159 | * @param hpcd: PCD handle
|
---|
160 | * @param epnum: Endpoint number
|
---|
161 | * @retval None
|
---|
162 | */
|
---|
163 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
164 | static void PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
---|
165 | #else
|
---|
166 | void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
---|
167 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
168 | {
|
---|
169 | USBD_LL_DataInStage((USBD_HandleTypeDef*)hpcd->pData, epnum, hpcd->IN_ep[epnum].xfer_buff);
|
---|
170 | }
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * @brief SOF callback.
|
---|
174 | * @param hpcd: PCD handle
|
---|
175 | * @retval None
|
---|
176 | */
|
---|
177 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
178 | static void PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
|
---|
179 | #else
|
---|
180 | void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
|
---|
181 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
182 | {
|
---|
183 | USBD_LL_SOF((USBD_HandleTypeDef*)hpcd->pData);
|
---|
184 | }
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * @brief Reset callback.
|
---|
188 | * @param hpcd: PCD handle
|
---|
189 | * @retval None
|
---|
190 | */
|
---|
191 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
192 | static void PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
|
---|
193 | #else
|
---|
194 | void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
|
---|
195 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
196 | {
|
---|
197 | USBD_SpeedTypeDef speed = USBD_SPEED_FULL;
|
---|
198 |
|
---|
199 | if ( hpcd->Init.speed == PCD_SPEED_HIGH)
|
---|
200 | {
|
---|
201 | speed = USBD_SPEED_HIGH;
|
---|
202 | }
|
---|
203 | else if ( hpcd->Init.speed == PCD_SPEED_FULL)
|
---|
204 | {
|
---|
205 | speed = USBD_SPEED_FULL;
|
---|
206 | }
|
---|
207 | else
|
---|
208 | {
|
---|
209 | Error_Handler();
|
---|
210 | }
|
---|
211 | /* Set Speed. */
|
---|
212 | USBD_LL_SetSpeed((USBD_HandleTypeDef*)hpcd->pData, speed);
|
---|
213 |
|
---|
214 | /* Reset Device. */
|
---|
215 | USBD_LL_Reset((USBD_HandleTypeDef*)hpcd->pData);
|
---|
216 | }
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * @brief Suspend callback.
|
---|
220 | * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
|
---|
221 | * @param hpcd: PCD handle
|
---|
222 | * @retval None
|
---|
223 | */
|
---|
224 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
225 | static void PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
|
---|
226 | #else
|
---|
227 | void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
|
---|
228 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
229 | {
|
---|
230 | /* Inform USB library that core enters in suspend Mode. */
|
---|
231 | USBD_LL_Suspend((USBD_HandleTypeDef*)hpcd->pData);
|
---|
232 | __HAL_PCD_GATE_PHYCLOCK(hpcd);
|
---|
233 | /* Enter in STOP mode. */
|
---|
234 | /* USER CODE BEGIN 2 */
|
---|
235 | if (hpcd->Init.low_power_enable)
|
---|
236 | {
|
---|
237 | /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */
|
---|
238 | SCB->SCR |= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk));
|
---|
239 | }
|
---|
240 | /* USER CODE END 2 */
|
---|
241 | }
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * @brief Resume callback.
|
---|
245 | * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
|
---|
246 | * @param hpcd: PCD handle
|
---|
247 | * @retval None
|
---|
248 | */
|
---|
249 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
250 | static void PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
|
---|
251 | #else
|
---|
252 | void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
|
---|
253 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
254 | {
|
---|
255 | /* USER CODE BEGIN 3 */
|
---|
256 |
|
---|
257 | /* USER CODE END 3 */
|
---|
258 | USBD_LL_Resume((USBD_HandleTypeDef*)hpcd->pData);
|
---|
259 | }
|
---|
260 |
|
---|
261 | /**
|
---|
262 | * @brief ISOOUTIncomplete callback.
|
---|
263 | * @param hpcd: PCD handle
|
---|
264 | * @param epnum: Endpoint number
|
---|
265 | * @retval None
|
---|
266 | */
|
---|
267 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
268 | static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
---|
269 | #else
|
---|
270 | void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
---|
271 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
272 | {
|
---|
273 | USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum);
|
---|
274 | }
|
---|
275 |
|
---|
276 | /**
|
---|
277 | * @brief ISOINIncomplete callback.
|
---|
278 | * @param hpcd: PCD handle
|
---|
279 | * @param epnum: Endpoint number
|
---|
280 | * @retval None
|
---|
281 | */
|
---|
282 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
283 | static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
---|
284 | #else
|
---|
285 | void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
|
---|
286 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
287 | {
|
---|
288 | USBD_LL_IsoINIncomplete((USBD_HandleTypeDef*)hpcd->pData, epnum);
|
---|
289 | }
|
---|
290 |
|
---|
291 | /**
|
---|
292 | * @brief Connect callback.
|
---|
293 | * @param hpcd: PCD handle
|
---|
294 | * @retval None
|
---|
295 | */
|
---|
296 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
297 | static void PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
|
---|
298 | #else
|
---|
299 | void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
|
---|
300 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
301 | {
|
---|
302 | USBD_LL_DevConnected((USBD_HandleTypeDef*)hpcd->pData);
|
---|
303 | }
|
---|
304 |
|
---|
305 | /**
|
---|
306 | * @brief Disconnect callback.
|
---|
307 | * @param hpcd: PCD handle
|
---|
308 | * @retval None
|
---|
309 | */
|
---|
310 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
311 | static void PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
|
---|
312 | #else
|
---|
313 | void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
|
---|
314 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
315 | {
|
---|
316 | USBD_LL_DevDisconnected((USBD_HandleTypeDef*)hpcd->pData);
|
---|
317 | }
|
---|
318 |
|
---|
319 | /*******************************************************************************
|
---|
320 | LL Driver Interface (USB Device Library --> PCD)
|
---|
321 | *******************************************************************************/
|
---|
322 |
|
---|
323 | /**
|
---|
324 | * @brief Initializes the low level portion of the device driver.
|
---|
325 | * @param pdev: Device handle
|
---|
326 | * @retval USBD status
|
---|
327 | */
|
---|
328 | USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
---|
329 | {
|
---|
330 | /* Init USB Ip. */
|
---|
331 | if (pdev->id == DEVICE_FS) {
|
---|
332 | /* Link the driver to the stack. */
|
---|
333 | hpcd_USB_OTG_FS.pData = pdev;
|
---|
334 | pdev->pData = &hpcd_USB_OTG_FS;
|
---|
335 |
|
---|
336 | hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
|
---|
337 | hpcd_USB_OTG_FS.Init.dev_endpoints = 4;
|
---|
338 | hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
|
---|
339 | hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
|
---|
340 | hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
|
---|
341 | hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
|
---|
342 | hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
|
---|
343 | hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
|
---|
344 | hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
|
---|
345 | hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
|
---|
346 | if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
|
---|
347 | {
|
---|
348 | Error_Handler( );
|
---|
349 | }
|
---|
350 |
|
---|
351 | #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
|
---|
352 | /* Register USB PCD CallBacks */
|
---|
353 | HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SOF_CB_ID, PCD_SOFCallback);
|
---|
354 | HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SETUPSTAGE_CB_ID, PCD_SetupStageCallback);
|
---|
355 | HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_RESET_CB_ID, PCD_ResetCallback);
|
---|
356 | HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_SUSPEND_CB_ID, PCD_SuspendCallback);
|
---|
357 | HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_RESUME_CB_ID, PCD_ResumeCallback);
|
---|
358 | HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_CONNECT_CB_ID, PCD_ConnectCallback);
|
---|
359 | HAL_PCD_RegisterCallback(&hpcd_USB_OTG_FS, HAL_PCD_DISCONNECT_CB_ID, PCD_DisconnectCallback);
|
---|
360 |
|
---|
361 | HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_OTG_FS, PCD_DataOutStageCallback);
|
---|
362 | HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_OTG_FS, PCD_DataInStageCallback);
|
---|
363 | HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOOUTIncompleteCallback);
|
---|
364 | HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_OTG_FS, PCD_ISOINIncompleteCallback);
|
---|
365 | #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
|
---|
366 | HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
|
---|
367 | HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
|
---|
368 | HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80);
|
---|
369 | }
|
---|
370 | return USBD_OK;
|
---|
371 | }
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * @brief De-Initializes the low level portion of the device driver.
|
---|
375 | * @param pdev: Device handle
|
---|
376 | * @retval USBD status
|
---|
377 | */
|
---|
378 | USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
---|
379 | {
|
---|
380 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
381 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
382 |
|
---|
383 | hal_status = HAL_PCD_DeInit(pdev->pData);
|
---|
384 |
|
---|
385 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
386 |
|
---|
387 | return usb_status;
|
---|
388 | }
|
---|
389 |
|
---|
390 | /**
|
---|
391 | * @brief Starts the low level portion of the device driver.
|
---|
392 | * @param pdev: Device handle
|
---|
393 | * @retval USBD status
|
---|
394 | */
|
---|
395 | USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
---|
396 | {
|
---|
397 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
398 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
399 |
|
---|
400 | hal_status = HAL_PCD_Start(pdev->pData);
|
---|
401 |
|
---|
402 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
403 |
|
---|
404 | return usb_status;
|
---|
405 | }
|
---|
406 |
|
---|
407 | /**
|
---|
408 | * @brief Stops the low level portion of the device driver.
|
---|
409 | * @param pdev: Device handle
|
---|
410 | * @retval USBD status
|
---|
411 | */
|
---|
412 | USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
---|
413 | {
|
---|
414 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
415 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
416 |
|
---|
417 | hal_status = HAL_PCD_Stop(pdev->pData);
|
---|
418 |
|
---|
419 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
420 |
|
---|
421 | return usb_status;
|
---|
422 | }
|
---|
423 |
|
---|
424 | /**
|
---|
425 | * @brief Opens an endpoint of the low level driver.
|
---|
426 | * @param pdev: Device handle
|
---|
427 | * @param ep_addr: Endpoint number
|
---|
428 | * @param ep_type: Endpoint type
|
---|
429 | * @param ep_mps: Endpoint max packet size
|
---|
430 | * @retval USBD status
|
---|
431 | */
|
---|
432 | USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps)
|
---|
433 | {
|
---|
434 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
435 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
436 |
|
---|
437 | hal_status = HAL_PCD_EP_Open(pdev->pData, ep_addr, ep_mps, ep_type);
|
---|
438 |
|
---|
439 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
440 |
|
---|
441 | return usb_status;
|
---|
442 | }
|
---|
443 |
|
---|
444 | /**
|
---|
445 | * @brief Closes an endpoint of the low level driver.
|
---|
446 | * @param pdev: Device handle
|
---|
447 | * @param ep_addr: Endpoint number
|
---|
448 | * @retval USBD status
|
---|
449 | */
|
---|
450 | USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
---|
451 | {
|
---|
452 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
453 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
454 |
|
---|
455 | hal_status = HAL_PCD_EP_Close(pdev->pData, ep_addr);
|
---|
456 |
|
---|
457 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
458 |
|
---|
459 | return usb_status;
|
---|
460 | }
|
---|
461 |
|
---|
462 | /**
|
---|
463 | * @brief Flushes an endpoint of the Low Level Driver.
|
---|
464 | * @param pdev: Device handle
|
---|
465 | * @param ep_addr: Endpoint number
|
---|
466 | * @retval USBD status
|
---|
467 | */
|
---|
468 | USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
---|
469 | {
|
---|
470 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
471 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
472 |
|
---|
473 | hal_status = HAL_PCD_EP_Flush(pdev->pData, ep_addr);
|
---|
474 |
|
---|
475 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
476 |
|
---|
477 | return usb_status;
|
---|
478 | }
|
---|
479 |
|
---|
480 | /**
|
---|
481 | * @brief Sets a Stall condition on an endpoint of the Low Level Driver.
|
---|
482 | * @param pdev: Device handle
|
---|
483 | * @param ep_addr: Endpoint number
|
---|
484 | * @retval USBD status
|
---|
485 | */
|
---|
486 | USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
---|
487 | {
|
---|
488 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
489 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
490 |
|
---|
491 | hal_status = HAL_PCD_EP_SetStall(pdev->pData, ep_addr);
|
---|
492 |
|
---|
493 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
494 |
|
---|
495 | return usb_status;
|
---|
496 | }
|
---|
497 |
|
---|
498 | /**
|
---|
499 | * @brief Clears a Stall condition on an endpoint of the Low Level Driver.
|
---|
500 | * @param pdev: Device handle
|
---|
501 | * @param ep_addr: Endpoint number
|
---|
502 | * @retval USBD status
|
---|
503 | */
|
---|
504 | USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
---|
505 | {
|
---|
506 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
507 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
508 |
|
---|
509 | hal_status = HAL_PCD_EP_ClrStall(pdev->pData, ep_addr);
|
---|
510 |
|
---|
511 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
512 |
|
---|
513 | return usb_status;
|
---|
514 | }
|
---|
515 |
|
---|
516 | /**
|
---|
517 | * @brief Returns Stall condition.
|
---|
518 | * @param pdev: Device handle
|
---|
519 | * @param ep_addr: Endpoint number
|
---|
520 | * @retval Stall (1: Yes, 0: No)
|
---|
521 | */
|
---|
522 | uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
---|
523 | {
|
---|
524 | PCD_HandleTypeDef *hpcd = (PCD_HandleTypeDef*) pdev->pData;
|
---|
525 |
|
---|
526 | if((ep_addr & 0x80) == 0x80)
|
---|
527 | {
|
---|
528 | return hpcd->IN_ep[ep_addr & 0x7F].is_stall;
|
---|
529 | }
|
---|
530 | else
|
---|
531 | {
|
---|
532 | return hpcd->OUT_ep[ep_addr & 0x7F].is_stall;
|
---|
533 | }
|
---|
534 | }
|
---|
535 |
|
---|
536 | /**
|
---|
537 | * @brief Assigns a USB address to the device.
|
---|
538 | * @param pdev: Device handle
|
---|
539 | * @param dev_addr: Device address
|
---|
540 | * @retval USBD status
|
---|
541 | */
|
---|
542 | USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr)
|
---|
543 | {
|
---|
544 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
545 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
546 |
|
---|
547 | hal_status = HAL_PCD_SetAddress(pdev->pData, dev_addr);
|
---|
548 |
|
---|
549 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
550 |
|
---|
551 | return usb_status;
|
---|
552 | }
|
---|
553 |
|
---|
554 | /**
|
---|
555 | * @brief Transmits data over an endpoint.
|
---|
556 | * @param pdev: Device handle
|
---|
557 | * @param ep_addr: Endpoint number
|
---|
558 | * @param pbuf: Pointer to data to be sent
|
---|
559 | * @param size: Data size
|
---|
560 | * @retval USBD status
|
---|
561 | */
|
---|
562 | USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size)
|
---|
563 | {
|
---|
564 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
565 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
566 |
|
---|
567 | hal_status = HAL_PCD_EP_Transmit(pdev->pData, ep_addr, pbuf, size);
|
---|
568 |
|
---|
569 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
570 |
|
---|
571 | return usb_status;
|
---|
572 | }
|
---|
573 |
|
---|
574 | /**
|
---|
575 | * @brief Prepares an endpoint for reception.
|
---|
576 | * @param pdev: Device handle
|
---|
577 | * @param ep_addr: Endpoint number
|
---|
578 | * @param pbuf: Pointer to data to be received
|
---|
579 | * @param size: Data size
|
---|
580 | * @retval USBD status
|
---|
581 | */
|
---|
582 | USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint32_t size)
|
---|
583 | {
|
---|
584 | HAL_StatusTypeDef hal_status = HAL_OK;
|
---|
585 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
586 |
|
---|
587 | hal_status = HAL_PCD_EP_Receive(pdev->pData, ep_addr, pbuf, size);
|
---|
588 |
|
---|
589 | usb_status = USBD_Get_USB_Status(hal_status);
|
---|
590 |
|
---|
591 | return usb_status;
|
---|
592 | }
|
---|
593 |
|
---|
594 | /**
|
---|
595 | * @brief Returns the last transfered packet size.
|
---|
596 | * @param pdev: Device handle
|
---|
597 | * @param ep_addr: Endpoint number
|
---|
598 | * @retval Recived Data Size
|
---|
599 | */
|
---|
600 | uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
---|
601 | {
|
---|
602 | return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef*) pdev->pData, ep_addr);
|
---|
603 | }
|
---|
604 |
|
---|
605 | /**
|
---|
606 | * @brief Static single allocation.
|
---|
607 | * @param size: Size of allocated memory
|
---|
608 | * @retval None
|
---|
609 | */
|
---|
610 | void *USBD_static_malloc(uint32_t size)
|
---|
611 | {
|
---|
612 | static uint32_t mem[(sizeof(USBD_CDC_HandleTypeDef)/4)+1];/* On 32-bit boundary */
|
---|
613 | return mem;
|
---|
614 | }
|
---|
615 |
|
---|
616 | /**
|
---|
617 | * @brief Dummy memory free
|
---|
618 | * @param p: Pointer to allocated memory address
|
---|
619 | * @retval None
|
---|
620 | */
|
---|
621 | void USBD_static_free(void *p)
|
---|
622 | {
|
---|
623 |
|
---|
624 | }
|
---|
625 |
|
---|
626 | /**
|
---|
627 | * @brief Delays routine for the USB Device Library.
|
---|
628 | * @param Delay: Delay in ms
|
---|
629 | * @retval None
|
---|
630 | */
|
---|
631 | void USBD_LL_Delay(uint32_t Delay)
|
---|
632 | {
|
---|
633 | HAL_Delay(Delay);
|
---|
634 | }
|
---|
635 |
|
---|
636 | /**
|
---|
637 | * @brief Retuns the USB status depending on the HAL status:
|
---|
638 | * @param hal_status: HAL status
|
---|
639 | * @retval USB status
|
---|
640 | */
|
---|
641 | USBD_StatusTypeDef USBD_Get_USB_Status(HAL_StatusTypeDef hal_status)
|
---|
642 | {
|
---|
643 | USBD_StatusTypeDef usb_status = USBD_OK;
|
---|
644 |
|
---|
645 | switch (hal_status)
|
---|
646 | {
|
---|
647 | case HAL_OK :
|
---|
648 | usb_status = USBD_OK;
|
---|
649 | break;
|
---|
650 | case HAL_ERROR :
|
---|
651 | usb_status = USBD_FAIL;
|
---|
652 | break;
|
---|
653 | case HAL_BUSY :
|
---|
654 | usb_status = USBD_BUSY;
|
---|
655 | break;
|
---|
656 | case HAL_TIMEOUT :
|
---|
657 | usb_status = USBD_FAIL;
|
---|
658 | break;
|
---|
659 | default :
|
---|
660 | usb_status = USBD_FAIL;
|
---|
661 | break;
|
---|
662 | }
|
---|
663 | return usb_status;
|
---|
664 | }
|
---|
665 |
|
---|
666 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|