diff --git a/src/platforms/common/cdcacm.c b/src/platforms/common/cdcacm.c index 25c7f10..3b0d62a 100644 --- a/src/platforms/common/cdcacm.c +++ b/src/platforms/common/cdcacm.c @@ -45,24 +45,16 @@ # include "traceswo.h" #endif #include "usbuart.h" -#include "serialno.h" -#include "version.h" -#include #include #include - -#include "usb_descriptors.h" - -usbd_device * usbdev; +#include static int configured; static int cdcacm_gdb_dtr = 1; static void cdcacm_set_modem_state(usbd_device *dev, int iface, bool dsr, bool dcd); -char serial_no[DFU_SERIAL_LENGTH]; - static void dfu_detach_complete(usbd_device *dev, struct usb_setup_data *req) { (void)dev; @@ -165,7 +157,7 @@ static void cdcacm_set_modem_state(usbd_device *dev, int iface, bool dsr, bool d usbd_ep_write_packet(dev, 0x82 + iface, buf, 10); } -static void cdcacm_set_config(usbd_device *dev, uint16_t wValue) +void cdcacm_set_config(usbd_device *dev, uint16_t wValue) { configured = wValue; @@ -208,19 +200,3 @@ static void cdcacm_set_config(usbd_device *dev, uint16_t wValue) cdcacm_set_modem_state(dev, GDB_IF_NO, true, true); cdcacm_set_modem_state(dev, UART_IF_NO, true, true); } - -/* We need a special large control buffer for this device: */ -static uint8_t usbd_control_buffer[256]; - -void blackmagic_usb_init(void) -{ - serial_no_read(serial_no); - - usbdev = usbd_init(&USB_DRIVER, &dev_desc, &config, usb_strings, sizeof(usb_strings) / sizeof(char *), - usbd_control_buffer, sizeof(usbd_control_buffer)); - - usbd_register_set_config_callback(usbdev, cdcacm_set_config); - - nvic_set_priority(USB_IRQ, IRQ_PRI_USB); - nvic_enable_irq(USB_IRQ); -} diff --git a/src/platforms/common/cdcacm.h b/src/platforms/common/cdcacm.h index c30c05c..e2e6bd1 100644 --- a/src/platforms/common/cdcacm.h +++ b/src/platforms/common/cdcacm.h @@ -31,6 +31,7 @@ #include "usb.h" void blackmagic_usb_init(void); +void cdcacm_set_config(usbd_device *dev, uint16_t wValue); /* Returns current usb configuration, or 0 if not configured. */ int cdcacm_get_config(void); int cdcacm_get_dtr(void); diff --git a/src/platforms/common/usb.c b/src/platforms/common/usb.c index 441984e..8155b94 100644 --- a/src/platforms/common/usb.c +++ b/src/platforms/common/usb.c @@ -18,8 +18,32 @@ * along with this program. If not, see . */ +#include + #include "general.h" #include "usb.h" +#include "usb_descriptors.h" +#include "cdcacm.h" +#include "serialno.h" + +char serial_no[DFU_SERIAL_LENGTH]; +usbd_device *usbdev = NULL; + +/* We need a special large control buffer for this device: */ +static uint8_t usbd_control_buffer[256]; + +void blackmagic_usb_init(void) +{ + serial_no_read(serial_no); + + usbdev = usbd_init(&USB_DRIVER, &dev_desc, &config, usb_strings, sizeof(usb_strings) / sizeof(char *), + usbd_control_buffer, sizeof(usbd_control_buffer)); + + usbd_register_set_config_callback(usbdev, cdcacm_set_config); + + nvic_set_priority(USB_IRQ, IRQ_PRI_USB); + nvic_enable_irq(USB_IRQ); +} void USB_ISR(void) { diff --git a/src/platforms/common/usb.h b/src/platforms/common/usb.h index 8ea94fe..f706b00 100644 --- a/src/platforms/common/usb.h +++ b/src/platforms/common/usb.h @@ -31,4 +31,14 @@ extern usbd_device *usbdev; #define CDCACM_UART_ENDPOINT 3 #define TRACE_ENDPOINT 5 +#define GDB_IF_NO 0 +#define UART_IF_NO 2 +#define DFU_IF_NO 4 +#ifdef PLATFORM_HAS_TRACESWO +#define TRACE_IF_NO 5 +#define TOTAL_INTERFACES 6 +#else +#define TOTAL_INTERFACES 5 +#endif + #endif /*USB_H*/ diff --git a/src/platforms/common/usb_descriptors.h b/src/platforms/common/usb_descriptors.h index 0e95702..370f4f5 100644 --- a/src/platforms/common/usb_descriptors.h +++ b/src/platforms/common/usb_descriptors.h @@ -26,19 +26,10 @@ #include #include "usb.h" +#include "version.h" #define BOARD_IDENT "Black Magic Probe " PLATFORM_IDENT FIRMWARE_VERSION -#define GDB_IF_NO 0 -#define UART_IF_NO 2 -#define DFU_IF_NO 4 -#ifdef PLATFORM_HAS_TRACESWO -#define TRACE_IF_NO 5 -#define TOTAL_INTERFACES 6 -#else -#define TOTAL_INTERFACES 5 -#endif - extern char serial_no[DFU_SERIAL_LENGTH]; /* Top-level device descriptor */