usb_device.c 957 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "usb_device.h"
  2. #include "stm32wbxx.h"
  3. #include "stm32wbxx_hal.h"
  4. #include "usbd_def.h"
  5. #include "usbd_core.h"
  6. #include "usbd_desc.h"
  7. #include "usbd_cdc.h"
  8. #include "usbd_cdc_if.h"
  9. extern void Error_Handler(void);
  10. /* USB Device Core handle declaration. */
  11. USBD_HandleTypeDef hUsbDeviceFS;
  12. extern USBD_DescriptorsTypeDef CDC_Desc;
  13. /** Init USB device Library, add supported class and start the library */
  14. void MX_USB_Device_Init(void) {
  15. /* Init Device Library, add supported class and start the library. */
  16. if (USBD_Init(&hUsbDeviceFS, &CDC_Desc, DEVICE_FS) != USBD_OK) {
  17. Error_Handler();
  18. }
  19. if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK) {
  20. Error_Handler();
  21. }
  22. if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK) {
  23. Error_Handler();
  24. }
  25. if (USBD_Start(&hUsbDeviceFS) != USBD_OK) {
  26. Error_Handler();
  27. }
  28. }