From 476f83b69ad86c71ee57c8633f09667e9caa0a5f Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 28 Feb 2015 22:48:26 -0800 Subject: Move common USB stuff out of platform header files. --- src/include/traceswo.h | 28 ---------------------- src/include/usbuart.h | 33 -------------------------- src/platforms/f4discovery/platform.h | 14 ----------- src/platforms/native/platform.c | 1 + src/platforms/native/platform.h | 14 ----------- src/platforms/stlink/platform.h | 14 ----------- src/platforms/stm32/cdcacm.c | 5 ++-- src/platforms/stm32/cdcacm.h | 45 ++++++++++++++++++++++++++++++++++++ src/platforms/stm32/gdb_if.c | 3 +-- src/platforms/stm32/traceswo.c | 3 +-- src/platforms/stm32/traceswo.h | 28 ++++++++++++++++++++++ src/platforms/stm32/usbuart.c | 3 ++- src/platforms/stm32/usbuart.h | 33 ++++++++++++++++++++++++++ src/platforms/swlink/platform.h | 14 ----------- 14 files changed, 114 insertions(+), 124 deletions(-) delete mode 100644 src/include/traceswo.h delete mode 100644 src/include/usbuart.h create mode 100644 src/platforms/stm32/cdcacm.h create mode 100644 src/platforms/stm32/traceswo.h create mode 100644 src/platforms/stm32/usbuart.h diff --git a/src/include/traceswo.h b/src/include/traceswo.h deleted file mode 100644 index 5566f94..0000000 --- a/src/include/traceswo.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of the Black Magic Debug project. - * - * Copyright (C) 2012 Black Sphere Technologies Ltd. - * Written by Gareth McMullin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef __TRACESWO_H -#define __TRACESWO_H - -#include - -void traceswo_init(void); -void trace_buf_drain(usbd_device *dev, uint8_t ep); - -#endif diff --git a/src/include/usbuart.h b/src/include/usbuart.h deleted file mode 100644 index 39f7dcd..0000000 --- a/src/include/usbuart.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the Black Magic Debug project. - * - * Copyright (C) 2012 Black Sphere Technologies Ltd. - * Written by Gareth McMullin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef __USBUART_H -#define __USBUART_H - -#include -#include -#include "general.h" - -void usbuart_init(void); - -void usbuart_set_line_coding(struct usb_cdc_line_coding *coding); -void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep); -void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep); - -#endif diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index dcad8a0..140e8d1 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -37,17 +37,12 @@ #include "gpio.h" #include "morse.h" -#define CDCACM_PACKET_SIZE 64 #define PLATFORM_HAS_TRACESWO #define BOARD_IDENT "Black Magic Probe (F4Discovery), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade) for F4Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define DFU_IDENT "Black Magic Firmware Upgrade (F4Discovery" #define DFU_IFACE_STRING "@Internal Flash /0x08000000/1*016Ka,3*016Kg,1*064Kg,7*128Kg" -extern usbd_device *usbdev; -#define CDCACM_GDB_ENDPOINT 1 -#define CDCACM_UART_ENDPOINT 3 - /* Important pin mappings for STM32 implementation: * * LED0 = PD12 (Green LED : Running) @@ -186,15 +181,6 @@ static inline int platform_hwversion(void) return 0; } -/* */ -void cdcacm_init(void); -/* Returns current usb configuration, or 0 if not configured. */ -int cdcacm_get_config(void); -int cdcacm_get_dtr(void); - -/* */ -void uart_usb_buf_drain(uint8_t ep); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index 3e269d9..3f61f5f 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -34,6 +34,7 @@ #include #include "jtag_scan.h" +#include "cdcacm.h" #include "usbuart.h" #include "morse.h" diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 2fa1e84..321c3f3 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -38,7 +38,6 @@ #include "gpio.h" #include "morse.h" -#define CDCACM_PACKET_SIZE 64 #define PLATFORM_HAS_TRACESWO #define PLATFORM_HAS_POWER_SWITCH #define BOARD_IDENT "Black Magic Probe" @@ -48,10 +47,6 @@ #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,120*001Kg" #define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" -extern usbd_device *usbdev; -#define CDCACM_GDB_ENDPOINT 1 -#define CDCACM_UART_ENDPOINT 3 - /* Important pin mappings for STM32 implementation: * * LED0 = PB2 (Yellow LED : Running) @@ -185,15 +180,6 @@ void platform_set_timeout(uint32_t ms); bool platform_timeout_expired(void); void platform_delay(uint32_t delay); -/* */ -void cdcacm_init(void); -/* Returns current usb configuration, or 0 if not configured. */ -int cdcacm_get_config(void); -int cdcacm_get_dtr(void); - -/* */ -void uart_usb_buf_drain(uint8_t ep); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index a49e73a..a33ca06 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -37,7 +37,6 @@ #include "gdb_packet.h" #include "gpio.h" -#define CDCACM_PACKET_SIZE 64 #define BOARD_IDENT "Black Magic Probe (STLINK), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -45,10 +44,6 @@ #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" #define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" -extern usbd_device *usbdev; -#define CDCACM_GDB_ENDPOINT 1 -#define CDCACM_UART_ENDPOINT 3 - /* Important pin mappings for STM32 implementation: * * LED0 = PB2 (Yellow LED : Running) @@ -161,15 +156,6 @@ const char *platform_target_voltage(void); void platform_delay(uint32_t delay); void platform_srst_set_val(bool assert); -/* */ -void cdcacm_init(void); -/* Returns current usb configuration, or 0 if not configured. */ -int cdcacm_get_config(void); -int cdcacm_get_dtr(void); - -/* */ -void uart_usb_buf_drain(uint8_t ep); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/stm32/cdcacm.c b/src/platforms/stm32/cdcacm.c index 9694cf0..074b534 100644 --- a/src/platforms/stm32/cdcacm.c +++ b/src/platforms/stm32/cdcacm.c @@ -35,10 +35,11 @@ #include "platform.h" #include "gdb_if.h" +#include "cdcacm.h" #if defined(PLATFORM_HAS_TRACESWO) -#include +#include "traceswo.h" #endif -#include +#include "usbuart.h" #define DFU_IF_NO 4 diff --git a/src/platforms/stm32/cdcacm.h b/src/platforms/stm32/cdcacm.h new file mode 100644 index 0000000..f64399d --- /dev/null +++ b/src/platforms/stm32/cdcacm.h @@ -0,0 +1,45 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2015 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* This file implements a the USB Communications Device Class - Abstract + * Control Model (CDC-ACM) as defined in CDC PSTN subclass 1.2. + * A Device Firmware Upgrade (DFU 1.1) class interface is provided for + * field firmware upgrade. + * + * The device's unique id is used as the USB serial number string. + */ +#ifndef __CDCACM_H +#define __CDCACM_H + +#include + +#define CDCACM_PACKET_SIZE 64 + +#define CDCACM_GDB_ENDPOINT 1 +#define CDCACM_UART_ENDPOINT 3 + +extern usbd_device *usbdev; + +void cdcacm_init(void); +/* Returns current usb configuration, or 0 if not configured. */ +int cdcacm_get_config(void); +int cdcacm_get_dtr(void); + +#endif diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c index c8208b3..6cc9084 100644 --- a/src/platforms/stm32/gdb_if.c +++ b/src/platforms/stm32/gdb_if.c @@ -23,8 +23,7 @@ * uses the USB CDC-ACM device bulk endpoints to implement the channel. */ #include "platform.h" -#include - +#include "cdcacm.h" #include "gdb_if.h" static uint32_t count_out; diff --git a/src/platforms/stm32/traceswo.c b/src/platforms/stm32/traceswo.c index 01ad728..29bae8f 100644 --- a/src/platforms/stm32/traceswo.c +++ b/src/platforms/stm32/traceswo.c @@ -37,10 +37,9 @@ #include #include -#include - #include #include "platform.h" +#include "cdcacm.h" void traceswo_init(void) { diff --git a/src/platforms/stm32/traceswo.h b/src/platforms/stm32/traceswo.h new file mode 100644 index 0000000..5566f94 --- /dev/null +++ b/src/platforms/stm32/traceswo.h @@ -0,0 +1,28 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2012 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef __TRACESWO_H +#define __TRACESWO_H + +#include + +void traceswo_init(void); +void trace_buf_drain(usbd_device *dev, uint8_t ep); + +#endif diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index f8f56bf..970a609 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -27,7 +27,8 @@ #include #include -#include +#include "platform.h" +#include "cdcacm.h" #define USBUART_TIMER_FREQ_HZ 1000000U /* 1us per tick */ #define USBUART_RUN_FREQ_HZ 5000U /* 200us (or 100 characters at 2Mbps) */ diff --git a/src/platforms/stm32/usbuart.h b/src/platforms/stm32/usbuart.h new file mode 100644 index 0000000..39f7dcd --- /dev/null +++ b/src/platforms/stm32/usbuart.h @@ -0,0 +1,33 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2012 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef __USBUART_H +#define __USBUART_H + +#include +#include +#include "general.h" + +void usbuart_init(void); + +void usbuart_set_line_coding(struct usb_cdc_line_coding *coding); +void usbuart_usb_out_cb(usbd_device *dev, uint8_t ep); +void usbuart_usb_in_cb(usbd_device *dev, uint8_t ep); + +#endif diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 4b26466..26cb7a6 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -37,7 +37,6 @@ #include "gdb_packet.h" #include "gpio.h" -#define CDCACM_PACKET_SIZE 64 #define BOARD_IDENT "Black Magic Probe (SWLINK), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade), STM8S Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_UPD "Black Magic (DFU Upgrade), STM8S Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -45,10 +44,6 @@ #define DFU_IFACE_STRING "@Internal Flash /0x08000000/8*001Ka,56*001Kg" #define UPD_IFACE_STRING "@Internal Flash /0x08000000/8*001Kg" -extern usbd_device *usbdev; -#define CDCACM_GDB_ENDPOINT 1 -#define CDCACM_UART_ENDPOINT 3 - /* Pin mappings: * * nTRST = PB1 @@ -158,15 +153,6 @@ int platform_init(void); const char *platform_target_voltage(void); void platform_delay(uint32_t delay); -/* */ -void cdcacm_init(void); -/* Returns current usb configuration, or 0 if not configured. */ -int cdcacm_get_config(void); -int cdcacm_get_dtr(void); - -/* */ -void uart_usb_buf_drain(uint8_t ep); - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf -- cgit v1.2.3