[stm32] add usb_tunnel, cleanup setup makefile

also replace usb_tunnel_0 and usb_tunnel_1 on lpc with one usb_tunnel target with configurable uart
This commit is contained in:
Felix Ruess
2014-12-06 16:37:24 +01:00
parent 4a052097c7
commit 43d3b2c1e0
11 changed files with 196 additions and 105 deletions
+3 -2
View File
@@ -160,8 +160,9 @@
<firmware name="setup">
<target name="tunnel" board="tiny_1.1" />
<target name="usb_tunnel_0" board="tiny_1.1" />
<target name="usb_tunnel_1" board="tiny_1.1" />
<target name="usb_tunnel" board="tiny_1.1">
<configure name="TUNNEL_PORT" value="UART0"/>
</target>
<target name="setup_actuators" board="tiny_1.1" />
</firmware>
+3 -2
View File
@@ -212,8 +212,9 @@
<firmware name="setup">
<target name="tunnel" board="tiny_1.1" />
<target name="usb_tunnel_0" board="tiny_1.1" />
<target name="usb_tunnel_1" board="tiny_1.1" />
<target name="usb_tunnel" board="tiny_1.1">
<configure name="TUNNEL_PORT" value="UART0"/>
</target>
</firmware>
</airframe>
+3
View File
@@ -6,6 +6,9 @@
<firmware name="setup">
<target name="tunnel" board="lisa_m_2.0"/>
<target name="usb_tunnel" board="lisa_m_2.0">
<configure name="TUNNEL_PORT" value="UART3"/>
</target>
<target name="setup_actuators" board="lisa_m_2.0">
<subsystem name="actuators" type="pwm"/>
<define name="SERVO_HZ" value="400"/>
+3 -2
View File
@@ -31,8 +31,9 @@
<firmware name="setup">
<target name="tunnel" board="twog_1.0" />
<target name="usb_tunnel_0" board="twog_1.0" />
<target name="usb_tunnel_1" board="twog_1.0" />
<target name="usb_tunnel" board="twog_1.0">
<configure name="TUNNEL_PORT" value="UART0"/>
</target>
</firmware>
<modules>
+1 -1
View File
@@ -55,7 +55,7 @@
<firmware name="setup">
<target name="tunnel" board="twog_1.0" />
<target name="usb_tunnel_0" board="twog_1.0" />
<target name="usb_tunnel" board="twog_1.0"/>
</firmware>
<firmware name="test_progs">
-7
View File
@@ -216,11 +216,4 @@
<load name="infrared_adc.xml"/>
</modules>
<firmware name="setup">
<target name="tunnel" board="tiny_2.1" />
<target name="usb_tunnel_0" board="tiny_2.1" />
<target name="usb_tunnel_1" board="tiny_2.1" />
<target name="setup_actuators" board="tiny_2.1" />
</firmware>
</airframe>
+3 -2
View File
@@ -21,8 +21,9 @@
<firmware name="setup">
<target name="tunnel" board="tiny_2.11"/>
<target name="usb_tunnel_0" board="tiny_2.11"/>
<target name="usb_tunnel_1" board="tiny_2.11"/>
<target name="usb_tunnel" board="tiny_2.11">
<configure name="TUNNEL_PORT" value="UART0"/>
</target>
<target name="setup_actuators" board="tiny_2.11"/>
</firmware>
+97 -87
View File
@@ -3,65 +3,110 @@
#
#
SRC_ARCH=arch/$(ARCH)
SRC_BOARD=boards/$(BOARD)
SRC_SUBSYSTEMS=subsystems
SRC_MODULES=modules
CFG_SHARED=$(PAPARAZZI_SRC)/conf/firmwares/subsystems/shared
#CFG_SETUP=$(PAPARAZZI_SRC)/conf/firmwares/subsystems/setup
SRC_ARCH=arch/$(ARCH)
SRC_FIRMWARE=firmwares/setup
SRC_LISA=lisa
SETUP_INC = -I$(SRC_FIRMWARE)
$(TARGET).CFLAGS += -DBOARD_CONFIG=$(BOARD_CFG)
# a test program to tunnel between both uart
tunnel.CFLAGS += -DUSE_LED
tunnel.srcs += $(SRC_ARCH)/uart_tunnel.c
tunnel.srcs += mcu.c $(SRC_ARCH)/mcu_arch.c
ifeq ($(ARCH), stm32)
tunnel.ARCHDIR = $(ARCH)
tunnel.CFLAGS += -I$(ARCH) -DPERIPHERALS_AUTO_INIT
tunnel.srcs += $(SRC_ARCH)/mcu_periph/gpio_arch.c $(SRC_ARCH)/led_hw.c
ifneq ($(SYS_TIME_LED),none)
tunnel.CFLAGS += -DSYS_TIME_LED=$(SYS_TIME_LED)
endif
tunnel.CFLAGS += -DPERIODIC_FREQUENCY='512.'
tunnel.srcs += mcu_periph/sys_time.c $(SRC_ARCH)/mcu_periph/sys_time_arch.c
endif
# for the usb_tunnel we need to set PCLK higher with the flag USE_USB_HIGH_PCLK
# a configuration program to access both uart through usb
ifeq ($(ARCH), lpc21)
usb_tunnel_0.CFLAGS += -DUSE_UART0 -DUART0_BAUD=B115200 -DPERIPHERALS_AUTO_INIT
usb_tunnel_0.CFLAGS += -DUSE_USB_LINE_CODING -DUSE_USB_SERIAL -DUSE_LED -DUSE_USB_HIGH_PCLK
usb_tunnel_0.srcs += $(SRC_ARCH)/usb_tunnel.c $(SRC_ARCH)/usb_ser_hw.c mcu_periph/uart.c $(SRC_ARCH)/mcu_periph/uart_arch.c
usb_tunnel_0.srcs += $(SRC_ARCH)/lpcusb/usbhw_lpc.c $(SRC_ARCH)/lpcusb/usbinit.c
usb_tunnel_0.srcs += $(SRC_ARCH)/lpcusb/usbcontrol.c $(SRC_ARCH)/lpcusb/usbstdreq.c
usb_tunnel_0.srcs += mcu_periph/sys_time.c $(SRC_ARCH)/mcu_periph/sys_time_arch.c $(SRC_ARCH)/armVIC.c
usb_tunnel_0.srcs += mcu.c $(SRC_ARCH)/mcu_arch.c
usb_tunnel_1.CFLAGS += -DUSE_UART1 -DUART1_BAUD=B115200 -DPERIPHERALS_AUTO_INIT
usb_tunnel_1.CFLAGS += -DUSE_USB_LINE_CODING -DUSE_USB_SERIAL -DUSE_LED -DUSE_USB_HIGH_PCLK
usb_tunnel_1.srcs += $(SRC_ARCH)/usb_tunnel.c $(SRC_ARCH)/usb_ser_hw.c mcu_periph/uart.c $(SRC_ARCH)/mcu_periph/uart_arch.c
usb_tunnel_1.srcs += $(SRC_ARCH)/lpcusb/usbhw_lpc.c $(SRC_ARCH)/lpcusb/usbinit.c
usb_tunnel_1.srcs += $(SRC_ARCH)/lpcusb/usbcontrol.c $(SRC_ARCH)/lpcusb/usbstdreq.c
usb_tunnel_1.srcs += mcu_periph/sys_time.c $(SRC_ARCH)/mcu_periph/sys_time_arch.c $(SRC_ARCH)/armVIC.c
usb_tunnel_1.srcs += mcu.c $(SRC_ARCH)/mcu_arch.c
else
ifeq ($(TARGET),usb_tunnel_0)
$(error usb_tunnel_0 currently only implemented for the lpc21)
else ifeq ($(TARGET),usb_tunnel_1)
$(error usb_tunnel_1 currently only implemented for the lpc21)
endif
endif
#
# common setup
#
# configuration
# SYS_TIME_LED
# MODEM_PORT
# MODEM_BAUD
#
PERIODIC_FREQUENCY ?= 512
COMMON_SETUP_CFLAGS = -I$(SRC_BOARD) -DBOARD_CONFIG=$(BOARD_CFG)
COMMON_SETUP_CFLAGS += -DPERIPHERALS_AUTO_INIT
COMMON_SETUP_SRCS = mcu.c $(SRC_ARCH)/mcu_arch.c
ifneq ($(SYS_TIME_LED),none)
COMMON_SETUP_CFLAGS += -DSYS_TIME_LED=$(SYS_TIME_LED)
endif
COMMON_SETUP_CFLAGS += -DPERIODIC_FREQUENCY=$(PERIODIC_FREQUENCY)
COMMON_SETUP_SRCS += mcu_periph/sys_time.c $(SRC_ARCH)/mcu_periph/sys_time_arch.c
COMMON_SETUP_CFLAGS += -DUSE_LED
ifeq ($(ARCH), lpc21)
COMMON_SETUP_SRCS += $(SRC_ARCH)/armVIC.c
else ifeq ($(ARCH), stm32)
COMMON_SETUP_SRCS += $(SRC_ARCH)/led_hw.c
COMMON_SETUP_SRCS += $(SRC_ARCH)/mcu_periph/gpio_arch.c
endif
#
# a test program to tunnel between both uart
#
tunnel.ARCHDIR = $(ARCH)
tunnel.CFLAGS += $(COMMON_SETUP_CFLAGS)
tunnel.srcs += $(COMMON_SETUP_SRCS)
tunnel.srcs += $(SRC_ARCH)/uart_tunnel.c
#
# usb tunnel
#
# a configuration program to access a uart through usb
#
# configuration:
# TUNNEL_PORT (defaults to GPS_PORT)
# TUNNEL_BAUD
#
usb_tunnel.ARCHDIR = $(ARCH)
usb_tunnel.CFLAGS += $(COMMON_SETUP_CFLAGS)
usb_tunnel.srcs += $(COMMON_SETUP_SRCS)
usb_tunnel.srcs += mcu_periph/uart.c $(SRC_ARCH)/mcu_periph/uart_arch.c
TUNNEL_PORT ?= GPS_PORT
TUNNEL_PORT_LOWER=$(shell echo $(TUNNEL_PORT) | tr A-Z a-z)
TUNNEL_PORT_UPPER=$(shell echo $(TUNNEL_PORT) | tr a-z A-Z)
TUNNEL_BAUD ?= B115200
usb_tunnel.CFLAGS += -DUSE_$(TUNNEL_PORT_UPPER) -D$(TUNNEL_PORT_UPPER)_BAUD=$(TUNNEL_BAUD)
usb_tunnel.CFLAGS += -DUSB_TUNNEL_UART=$(TUNNEL_PORT_LOWER)
usb_tunnel.CFLAGS += -DUSE_USB_LINE_CODING -DUSE_USB_SERIAL
usb_tunnel.srcs += $(SRC_ARCH)/usb_tunnel.c $(SRC_ARCH)/usb_ser_hw.c
ifeq ($(ARCH), lpc21)
# for the usb_tunnel we need to set PCLK higher with the flag USE_USB_HIGH_PCLK
usb_tunnel.CFLAGS += -DUSE_USB_HIGH_PCLK
usb_tunnel.srcs += $(SRC_ARCH)/lpcusb/usbhw_lpc.c $(SRC_ARCH)/lpcusb/usbinit.c
usb_tunnel.srcs += $(SRC_ARCH)/lpcusb/usbcontrol.c $(SRC_ARCH)/lpcusb/usbstdreq.c
else ifeq($(ARCH), stm32)
else
ifeq ($(TARGET),usb_tunnel)
$(error usb_tunnel is only implemented for lpc21 and stm32)
endif
endif
#
# setup actuators
#
setup_actuators.ARCHDIR = $(ARCH)
setup_actuators.CFLAGS += $(COMMON_SETUP_CFLAGS)
setup_actuators.srcs += $(COMMON_SETUP_SRCS)
setup_actuators.srcs += mcu_periph/uart.c $(SRC_ARCH)/mcu_periph/uart_arch.c
setup_actuators.CFLAGS += -DUSE_$(MODEM_PORT)
setup_actuators.CFLAGS += -D$(MODEM_PORT)_BAUD=$(MODEM_BAUD)
SETUP_ACTUATORS_MODEM_PORT_LOWER=$(shell echo $(MODEM_PORT) | tr A-Z a-z)
setup_actuators.CFLAGS += -DDOWNLINK -DDOWNLINK_DEVICE=$(SETUP_ACTUATORS_MODEM_PORT_LOWER) -DPPRZ_UART=$(MODEM_PORT)
setup_actuators.CFLAGS += -DDOWNLINK_TRANSPORT=pprz_tp -DDATALINK=PPRZ
setup_actuators.srcs += subsystems/datalink/downlink.c subsystems/datalink/pprz_transport.c
setup_actuators.srcs += subsystems/actuators.c
setup_actuators.srcs += $(SRC_FIRMWARE)/setup_actuators.c
ifeq ($(TARGET), setup_actuators)
ifeq ($(ACTUATORS),)
$(error ACTUATORS not configured, if your board file has no default, configure in your airframe file)
@@ -69,38 +114,3 @@ ifeq ($(TARGET), setup_actuators)
include $(CFG_SHARED)/$(ACTUATORS).makefile
endif
endif
# a test program to setup actuators
setup_actuators.CFLAGS += -DUSE_LED -DPERIPHERALS_AUTO_INIT
setup_actuators.srcs += mcu.c $(SRC_ARCH)/mcu_arch.c
ifneq ($(SYS_TIME_LED),none)
setup_actuators.CFLAGS += -DSYS_TIME_LED=$(SYS_TIME_LED)
endif
setup_actuators.srcs += mcu_periph/sys_time.c $(SRC_ARCH)/mcu_periph/sys_time_arch.c
setup_actuators.CFLAGS += -DUSE_$(MODEM_PORT)
setup_actuators.CFLAGS += -D$(MODEM_PORT)_BAUD=$(MODEM_BAUD)
setup_actuators.srcs += mcu_periph/uart.c $(SRC_ARCH)/mcu_periph/uart_arch.c
SETUP_ACTUATORS_MODEM_PORT_LOWER=$(shell echo $(MODEM_PORT) | tr A-Z a-z)
setup_actuators.CFLAGS += -DDOWNLINK -DDOWNLINK_DEVICE=$(SETUP_ACTUATORS_MODEM_PORT_LOWER) -DPPRZ_UART=$(MODEM_PORT)
setup_actuators.CFLAGS += -DDOWNLINK_TRANSPORT=pprz_tp -DDATALINK=PPRZ
setup_actuators.srcs += subsystems/datalink/downlink.c subsystems/datalink/pprz_transport.c
# we actually don't really use the generated periodic telemetry in this firmware,
# but still needed to register e.g. the UART_ERRORS message #if DOWNLINK
setup_actuators.CFLAGS += -DDefaultPeriodic='&telemetry_Main'
setup_actuators.srcs += subsystems/datalink/telemetry.c
setup_actuators.CFLAGS += -DPERIODIC_FREQUENCY=$(PERIODIC_FREQUENCY)
setup_actuators.srcs += subsystems/actuators.c
setup_actuators.srcs += $(SRC_FIRMWARE)/setup_actuators.c
ifeq ($(ARCH), lpc21)
setup_actuators.srcs += $(SRC_ARCH)/armVIC.c
else ifeq ($(ARCH), stm32)
setup_actuators.ARCHDIR = $(ARCH)
setup_actuators.CFLAGS += -I$(ARCH)
setup_actuators.srcs += $(SRC_ARCH)/led_hw.c
setup_actuators.srcs += $(SRC_ARCH)/mcu_periph/gpio_arch.c
endif
+2
View File
@@ -46,6 +46,8 @@
#endif
#endif
INFO_VAR(USB_TUNNEL_UART)
int main( void ) {
unsigned char inc;
unsigned int rx_time=0, tx_time=0;
+2 -2
View File
@@ -483,8 +483,8 @@ void VCOM_transmit_message()
* USE_USB_LINE_CODING is not used in case of example1, example2 and telemetry
*/
#ifdef USE_USB_LINE_CODING
void VCOM_allow_linecoding(uint8_t mode) {}
void VCOM_set_linecoding(uint8_t mode) {}
void VCOM_allow_linecoding(uint8_t mode __attribute__((unused))) {}
void VCOM_set_linecoding(uint8_t mode __attribute__((unused))) {}
#endif
/*
+79
View File
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2009 Martin Mueller
* 2014 Felix Ruess <felix.ruess@gmail.com
*
* This file is part of paparazzi.
*
* paparazzi 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 2, or (at your option)
* any later version.
*
* paparazzi 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 paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
/**
* @file usb_tunnel.c
*
* USB tunnel application.
*
* This creates a USB serial port that connects to one of the UARTs.
* This enables you to e.g. configure the gps receiver or the modem without removing it.
*/
#include "std.h"
#include "mcu.h"
#include "mcu_periph/sys_time.h"
#include "led.h"
#include "mcu_periph/uart.h"
#include "mcu_periph/usb_serial.h"
#ifndef USB_TUNNEL_UART
#error USB_TUNNEL_UART not defined. Add <configure name="TUNNEL_PORT" value="UARTx"/>
#endif
INFO_VAR(USB_TUNNEL_UART)
static void tunnel_event(void)
{
static unsigned char inc;
if (uart_char_available(&USB_TUNNEL_UART) && VCOM_check_free_space(1)) {
inc = uart_getch(&USB_TUNNEL_UART);
VCOM_putchar(inc);
}
if (VCOM_check_available() && uart_check_free_space(&USB_TUNNEL_UART, 1)) {
inc = VCOM_getchar();
uart_transmit(&USB_TUNNEL_UART, inc);
}
}
int main(void)
{
mcu_init();
sys_time_init();
led_init();
VCOM_allow_linecoding(1);
VCOM_init();
mcu_int_enable();
while(1) {
VCOM_event();
tunnel_event();
}
return 0;
}