diff --git a/Makefile b/Makefile index c4197a7729..f818e81071 100644 --- a/Makefile +++ b/Makefile @@ -53,13 +53,13 @@ LINKER_DIR = $(ROOT)/src/main/target # Search path for sources VPATH := $(SRC_DIR):$(SRC_DIR)/startup +USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver +USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c)) ifeq ($(TARGET),$(filter $(TARGET),STM32F3DISCOVERY CHEBUZZF3 NAZE32PRO SPRACINGF3 SPARKY)) STDPERIPH_DIR = $(ROOT)/lib/main/STM32F30x_StdPeriph_Driver -USBFS_DIR = $(ROOT)/lib/main/STM32_USB-FS-Device_Driver -USBPERIPH_SRC = $(notdir $(wildcard $(USBFS_DIR)/src/*.c)) STDPERIPH_SRC = $(notdir $(wildcard $(STDPERIPH_DIR)/src/*.c)) EXCLUDES = stm32f30x_crc.c \ @@ -155,14 +155,26 @@ INCLUDE_DIRS := $(INCLUDE_DIRS) \ $(CMSIS_DIR)/CM3/CoreSupport \ $(CMSIS_DIR)/CM3/DeviceSupport/ST/STM32F10x \ +DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC) + +ifeq ($(TARGET),CC3D) +INCLUDE_DIRS := $(INCLUDE_DIRS) \ + $(USBFS_DIR)/inc \ + $(ROOT)/src/main/vcp + +VPATH := $(VPATH):$(USBFS_DIR)/src + +DEVICE_STDPERIPH_SRC := $(DEVICE_STDPERIPH_SRC) \ + $(USBPERIPH_SRC) + +endif + LD_SCRIPT = $(LINKER_DIR)/stm32_flash_f103_128k.ld ARCH_FLAGS = -mthumb -mcpu=cortex-m3 TARGET_FLAGS = -D$(TARGET) -pedantic DEVICE_FLAGS = -DSTM32F10X_MD -DSTM32F10X -DEVICE_STDPERIPH_SRC = $(STDPERIPH_SRC) - endif TARGET_DIR = $(ROOT)/src/main/target/$(TARGET) @@ -233,11 +245,21 @@ HIGHEND_SRC = flight/autotune.c \ telemetry/frsky.c \ telemetry/hott.c \ telemetry/msp.c \ - telemetry/smartport.c \ + telemetry/smartport.c \ sensors/sonar.c \ sensors/barometer.c \ blackbox/blackbox.c +VCP_SRC = \ + vcp/hw_config.c \ + vcp/stm32_it.c \ + vcp/usb_desc.c \ + vcp/usb_endp.c \ + vcp/usb_istr.c \ + vcp/usb_prop.c \ + vcp/usb_pwr.c \ + drivers/serial_usb_vcp.c + NAZE_SRC = startup_stm32f10x_md_gcc.S \ drivers/accgyro_adxl345.c \ drivers/accgyro_bma280.c \ @@ -403,7 +425,8 @@ CC3D_SRC = \ drivers/timer.c \ drivers/timer_stm32f10x.c \ $(HIGHEND_SRC) \ - $(COMMON_SRC) + $(COMMON_SRC) \ + $(VCP_SRC) STM32F30x_COMMON_SRC = \ startup_stm32f30x_md_gcc.S \ @@ -425,16 +448,6 @@ STM32F30x_COMMON_SRC = \ drivers/timer.c \ drivers/timer_stm32f30x.c -VCP_SRC = \ - vcp/hw_config.c \ - vcp/stm32_it.c \ - vcp/usb_desc.c \ - vcp/usb_endp.c \ - vcp/usb_istr.c \ - vcp/usb_prop.c \ - vcp/usb_pwr.c \ - drivers/serial_usb_vcp.c - NAZE32PRO_SRC = \ $(STM32F30x_COMMON_SRC) \ $(HIGHEND_SRC) \ diff --git a/src/main/io/serial.c b/src/main/io/serial.c index e9e9a47122..6a3d974b2b 100644 --- a/src/main/io/serial.c +++ b/src/main/io/serial.c @@ -106,12 +106,18 @@ const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT] = { #ifdef CC3D static serialPortFunction_t serialPortFunctions[SERIAL_PORT_COUNT] = { +#ifdef USE_VCP + {SERIAL_PORT_USB_VCP, NULL, SCENARIO_UNUSED, FUNCTION_NONE}, +#endif {SERIAL_PORT_USART1, NULL, SCENARIO_UNUSED, FUNCTION_NONE}, {SERIAL_PORT_USART3, NULL, SCENARIO_UNUSED, FUNCTION_NONE}, {SERIAL_PORT_SOFTSERIAL1, NULL, SCENARIO_UNUSED, FUNCTION_NONE} }; const serialPortConstraint_t serialPortConstraints[SERIAL_PORT_COUNT] = { +#ifdef USE_VCP + {SERIAL_PORT_USB_VCP, 9600, 115200, SPF_NONE }, +#endif {SERIAL_PORT_USART1, 9600, 115200, SPF_NONE | SPF_SUPPORTS_SBUS_MODE | SPF_SUPPORTS_BIDIR_MODE}, {SERIAL_PORT_USART3, 9600, 115200, SPF_SUPPORTS_CALLBACK | SPF_SUPPORTS_SBUS_MODE | SPF_SUPPORTS_BIDIR_MODE}, {SERIAL_PORT_SOFTSERIAL1, 9600, 19200, SPF_SUPPORTS_CALLBACK | SPF_IS_SOFTWARE_INVERTABLE} diff --git a/src/main/target/CC3D/target.h b/src/main/target/CC3D/target.h index 26a1358c61..a06d3540a6 100644 --- a/src/main/target/CC3D/target.h +++ b/src/main/target/CC3D/target.h @@ -60,10 +60,11 @@ #define BEEPER #define DISPLAY +#define USE_VCP #define USE_USART1 #define USE_USART3 #define USE_SOFTSERIAL1 -#define SERIAL_PORT_COUNT 3 +#define SERIAL_PORT_COUNT 4 #define SOFTSERIAL_1_TIMER TIM3 #define SOFTSERIAL_1_TIMER_TX_HARDWARE 1 // PWM 2 diff --git a/src/main/vcp/hw_config.c b/src/main/vcp/hw_config.c index 59cb84eb79..cb0600d132 100644 --- a/src/main/vcp/hw_config.c +++ b/src/main/vcp/hw_config.c @@ -92,11 +92,11 @@ void Set_System(void) GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; // HJI GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // HJI #else - RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // HJI + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // HJI - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;// HJI - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;// HJI - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;// HJI + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;// HJI + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;// HJI + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;// HJI #endif GPIO_Init(GPIOA, &GPIO_InitStructure); // HJI @@ -123,6 +123,13 @@ void Set_System(void) GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_14); #endif /* STM32F37X && STM32F303xC)*/ +#if defined(STM32F10X) + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; + GPIO_Init(GPIOA, &GPIO_InitStructure); +#endif /* Configure the EXTI line 18 connected internally to the USB IP */ EXTI_ClearITPendingBit(EXTI_Line18); diff --git a/src/main/vcp/hw_config.h b/src/main/vcp/hw_config.h index f077f6ddb5..ee40ed7085 100644 --- a/src/main/vcp/hw_config.h +++ b/src/main/vcp/hw_config.h @@ -32,7 +32,13 @@ /* Includes ------------------------------------------------------------------*/ //#include "platform_config.h" #include "usb_type.h" +#ifdef STM32F303 #include "stm32f30x.h" +#endif + +#ifdef STM32F10X +#include "stm32f10x.h" +#endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/