usb_device.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : usb_device.c
  5. * @version : v2.0_Cube
  6. * @brief : This file implements the USB Device
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2020 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. /* Includes ------------------------------------------------------------------*/
  22. #include "usb_device.h"
  23. #include "usbd_core.h"
  24. #include "usbd_desc.h"
  25. #include "usbd_cdc.h"
  26. #include "usbd_cdc_if.h"
  27. /* USER CODE BEGIN Includes */
  28. /* USER CODE END Includes */
  29. /* USER CODE BEGIN PV */
  30. /* Private variables ---------------------------------------------------------*/
  31. /* USER CODE END PV */
  32. /* USER CODE BEGIN PFP */
  33. /* Private function prototypes -----------------------------------------------*/
  34. /* USER CODE END PFP */
  35. /* USB Device Core handle declaration. */
  36. USBD_HandleTypeDef hUsbDeviceFS;
  37. extern USBD_DescriptorsTypeDef FS_Desc;
  38. /*
  39. * -- Insert your variables declaration here --
  40. */
  41. /* USER CODE BEGIN 0 */
  42. /* USER CODE END 0 */
  43. /*
  44. * -- Insert your external function declaration here --
  45. */
  46. /* USER CODE BEGIN 1 */
  47. /* USER CODE END 1 */
  48. /**
  49. * Init USB device Library, add supported class and start the library
  50. * @retval None
  51. */
  52. void MX_USB_DEVICE_Init(void) {
  53. /* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
  54. /* USER CODE END USB_DEVICE_Init_PreTreatment */
  55. /* Init Device Library, add supported class and start the library. */
  56. if(USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK) {
  57. Error_Handler();
  58. }
  59. if(USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) {
  60. Error_Handler();
  61. }
  62. if(USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) {
  63. Error_Handler();
  64. }
  65. if(USBD_Start(&hUsbDeviceFS) != USBD_OK) {
  66. Error_Handler();
  67. }
  68. /* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
  69. /* USER CODE END USB_DEVICE_Init_PostTreatment */
  70. }
  71. /**
  72. * @}
  73. */
  74. /**
  75. * @}
  76. */
  77. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/