diff --git a/src/platforms/stlink/cdcacm.c b/src/platforms/stlink/cdcacm.c index db54185..a2a4510 100644 --- a/src/platforms/stlink/cdcacm.c +++ b/src/platforms/stlink/cdcacm.c @@ -27,17 +27,19 @@ */ #include -#include +#include #include #include #include #include -#include +#include #include #include #include "platform.h" +usbd_device * usbdev; + static char *get_dev_unique_id(char *serial_no); static int configured; @@ -197,9 +199,12 @@ static const char *usb_strings[] = { "Black Magic GDB Server", }; -static int cdcacm_control_request(struct usb_setup_data *req, uint8_t **buf, - uint16_t *len, void (**complete)(struct usb_setup_data *req)) +static int cdcacm_control_request( + usbd_device *dev, + struct usb_setup_data *req, uint8_t **buf, uint16_t *len, + void (**complete)(usbd_device *dev, struct usb_setup_data *req)) { + (void)dev; (void)complete; (void)buf; (void)len; @@ -237,16 +242,18 @@ int cdcacm_get_dtr(void) return cdcacm_gdb_dtr; } -static void cdcacm_set_config(u16 wValue) +static void cdcacm_set_config(usbd_device *dev, u16 wValue) { configured = wValue; /* GDB interface */ - usbd_ep_setup(0x01, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, NULL); - usbd_ep_setup(0x81, USB_ENDPOINT_ATTR_BULK, CDCACM_PACKET_SIZE, NULL); - usbd_ep_setup(0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); + usbd_ep_setup(dev, 0x01, USB_ENDPOINT_ATTR_BULK, + CDCACM_PACKET_SIZE, NULL); + usbd_ep_setup(dev, 0x81, USB_ENDPOINT_ATTR_BULK, + CDCACM_PACKET_SIZE, NULL); + usbd_ep_setup(dev, 0x82, USB_ENDPOINT_ATTR_INTERRUPT, 16, NULL); - usbd_register_control_callback( + usbd_register_control_callback(dev, USB_REQ_TYPE_CLASS | USB_REQ_TYPE_INTERFACE, USB_REQ_TYPE_TYPE | USB_REQ_TYPE_RECIPIENT, cdcacm_control_request); @@ -264,24 +271,29 @@ static void cdcacm_set_config(u16 wValue) notif->wLength = 2; buf[8] = 3; /* DCD | DSR */ buf[9] = 0; - usbd_ep_write_packet(0x82, buf, 10); + usbd_ep_write_packet(dev, 0x82, buf, 10); } +/* We need a special large control buffer for this device: */ +uint8_t usbd_control_buffer[256]; + void cdcacm_init(void) { void exti15_10_isr(void); get_dev_unique_id(serial_no); - usbd_init(&stm32f103_usb_driver, &dev, &config, usb_strings); - usbd_register_set_config_callback(cdcacm_set_config); + usbdev = usbd_init(&stm32f103_usb_driver, + &dev, &config, usb_strings, 7); + usbd_set_control_buffer_size(usbdev, sizeof(usbd_control_buffer)); + usbd_register_set_config_callback(usbdev, cdcacm_set_config); nvic_enable_irq(NVIC_USB_LP_CAN_RX0_IRQ); } void usb_lp_can_rx0_isr(void) { - usbd_poll(); + usbd_poll(usbdev); } static char *get_dev_unique_id(char *s) diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index 836a2e9..f28764f 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -23,9 +23,9 @@ */ #include -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index fb55441..d804abc 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -25,6 +25,7 @@ #define __PLATFORM_H #include +#include #include #include @@ -33,6 +34,8 @@ #define INLINE_GPIO #define CDCACM_PACKET_SIZE 64 + +extern usbd_device *usbdev; #define CDCACM_GDB_ENDPOINT 1 /* Important pin mappings for STM32 implementation: