add some tests

This commit is contained in:
Felix Ruess
2013-10-22 17:39:15 +02:00
parent e0c3b23c7b
commit dd38f018d2
4 changed files with 278 additions and 5 deletions
@@ -29,6 +29,12 @@
<subsystem name="ins"/>
</firmware>
<firmware name="test_progs">
<target name="test_lis302dl" board="stm32f4_discovery">
<define name="STM32F4_DISCOVERY_SPI1_FOR_LIS302"/>
</target>
</firmware>
<modules main_freq="512">
<load name="baro_ets.xml">
<define name="BARO_ETS_SCALE" value="40.0"/>
+153
View File
@@ -0,0 +1,153 @@
# Hey Emacs, this is a -*- makefile -*-
#
# Copyright (C) 2013 The Paparazzi Team
#
# 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.
#
################################################################################
#
#
# Common test programs for the all LPC21 and STM32 boards
#
################################################################################
SRC_ARCH=arch/$(ARCH)
SRC_BOARD=boards/$(BOARD)
SRC_SUBSYSTEMS=subsystems
SRC_MODULES=modules
CFG_SHARED=$(PAPARAZZI_SRC)/conf/firmwares/subsystems/shared
#
# common test
#
# configuration
# SYS_TIME_LED
# MODEM_PORT
# MODEM_BAUD
#
PERIODIC_FREQUENCY ?= 512
COMMON_TEST_CFLAGS = -I$(SRC_BOARD) -DBOARD_CONFIG=$(BOARD_CFG)
COMMON_TEST_CFLAGS += -DPERIPHERALS_AUTO_INIT
COMMON_TEST_SRCS = mcu.c $(SRC_ARCH)/mcu_arch.c
COMMON_TEST_SRCS += $(SRC_ARCH)/mcu_periph/gpio_arch.c
COMMON_TEST_CFLAGS += -DUSE_SYS_TIME
ifneq ($(SYS_TIME_LED),none)
COMMON_TEST_CFLAGS += -DSYS_TIME_LED=$(SYS_TIME_LED)
endif
COMMON_TEST_CFLAGS += -DPERIODIC_FREQUENCY=$(PERIODIC_FREQUENCY)
COMMON_TEST_SRCS += mcu_periph/sys_time.c $(SRC_ARCH)/mcu_periph/sys_time_arch.c
COMMON_TEST_CFLAGS += -DUSE_LED
COMMON_TEST_SRCS += $(SRC_ARCH)/led_hw.c
COMMON_TELEMETRY_CFLAGS = -DUSE_$(MODEM_PORT) -D$(MODEM_PORT)_BAUD=$(MODEM_BAUD)
COMMON_TELEMETRY_CFLAGS += -DDOWNLINK -DDOWNLINK_TRANSPORT=PprzTransport -DDOWNLINK_DEVICE=$(MODEM_PORT)
COMMON_TELEMETRY_SRCS = mcu_periph/uart.c
COMMON_TELEMETRY_SRCS += $(SRC_ARCH)/mcu_periph/uart_arch.c
COMMON_TELEMETRY_SRCS += subsystems/datalink/downlink.c subsystems/datalink/pprz_transport.c
#COMMON_TEST_SRCS += math/pprz_trig_int.c
#
# test sys_time
#
ifeq ($(BOARD), lisa_m)
ifeq ($(BOARD_VERSION), 2.0)
LED_DEFINES = -DLED_BLUE=3 -DLED_RED=4 -DLED_GREEN=5
endif
endif
LED_DEFINES ?= -DLED_RED=2 -DLED_GREEN=3
test_sys_time_timer.ARCHDIR = $(ARCH)
test_sys_time_timer.CFLAGS += $(COMMON_TEST_CFLAGS) $(LED_DEFINES)
test_sys_time_timer.srcs += $(COMMON_TEST_SRCS)
test_sys_time_timer.srcs += $(SRC_AIRBORNE)/test/mcu_periph/test_sys_time_timer.c
test_sys_time_usleep.ARCHDIR = $(ARCH)
test_sys_time_usleep.CFLAGS += $(COMMON_TEST_CFLAGS) $(LED_DEFINES)
test_sys_time_usleep.srcs += $(COMMON_TEST_SRCS)
test_sys_time_usleep.srcs += $(SRC_AIRBORNE)/test/mcu_periph/test_sys_time_usleep.c
#
# test_telemetry : Sends ALIVE telemetry messages
#
# configuration
# MODEM_PORT :
# MODEM_BAUD :
#
test_telemetry.ARCHDIR = $(ARCH)
test_telemetry.CFLAGS += $(COMMON_TEST_CFLAGS)
test_telemetry.srcs += $(COMMON_TEST_SRCS)
test_telemetry.CFLAGS += $(COMMON_TELEMETRY_CFLAGS)
test_telemetry.srcs += $(COMMON_TELEMETRY_SRCS)
test_telemetry.srcs += test/test_telemetry.c
#
# test ms2100 mag
#
test_ms2100.ARCHDIR = $(ARCH)
test_ms2100.CFLAGS += $(COMMON_TEST_CFLAGS)
test_ms2100.srcs += $(COMMON_TEST_SRCS)
test_ms2100.CFLAGS += $(COMMON_TELEMETRY_CFLAGS)
test_ms2100.srcs += $(COMMON_TELEMETRY_SRCS)
test_ms2100.srcs += test/peripherals/test_ms2100.c
test_ms2100.srcs += peripherals/ms2100.c $(SRC_ARCH)/peripherals/ms2100_arch.c
test_ms2100.CFLAGS += -DUSE_SPI -DSPI_MASTER
test_ms2100.srcs += mcu_periph/spi.c $(SRC_ARCH)/mcu_periph/spi_arch.c
ifeq ($(ARCH), lpc21)
test_ms2100.CFLAGS += -DUSE_SPI1
test_ms2100.CFLAGS += -DUSE_SPI_SLAVE1
test_ms2100.CFLAGS += -DMS2100_SLAVE_IDX=1
test_ms2100.CFLAGS += -DMS2100_SPI_DEV=spi1
test_ms2100.CFLAGS += -DMS2100_DRDY_VIC_SLOT=12
else ifeq ($(ARCH), stm32)
test_ms2100.CFLAGS += -DUSE_SPI2
test_ms2100.CFLAGS += -DUSE_SPI_SLAVE4
test_ms2100.CFLAGS += -DMS2100_SLAVE_IDX=4
test_ms2100.CFLAGS += -DMS2100_SPI_DEV=spi2
endif
#
# test lis302dl accelerometer
#
test_lis302dl.ARCHDIR = $(ARCH)
test_lis302dl.CFLAGS += $(COMMON_TEST_CFLAGS)
test_lis302dl.srcs += $(COMMON_TEST_SRCS)
test_lis302dl.CFLAGS += $(COMMON_TELEMETRY_CFLAGS)
test_lis302dl.srcs += $(COMMON_TELEMETRY_SRCS)
test_lis302dl.srcs += test/peripherals/test_lis302dl_spi.c
test_lis302dl.srcs += peripherals/lis302dl_spi.c
test_lis302dl.CFLAGS += -DUSE_SPI -DSPI_MASTER
test_lis302dl.srcs += mcu_periph/spi.c $(SRC_ARCH)/mcu_periph/spi_arch.c
test_lis302dl.CFLAGS += -DUSE_SPI1
test_lis302dl.CFLAGS += -DUSE_SPI_SLAVE2
test_lis302dl.CFLAGS += -DLIS302DL_SLAVE_IDX=2
test_lis302dl.CFLAGS += -DLIS302DL_SPI_DEV=spi1
+16 -5
View File
@@ -7,9 +7,9 @@
* PA2 = PWM7
* PA3 = PWM6
* PA4 = ADC_4 (ADC12 IN 4)+CS43L22 DAC out, capacitively coupled+100Kohm, should not interfere.
* PA5 = FREE
* PA6 = CANNOT BE USED
* PA7 = FREE
* PA5 = SPI1 SCK if STM32F4_DISCOVERY_SPI1_FOR_LIS302
* PA6 = SPI1 MISO if STM32F4_DISCOVERY_SPI1_FOR_LIS302
* PA7 = SPI1 MOSI if STM32F4_DISCOVERY_SPI1_FOR_LIS302
* PA8 = SPECTRUM BIND
* PA9 = FREE (ONLY if usb is not active during runtime, PC0 must be high or input )
* PA10 = UART2 (Spektrum input)
@@ -73,7 +73,7 @@
* PE0 = CANNOT BE USED (Accel int output)
* PE1 = CANNOT BE USED (Accel int output)
* PE2 = SPI SLAVE 0
* PE3 = FREE (Needs some testing as it is used for the accel spi/i2c select pin)
* PE3 = SPI SLAVE 2 (used for the LIS302DL accel spi/i2c select pin)
* PE4 = FREE
* PE5 = PWM4
* PE6 = PWM5
@@ -214,6 +214,15 @@
/************************************** SPI *************************************************/
/***************************************************************************************************/
#if STM32F4_DISCOVERY_SPI1_FOR_LIS302
#define SPI1_GPIO_AF GPIO_AF5
#define SPI1_GPIO_PORT_SCK GPIOA
#define SPI1_GPIO_SCK GPIO5
#define SPI1_GPIO_PORT_MISO GPIOA
#define SPI1_GPIO_MISO GPIO6
#define SPI1_GPIO_PORT_MOSI GPIOA
#define SPI1_GPIO_MOSI GPIO7
#else
#define SPI1_GPIO_AF GPIO_AF5
#define SPI1_GPIO_PORT_SCK GPIOB
#define SPI1_GPIO_SCK GPIO3
@@ -221,7 +230,7 @@
#define SPI1_GPIO_MISO GPIO4
#define SPI1_GPIO_PORT_MOSI GPIOB
#define SPI1_GPIO_MOSI GPIO5
#endif
/* CANNOT BE USED IF PWM CHANNELS 10 & 11 ARE ACTIVE !!! */
#define SPI2_GPIO_AF GPIO_AF5
@@ -245,6 +254,8 @@
#define SPI_SELECT_SLAVE0_PIN GPIO2
#define SPI_SELECT_SLAVE1_PORT GPIOE
#define SPI_SELECT_SLAVE1_PIN GPIO7
#define SPI_SELECT_SLAVE2_PORT GPIOE
#define SPI_SELECT_SLAVE2_PIN GPIO3
/***************************************************************************************************/
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2013 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 test/peripherals/test_lis302dl_spi.c
*
* Test for LIS302DL 3-axis accelerometer from ST using SPI.
*/
#include BOARD_CONFIG
#include "mcu.h"
#include "mcu_periph/sys_time.h"
#include "mcu_periph/uart.h"
#include "subsystems/datalink/downlink.h"
#include "led.h"
#include "peripherals/lis302dl_spi.h"
#ifndef LIS302DL_SPI_DEV
#define LIS302DL_SPI_DEV spi2
#endif
PRINT_CONFIG_VAR(LIS302DL_SPI_DEV)
#ifndef LIS302DL_SPI_SLAVE_IDX
#define LIS302DL_SPI_SLAVE_IDX SPI_SLAVE2
#endif
PRINT_CONFIG_VAR(LIS302DL_SPI_SLAVE_IDX)
struct Lis302dl_Spi lis302;
static inline void main_init( void );
static inline void main_periodic_task( void );
static inline void main_event_task( void );
int main(void) {
main_init();
while(1) {
if (sys_time_check_and_ack_timer(0))
main_periodic_task();
main_event_task();
}
return 0;
}
static inline void main_init( void ) {
mcu_init();
mcu_int_enable();
sys_time_register_timer((1./50), NULL);
lis302dl_spi_init(&lis302, &(LIS302DL_SPI_DEV), LIS302DL_SPI_SLAVE_IDX);
}
static inline void main_periodic_task( void ) {
RunOnceEvery(100, DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM));
if (sys_time.nb_sec > 1) {
lis302dl_spi_periodic(&lis302);
#if USE_LED_5
RunOnceEvery(10, LED_TOGGLE(5););
#endif
}
}
static inline void main_event_task( void ) {
if (sys_time.nb_sec > 1)
lis302dl_spi_event(&lis302);
if (lis302.data_available) {
struct Int32Vect3 accel;
VECT3_COPY(accel, lis302.data.vect);
lis302.data_available = FALSE;
RunOnceEvery(10, {
DOWNLINK_SEND_IMU_ACCEL_RAW(DefaultChannel, DefaultDevice,
&accel.x, &accel.y, &accel.z);
#if USE_LED_6
LED_TOGGLE(6);
#endif
});
}
}