usb_device.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /* USER CODE BEGIN USB_Device_Init_PreTreatment */
  55. /* USER CODE END USB_Device_Init_PreTreatment */
  56. /* Init Device Library, add supported class and start the library. */
  57. if(USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) {
  58. Error_Handler();
  59. }
  60. if(USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) {
  61. Error_Handler();
  62. }
  63. if(USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) {
  64. Error_Handler();
  65. }
  66. if(USBD_Start(&hUsbDeviceFS) != USBD_OK) {
  67. Error_Handler();
  68. }
  69. /* USER CODE BEGIN USB_Device_Init_PostTreatment */
  70. /* USER CODE END USB_Device_Init_PostTreatment */
  71. }
  72. /**
  73. * @}
  74. */
  75. /**
  76. * @}
  77. */
  78. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/