#include "project.h" #define USB_DM GPIO11 #define USB_DM_PORT GPIOA #define USB_DP GPIO12 #define USB_DP_PORT GPIOA /* Buffer to be used for control requests. */ uint8_t usbd_control_buffer[128]; usbd_device *usb_device; static const struct usb_device_descriptor dev = { .bLength = USB_DT_DEVICE_SIZE, .bDescriptorType = USB_DT_DEVICE, .bcdUSB = 0x0200, .bDeviceClass = USB_CLASS_CDC, .bDeviceSubClass = 0, .bDeviceProtocol = 0, .bMaxPacketSize0 = 64, .idVendor = ID_VENDOR, .idProduct = ID_PRODUCT, .bcdDevice = 0x0200, .iManufacturer = 1, .iProduct = 2, .iSerialNumber = 3, .bNumConfigurations = 1, }; static const struct usb_interface ifaces[] = { { .num_altsetting = 1, .altsetting = &comm_iface, }, { .num_altsetting = 1, .altsetting = &data_iface, }, { .num_altsetting = 1, .altsetting = &dfu_iface, }, }; static const struct usb_config_descriptor config = { .bLength = USB_DT_CONFIGURATION_SIZE, .bDescriptorType = USB_DT_CONFIGURATION, .wTotalLength = 0, .bNumInterfaces = 3, .bConfigurationValue = 1, .iConfiguration = 0, .bmAttributes = 0x80, .bMaxPower = 0x32, .interface = ifaces, }; static const char *usb_strings[] = { VENDOR_NAME, PRODUCT_NAME, SERIAL_NUMBER, "DFU", }; void otg_fs_isr (void) { usbd_poll (usb_device); } void usb_init (void) { MAP_AF_100 (USB_DP, GPIO_AF10); MAP_AF_100 (USB_DM, GPIO_AF10); usb_device = usbd_init (&otgfs_usb_driver, &dev, &config, usb_strings, 4, usbd_control_buffer, sizeof (usbd_control_buffer)); /* Disable VBUS sensing */ OTG_FS_GCCFG |= OTG_GCCFG_NOVBUSSENS; OTG_FS_GCCFG &= ~OTG_GCCFG_VBUSASEN; OTG_FS_GCCFG &= ~OTG_GCCFG_VBUSBSEN; usbd_register_set_config_callback (usb_device, cdcacm_set_config); nvic_enable_irq (NVIC_OTG_FS_IRQ); }