1 /* USER CODE BEGIN Header */
3 ******************************************************************************
4 * @file USB_Device/CDC_Standalone/USB_Device/Target/usbd_conf.c
5 * @author MCD Application Team
6 * @brief This file implements the board support package for the USB device library
7 ******************************************************************************
10 * <h2><center>© Copyright (c) 2019 STMicroelectronics.
11 * All rights reserved.</center></h2>
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:
18 ******************************************************************************
20 /* USER CODE END Header */
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32g4xx.h"
24 #include "stm32g4xx_hal.h"
26 #include "usbd_core.h"
30 /* USER CODE BEGIN Includes */
34 /* USER CODE END Includes */
36 /* Private typedef -----------------------------------------------------------*/
37 /* Private define ------------------------------------------------------------*/
38 /* Private macro -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* USER CODE BEGIN PV */
42 /* Private variables ---------------------------------------------------------*/
44 /* USER CODE END PV */
46 PCD_HandleTypeDef hpcd_USB_FS
;
47 void Error_Handler(void);
49 /* USER CODE BEGIN 0 */
53 /* Exported function prototypes ----------------------------------------------*/
55 /* USER CODE BEGIN PFP */
56 /* Private function prototypes -----------------------------------------------*/
58 /* USER CODE END PFP */
60 /* Private functions ---------------------------------------------------------*/
61 static USBD_StatusTypeDef
USBD_Get_USB_Status(HAL_StatusTypeDef hal_status
);
62 /* USER CODE BEGIN 1 */
63 static void SystemClockConfig_Resume(void);
64 extern void USBD_Clock_Config(void);
66 extern void SystemClock_Config(void);
68 void USB_LP_IRQHandler(void)
70 HAL_PCD_IRQHandler(&hpcd_USB_FS
);
73 /*******************************************************************************
74 LL Driver Callbacks (PCD -> USB Device Library)
75 *******************************************************************************/
78 #if (USE_HAL_PCD_REGISTER_CALLBACK == 1U)
79 static void HAL_PCD_MspInit(PCD_HandleTypeDef
* pcdHandle
)
81 void HAL_PCD_MspInit(PCD_HandleTypeDef
* pcdHandle
)
82 #endif /* USE_HAL_PCD_REGISTER_CALLBACK */
84 GPIO_InitTypeDef GPIO_InitStruct
= {0};
85 if(pcdHandle
->Instance
==USB
)
87 /* USER CODE BEGIN USB_MspInit 0 */
89 /* USER CODE END USB_MspInit 0 */
91 __HAL_RCC_GPIOA_CLK_ENABLE();
92 /**USB GPIO Configuration
96 GPIO_InitStruct
.Pin
= GPIO_PIN_11
|GPIO_PIN_12
;
97 GPIO_InitStruct
.Mode
= GPIO_MODE_AF_PP
;
98 GPIO_InitStruct
.Pull
= GPIO_NOPULL
;
99 GPIO_InitStruct
.Speed
= GPIO_SPEED_FREQ_VERY_HIGH
;
100 HAL_GPIO_Init(GPIOA
, &GPIO_InitStruct
);
102 /* Peripheral clock enable */
103 __HAL_RCC_USB_CLK_ENABLE();
105 /* Peripheral interrupt init */
106 HAL_NVIC_SetPriority(USB_LP_IRQn
, 6, 0);
107 HAL_NVIC_EnableIRQ(USB_LP_IRQn
);
108 /* USER CODE BEGIN USB_MspInit 1 */
110 /* USER CODE END USB_MspInit 1 */
114 #if (USE_HAL_PCD_REGISTER_CALLBACK == 1U)
115 static void HAL_PCD_MspDeInit(PCD_HandleTypeDef
* pcdHandle
)
117 void HAL_PCD_MspDeInit(PCD_HandleTypeDef
* pcdHandle
)
118 #endif /* USE_HAL_PCD_REGISTER_CALLBACK */
120 if(pcdHandle
->Instance
==USB
)
122 /* USER CODE BEGIN USB_MspDeInit 0 */
124 /* USER CODE END USB_MspDeInit 0 */
125 /* Peripheral clock disable */
126 __HAL_RCC_USB_CLK_DISABLE();
128 /**USB GPIO Configuration
132 HAL_GPIO_DeInit(GPIOA
, GPIO_PIN_11
|GPIO_PIN_12
);
134 /* Peripheral interrupt Deinit*/
135 HAL_NVIC_DisableIRQ(USB_LP_IRQn
);
137 /* USER CODE BEGIN USB_MspDeInit 1 */
138 __HAL_RCC_GPIOA_CLK_DISABLE();
139 /* USER CODE END USB_MspDeInit 1 */
144 * @brief Setup stage callback
145 * @param hpcd: PCD handle
148 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
149 static void PCD_SetupStageCallback(PCD_HandleTypeDef
*hpcd
)
151 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef
*hpcd
)
152 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
154 /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PreTreatment */
156 /* USER CODE END HAL_PCD_SetupStageCallback_PreTreatment */
157 USBD_LL_SetupStage((USBD_HandleTypeDef
*)hpcd
->pData
, (uint8_t *)hpcd
->Setup
);
158 /* USER CODE BEGIN HAL_PCD_SetupStageCallback_PostTreatment */
160 /* USER CODE END HAL_PCD_SetupStageCallback_PostTreatment */
164 * @brief Data Out stage callback.
165 * @param hpcd: PCD handle
166 * @param epnum: Endpoint number
169 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
170 static void PCD_DataOutStageCallback(PCD_HandleTypeDef
*hpcd
, uint8_t epnum
)
172 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef
*hpcd
, uint8_t epnum
)
173 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
175 /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PreTreatment */
177 /* USER CODE END HAL_PCD_DataOutStageCallback_PreTreatment */
178 USBD_LL_DataOutStage((USBD_HandleTypeDef
*)hpcd
->pData
, epnum
, hpcd
->OUT_ep
[epnum
].xfer_buff
);
179 /* USER CODE BEGIN HAL_PCD_DataOutStageCallback_PostTreatment */
181 /* USER CODE END HAL_PCD_DataOutStageCallback_PostTreatment */
185 * @brief Data In stage callback.
186 * @param hpcd: PCD handle
187 * @param epnum: Endpoint number
190 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
191 static void PCD_DataInStageCallback(PCD_HandleTypeDef
*hpcd
, uint8_t epnum
)
193 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef
*hpcd
, uint8_t epnum
)
194 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
196 /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PreTreatment */
198 /* USER CODE END HAL_PCD_DataInStageCallback_PreTreatment */
199 USBD_LL_DataInStage((USBD_HandleTypeDef
*)hpcd
->pData
, epnum
, hpcd
->IN_ep
[epnum
].xfer_buff
);
200 /* USER CODE BEGIN HAL_PCD_DataInStageCallback_PostTreatment */
202 /* USER CODE END HAL_PCD_DataInStageCallback_PostTreatment */
206 * @brief SOF callback.
207 * @param hpcd: PCD handle
210 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
211 static void PCD_SOFCallback(PCD_HandleTypeDef
*hpcd
)
213 void HAL_PCD_SOFCallback(PCD_HandleTypeDef
*hpcd
)
214 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
216 /* USER CODE BEGIN HAL_PCD_SOFCallback_PreTreatment */
218 /* USER CODE END HAL_PCD_SOFCallback_PreTreatment */
219 USBD_LL_SOF((USBD_HandleTypeDef
*)hpcd
->pData
);
220 /* USER CODE BEGIN HAL_PCD_SOFCallback_PostTreatment */
222 /* USER CODE END HAL_PCD_SOFCallback_PostTreatment */
226 * @brief Reset callback.
227 * @param hpcd: PCD handle
230 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
231 static void PCD_ResetCallback(PCD_HandleTypeDef
*hpcd
)
233 void HAL_PCD_ResetCallback(PCD_HandleTypeDef
*hpcd
)
234 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
236 /* USER CODE BEGIN HAL_PCD_ResetCallback_PreTreatment */
238 /* USER CODE END HAL_PCD_ResetCallback_PreTreatment */
239 USBD_SpeedTypeDef speed
= USBD_SPEED_FULL
;
241 if ( hpcd
->Init
.speed
!= PCD_SPEED_FULL
)
246 USBD_LL_SetSpeed((USBD_HandleTypeDef
*)hpcd
->pData
, speed
);
249 USBD_LL_Reset((USBD_HandleTypeDef
*)hpcd
->pData
);
250 /* USER CODE BEGIN HAL_PCD_ResetCallback_PostTreatment */
252 /* USER CODE END HAL_PCD_ResetCallback_PostTreatment */
256 * @brief Suspend callback.
257 * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
258 * @param hpcd: PCD handle
261 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
262 static void PCD_SuspendCallback(PCD_HandleTypeDef
*hpcd
)
264 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef
*hpcd
)
265 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
267 /* USER CODE BEGIN HAL_PCD_SuspendCallback_PreTreatment */
269 /* USER CODE END HAL_PCD_SuspendCallback_PreTreatment */
270 /* Inform USB library that core enters in suspend Mode. */
271 USBD_LL_Suspend((USBD_HandleTypeDef
*)hpcd
->pData
);
272 /* Enter in STOP mode. */
273 /* USER CODE BEGIN 2 */
274 if (hpcd
->Init
.low_power_enable
)
276 /* Set SLEEPDEEP bit and SleepOnExit of Cortex System Control Register. */
277 SCB
->SCR
|= (uint32_t)((uint32_t)(SCB_SCR_SLEEPDEEP_Msk
| SCB_SCR_SLEEPONEXIT_Msk
));
279 /* USER CODE END 2 */
280 /* USER CODE BEGIN HAL_PCD_SuspendCallback_PostTreatment */
282 /* USER CODE END HAL_PCD_SuspendCallback_PostTreatment */
286 * @brief Resume callback.
287 * When Low power mode is enabled the debug cannot be used (IAR, Keil doesn't support it)
288 * @param hpcd: PCD handle
291 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
292 static void PCD_ResumeCallback(PCD_HandleTypeDef
*hpcd
)
294 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef
*hpcd
)
295 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
297 /* USER CODE BEGIN HAL_PCD_ResumeCallback_PreTreatment */
299 /* USER CODE END HAL_PCD_ResumeCallback_PreTreatment */
301 /* USER CODE BEGIN 3 */
302 if (hpcd
->Init
.low_power_enable
)
304 /* Reset SLEEPDEEP bit of Cortex System Control Register. */
305 SCB
->SCR
&= (uint32_t)~((uint32_t)(SCB_SCR_SLEEPDEEP_Msk
| SCB_SCR_SLEEPONEXIT_Msk
));
306 SystemClockConfig_Resume();
308 /* USER CODE END 3 */
310 USBD_LL_Resume((USBD_HandleTypeDef
*)hpcd
->pData
);
311 /* USER CODE BEGIN HAL_PCD_ResumeCallback_PostTreatment */
313 /* USER CODE END HAL_PCD_ResumeCallback_PostTreatment */
317 * @brief ISOOUTIncomplete callback.
318 * @param hpcd: PCD handle
319 * @param epnum: Endpoint number
322 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
323 static void PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef
*hpcd
, uint8_t epnum
)
325 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef
*hpcd
, uint8_t epnum
)
326 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
328 /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */
330 /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PreTreatment */
331 USBD_LL_IsoOUTIncomplete((USBD_HandleTypeDef
*)hpcd
->pData
, epnum
);
332 /* USER CODE BEGIN HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */
334 /* USER CODE END HAL_PCD_ISOOUTIncompleteCallback_PostTreatment */
338 * @brief ISOINIncomplete callback.
339 * @param hpcd: PCD handle
340 * @param epnum: Endpoint number
343 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
344 static void PCD_ISOINIncompleteCallback(PCD_HandleTypeDef
*hpcd
, uint8_t epnum
)
346 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef
*hpcd
, uint8_t epnum
)
347 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
349 /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PreTreatment */
351 /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PreTreatment */
352 USBD_LL_IsoINIncomplete((USBD_HandleTypeDef
*)hpcd
->pData
, epnum
);
353 /* USER CODE BEGIN HAL_PCD_ISOINIncompleteCallback_PostTreatment */
355 /* USER CODE END HAL_PCD_ISOINIncompleteCallback_PostTreatment */
359 * @brief Connect callback.
360 * @param hpcd: PCD handle
363 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
364 static void PCD_ConnectCallback(PCD_HandleTypeDef
*hpcd
)
366 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef
*hpcd
)
367 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
369 /* USER CODE BEGIN HAL_PCD_ConnectCallback_PreTreatment */
371 /* USER CODE END HAL_PCD_ConnectCallback_PreTreatment */
372 USBD_LL_DevConnected((USBD_HandleTypeDef
*)hpcd
->pData
);
373 /* USER CODE BEGIN HAL_PCD_ConnectCallback_PostTreatment */
375 /* USER CODE END HAL_PCD_ConnectCallback_PostTreatment */
379 * @brief Disconnect callback.
380 * @param hpcd: PCD handle
383 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
384 static void PCD_DisconnectCallback(PCD_HandleTypeDef
*hpcd
)
386 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef
*hpcd
)
387 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
389 /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PreTreatment */
391 /* USER CODE END HAL_PCD_DisconnectCallback_PreTreatment */
392 USBD_LL_DevDisconnected((USBD_HandleTypeDef
*)hpcd
->pData
);
393 /* USER CODE BEGIN HAL_PCD_DisconnectCallback_PostTreatment */
395 /* USER CODE END HAL_PCD_DisconnectCallback_PostTreatment */
398 /* USER CODE BEGIN LowLevelInterface */
400 /* USER CODE END LowLevelInterface */
402 /*******************************************************************************
403 LL Driver Interface (USB Device Library --> PCD)
404 *******************************************************************************/
407 * @brief Initializes the low level portion of the device driver.
408 * @param pdev: Device handle
409 * @retval USBD status
411 USBD_StatusTypeDef
USBD_LL_Init(USBD_HandleTypeDef
*pdev
)
414 hpcd_USB_FS
.pData
= pdev
;
415 /* Link the driver to the stack. */
416 pdev
->pData
= &hpcd_USB_FS
;
418 hpcd_USB_FS
.Instance
= USB
;
419 hpcd_USB_FS
.Init
.dev_endpoints
= 8;
420 hpcd_USB_FS
.Init
.speed
= PCD_SPEED_FULL
;
421 hpcd_USB_FS
.Init
.phy_itface
= PCD_PHY_EMBEDDED
;
422 hpcd_USB_FS
.Init
.Sof_enable
= DISABLE
;
423 hpcd_USB_FS
.Init
.low_power_enable
= DISABLE
;
424 hpcd_USB_FS
.Init
.lpm_enable
= DISABLE
;
425 hpcd_USB_FS
.Init
.battery_charging_enable
= DISABLE
;
427 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
428 /* register Msp Callbacks (before the Init) */
429 HAL_PCD_RegisterCallback(&hpcd_USB_FS
, HAL_PCD_MSPINIT_CB_ID
, PCD_MspInit
);
430 HAL_PCD_RegisterCallback(&hpcd_USB_FS
, HAL_PCD_MSPDEINIT_CB_ID
, PCD_MspDeInit
);
431 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
433 if (HAL_PCD_Init(&hpcd_USB_FS
) != HAL_OK
)
438 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
439 /* Register USB PCD CallBacks */
440 HAL_PCD_RegisterCallback(&hpcd_USB_FS
, HAL_PCD_SOF_CB_ID
, PCD_SOFCallback
);
441 HAL_PCD_RegisterCallback(&hpcd_USB_FS
, HAL_PCD_SETUPSTAGE_CB_ID
, PCD_SetupStageCallback
);
442 HAL_PCD_RegisterCallback(&hpcd_USB_FS
, HAL_PCD_RESET_CB_ID
, PCD_ResetCallback
);
443 HAL_PCD_RegisterCallback(&hpcd_USB_FS
, HAL_PCD_SUSPEND_CB_ID
, PCD_SuspendCallback
);
444 HAL_PCD_RegisterCallback(&hpcd_USB_FS
, HAL_PCD_RESUME_CB_ID
, PCD_ResumeCallback
);
445 HAL_PCD_RegisterCallback(&hpcd_USB_FS
, HAL_PCD_CONNECT_CB_ID
, PCD_ConnectCallback
);
446 HAL_PCD_RegisterCallback(&hpcd_USB_FS
, HAL_PCD_DISCONNECT_CB_ID
, PCD_DisconnectCallback
);
447 /* USER CODE BEGIN RegisterCallBackFirstPart */
449 /* USER CODE END RegisterCallBackFirstPart */
450 HAL_PCD_RegisterDataOutStageCallback(&hpcd_USB_FS
, PCD_DataOutStageCallback
);
451 HAL_PCD_RegisterDataInStageCallback(&hpcd_USB_FS
, PCD_DataInStageCallback
);
452 HAL_PCD_RegisterIsoOutIncpltCallback(&hpcd_USB_FS
, PCD_ISOOUTIncompleteCallback
);
453 HAL_PCD_RegisterIsoInIncpltCallback(&hpcd_USB_FS
, PCD_ISOINIncompleteCallback
);
454 /* USER CODE BEGIN RegisterCallBackSecondPart */
456 /* USER CODE END RegisterCallBackSecondPart */
457 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
458 /* USER CODE BEGIN EndPoint_Configuration */
459 HAL_PCDEx_PMAConfig(&hpcd_USB_FS
, 0x00 , PCD_SNG_BUF
, 0x14);
460 HAL_PCDEx_PMAConfig(&hpcd_USB_FS
, 0x80 , PCD_SNG_BUF
, 0x54);
461 /* USER CODE END EndPoint_Configuration */
462 /* USER CODE BEGIN EndPoint_Configuration_CDC */
463 HAL_PCDEx_PMAConfig(&hpcd_USB_FS
, CDC_IN_EP
, PCD_SNG_BUF
, 0x94);
464 HAL_PCDEx_PMAConfig(&hpcd_USB_FS
, CDC_OUT_EP
, PCD_SNG_BUF
, 0xD4);
465 HAL_PCDEx_PMAConfig(&hpcd_USB_FS
, CDC_CMD_EP
, PCD_SNG_BUF
, 0x114);
466 /* USER CODE END EndPoint_Configuration_CDC */
471 * @brief De-Initializes the low level portion of the device driver.
472 * @param pdev: Device handle
473 * @retval USBD status
475 USBD_StatusTypeDef
USBD_LL_DeInit(USBD_HandleTypeDef
*pdev
)
477 HAL_StatusTypeDef hal_status
= HAL_OK
;
478 USBD_StatusTypeDef usb_status
= USBD_OK
;
480 hal_status
= HAL_PCD_DeInit(pdev
->pData
);
482 usb_status
= USBD_Get_USB_Status(hal_status
);
488 * @brief Starts the low level portion of the device driver.
489 * @param pdev: Device handle
490 * @retval USBD status
492 USBD_StatusTypeDef
USBD_LL_Start(USBD_HandleTypeDef
*pdev
)
494 HAL_StatusTypeDef hal_status
= HAL_OK
;
495 USBD_StatusTypeDef usb_status
= USBD_OK
;
497 hal_status
= HAL_PCD_Start(pdev
->pData
);
499 usb_status
= USBD_Get_USB_Status(hal_status
);
505 * @brief Stops the low level portion of the device driver.
506 * @param pdev: Device handle
507 * @retval USBD status
509 USBD_StatusTypeDef
USBD_LL_Stop(USBD_HandleTypeDef
*pdev
)
511 HAL_StatusTypeDef hal_status
= HAL_OK
;
512 USBD_StatusTypeDef usb_status
= USBD_OK
;
514 hal_status
= HAL_PCD_Stop(pdev
->pData
);
516 usb_status
= USBD_Get_USB_Status(hal_status
);
522 * @brief Opens an endpoint of the low level driver.
523 * @param pdev: Device handle
524 * @param ep_addr: Endpoint number
525 * @param ep_type: Endpoint type
526 * @param ep_mps: Endpoint max packet size
527 * @retval USBD status
529 USBD_StatusTypeDef
USBD_LL_OpenEP(USBD_HandleTypeDef
*pdev
, uint8_t ep_addr
, uint8_t ep_type
, uint16_t ep_mps
)
531 HAL_StatusTypeDef hal_status
= HAL_OK
;
532 USBD_StatusTypeDef usb_status
= USBD_OK
;
534 hal_status
= HAL_PCD_EP_Open(pdev
->pData
, ep_addr
, ep_mps
, ep_type
);
536 usb_status
= USBD_Get_USB_Status(hal_status
);
542 * @brief Closes an endpoint of the low level driver.
543 * @param pdev: Device handle
544 * @param ep_addr: Endpoint number
545 * @retval USBD status
547 USBD_StatusTypeDef
USBD_LL_CloseEP(USBD_HandleTypeDef
*pdev
, uint8_t ep_addr
)
549 HAL_StatusTypeDef hal_status
= HAL_OK
;
550 USBD_StatusTypeDef usb_status
= USBD_OK
;
552 hal_status
= HAL_PCD_EP_Close(pdev
->pData
, ep_addr
);
554 usb_status
= USBD_Get_USB_Status(hal_status
);
560 * @brief Flushes an endpoint of the Low Level Driver.
561 * @param pdev: Device handle
562 * @param ep_addr: Endpoint number
563 * @retval USBD status
565 USBD_StatusTypeDef
USBD_LL_FlushEP(USBD_HandleTypeDef
*pdev
, uint8_t ep_addr
)
567 HAL_StatusTypeDef hal_status
= HAL_OK
;
568 USBD_StatusTypeDef usb_status
= USBD_OK
;
570 hal_status
= HAL_PCD_EP_Flush(pdev
->pData
, ep_addr
);
572 usb_status
= USBD_Get_USB_Status(hal_status
);
578 * @brief Sets a Stall condition on an endpoint of the Low Level Driver.
579 * @param pdev: Device handle
580 * @param ep_addr: Endpoint number
581 * @retval USBD status
583 USBD_StatusTypeDef
USBD_LL_StallEP(USBD_HandleTypeDef
*pdev
, uint8_t ep_addr
)
585 HAL_StatusTypeDef hal_status
= HAL_OK
;
586 USBD_StatusTypeDef usb_status
= USBD_OK
;
588 hal_status
= HAL_PCD_EP_SetStall(pdev
->pData
, ep_addr
);
590 usb_status
= USBD_Get_USB_Status(hal_status
);
596 * @brief Clears a Stall condition on an endpoint of the Low Level Driver.
597 * @param pdev: Device handle
598 * @param ep_addr: Endpoint number
599 * @retval USBD status
601 USBD_StatusTypeDef
USBD_LL_ClearStallEP(USBD_HandleTypeDef
*pdev
, uint8_t ep_addr
)
603 HAL_StatusTypeDef hal_status
= HAL_OK
;
604 USBD_StatusTypeDef usb_status
= USBD_OK
;
606 hal_status
= HAL_PCD_EP_ClrStall(pdev
->pData
, ep_addr
);
608 usb_status
= USBD_Get_USB_Status(hal_status
);
614 * @brief Returns Stall condition.
615 * @param pdev: Device handle
616 * @param ep_addr: Endpoint number
617 * @retval Stall (1: Yes, 0: No)
619 uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef
*pdev
, uint8_t ep_addr
)
621 PCD_HandleTypeDef
*hpcd
= (PCD_HandleTypeDef
*) pdev
->pData
;
623 if((ep_addr
& 0x80) == 0x80)
625 return hpcd
->IN_ep
[ep_addr
& 0x7F].is_stall
;
629 return hpcd
->OUT_ep
[ep_addr
& 0x7F].is_stall
;
634 * @brief Assigns a USB address to the device.
635 * @param pdev: Device handle
636 * @param dev_addr: Device address
637 * @retval USBD status
639 USBD_StatusTypeDef
USBD_LL_SetUSBAddress(USBD_HandleTypeDef
*pdev
, uint8_t dev_addr
)
641 HAL_StatusTypeDef hal_status
= HAL_OK
;
642 USBD_StatusTypeDef usb_status
= USBD_OK
;
644 hal_status
= HAL_PCD_SetAddress(pdev
->pData
, dev_addr
);
646 usb_status
= USBD_Get_USB_Status(hal_status
);
652 * @brief Transmits data over an endpoint.
653 * @param pdev: Device handle
654 * @param ep_addr: Endpoint number
655 * @param pbuf: Pointer to data to be sent
656 * @param size: Data size
657 * @retval USBD status
659 USBD_StatusTypeDef
USBD_LL_Transmit(USBD_HandleTypeDef
*pdev
, uint8_t ep_addr
, uint8_t *pbuf
, uint16_t size
)
661 HAL_StatusTypeDef hal_status
= HAL_OK
;
662 USBD_StatusTypeDef usb_status
= USBD_OK
;
664 hal_status
= HAL_PCD_EP_Transmit(pdev
->pData
, ep_addr
, pbuf
, size
);
666 usb_status
= USBD_Get_USB_Status(hal_status
);
672 * @brief Prepares an endpoint for reception.
673 * @param pdev: Device handle
674 * @param ep_addr: Endpoint number
675 * @param pbuf: Pointer to data to be received
676 * @param size: Data size
677 * @retval USBD status
679 USBD_StatusTypeDef
USBD_LL_PrepareReceive(USBD_HandleTypeDef
*pdev
, uint8_t ep_addr
, uint8_t *pbuf
, uint16_t size
)
681 HAL_StatusTypeDef hal_status
= HAL_OK
;
682 USBD_StatusTypeDef usb_status
= USBD_OK
;
684 hal_status
= HAL_PCD_EP_Receive(pdev
->pData
, ep_addr
, pbuf
, size
);
686 usb_status
= USBD_Get_USB_Status(hal_status
);
692 * @brief Returns the last transfered packet size.
693 * @param pdev: Device handle
694 * @param ep_addr: Endpoint number
695 * @retval Recived Data Size
697 uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef
*pdev
, uint8_t ep_addr
)
699 return HAL_PCD_EP_GetRxCount((PCD_HandleTypeDef
*) pdev
->pData
, ep_addr
);
703 * @brief Delays routine for the USB Device Library.
704 * @param Delay: Delay in ms
707 void USBD_LL_Delay(uint32_t Delay
)
713 * @brief Static single allocation.
714 * @param size: Size of allocated memory
717 void *USBD_static_malloc(uint32_t size
)
721 static uint32_t mem
[(sizeof(USBD_CDC_HandleTypeDef
)/4)+1];/* On 32-bit boundary */
726 * @brief Dummy memory free
727 * @param p: Pointer to allocated memory address
730 void USBD_static_free(void *p
)
735 /* USER CODE BEGIN 5 */
737 * @brief Configures system clock after wake-up from USB resume callBack:
738 * enable HSI, PLL and select PLL as system clock source.
741 void SystemClockConfig_Resume(void)
744 // We don't need this as we don't sleep
745 // XXX Entire sleep & wakeup support may be removed?
746 SystemClock_Config();
750 /* USER CODE END 5 */
753 * @brief Retuns the USB status depending on the HAL status:
754 * @param hal_status: HAL status
757 USBD_StatusTypeDef
USBD_Get_USB_Status(HAL_StatusTypeDef hal_status
)
759 USBD_StatusTypeDef usb_status
= USBD_OK
;
764 usb_status
= USBD_OK
;
767 usb_status
= USBD_FAIL
;
770 usb_status
= USBD_BUSY
;
773 usb_status
= USBD_FAIL
;
776 usb_status
= USBD_FAIL
;
781 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/