usb_device.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : usb_device.c
  5. * @version : v3.0_Cube
  6. * @brief : This file implements the USB Device
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; 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. /* 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. extern void Error_Handler(void);
  36. /* USB Device Core handle declaration. */
  37. USBD_HandleTypeDef hUsbDeviceFS;
  38. extern USBD_DescriptorsTypeDef CDC_Desc;
  39. /*
  40. * -- Insert your variables declaration here --
  41. */
  42. /* USER CODE BEGIN 0 */
  43. /* USER CODE END 0 */
  44. /*
  45. * -- Insert your external function declaration here --
  46. */
  47. /* USER CODE BEGIN 1 */
  48. /* USER CODE END 1 */
  49. /**
  50. * Init USB device Library, add supported class and start the library
  51. * @retval None
  52. */
  53. void MX_USB_Device_Init(void)
  54. {
  55. /* USER CODE BEGIN USB_Device_Init_PreTreatment */
  56. /* USER CODE END USB_Device_Init_PreTreatment */
  57. /* Init Device Library, add supported class and start the library. */
  58. if (USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) {
  59. Error_Handler();
  60. }
  61. if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) {
  62. Error_Handler();
  63. }
  64. if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) {
  65. Error_Handler();
  66. }
  67. if (USBD_Start(&hUsbDeviceFS) != USBD_OK) {
  68. Error_Handler();
  69. }
  70. /* USER CODE BEGIN USB_Device_Init_PostTreatment */
  71. /* USER CODE END USB_Device_Init_PostTreatment */
  72. }
  73. /**
  74. * @}
  75. */
  76. /**
  77. * @}
  78. */
  79. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/