From a3ac3feae9b390b2167fbcd9cba676de57f5d959 Mon Sep 17 00:00:00 2001 From: pip Date: Wed, 13 Oct 2010 07:43:32 +0000 Subject: [PATCH] Added PipXtreme folder. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1954 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/PipXtreme/Makefile | 570 +++++++++++++++++++++++++++++ flight/PipXtreme/inc/pios_board.h | 255 +++++++++++++ flight/PipXtreme/inc/pios_config.h | 43 +++ flight/PipXtreme/inc/pipbee.h | 34 ++ flight/PipXtreme/pios_board.c | 262 +++++++++++++ 5 files changed, 1164 insertions(+) create mode 100644 flight/PipXtreme/Makefile create mode 100644 flight/PipXtreme/inc/pios_board.h create mode 100644 flight/PipXtreme/inc/pios_config.h create mode 100644 flight/PipXtreme/inc/pipbee.h create mode 100644 flight/PipXtreme/pios_board.c diff --git a/flight/PipXtreme/Makefile b/flight/PipXtreme/Makefile new file mode 100644 index 000000000..40ff26138 --- /dev/null +++ b/flight/PipXtreme/Makefile @@ -0,0 +1,570 @@ + ##### + # Project: OpenPilot PipBee Modems + # + # + # Makefile for OpenPilot PipBee project + # + # The OpenPilot Team, http://www.openpilot.org, Copyright (C) 2009. + # + # + # 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, write to the Free Software Foundation, Inc., + # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + ##### + + +# Set developer code and compile options +# Set to YES for debugging +DEBUG ?= YES +USE_BOOTLOADER ?= NO + +# Set to YES when using Code Sourcery toolchain +CODE_SOURCERY ?= YES + +# Toolchain prefix (i.e arm-elf- -> arm-elf-gcc.exe) +TCHAIN_PREFIX = arm-none-eabi- + +ifeq ($(CODE_SOURCERY), YES) +REMOVE_CMD = cs-rm +else +REMOVE_CMD = rm +endif + +FLASH_TOOL = OPENOCD + +# YES enables -mthumb option to flags for source-files listed +# in SRC and CPPSRC +USE_THUMB_MODE = YES + +# MCU name, submodel and board +# - MCU used for compiler-option (-mcpu) +# - MODEL used for linker-script name (-T) and passed as define +# - BOARD just passed as define (optional) +MCU = cortex-m3 +CHIP = STM32F103CBT +BOARD = STM32103CB_PIPBEE +ifeq ($(USE_BOOTLOADER), YES) +MODEL = MD +else +MODEL = MD +endif + +# Directory for output files (lst, obj, dep, elf, sym, map, hex, bin etc.) +OUTDIR = Build + +# Target file name (without extension). +TARGET = PipBee + +# Paths +PIPBEE = ./ +PIPBEEINC = $(PIPBEE)/inc +PIOS = ../PiOS +PIOSINC = $(PIOS)/inc +FLIGHTLIB = ../Libraries +FLIGHTLIBINC = ../Libraries/inc +PIOSSTM32F10X = $(PIOS)/STM32F10x +PIOSCOMMON = $(PIOS)/Common +APPLIBDIR = $(PIOSSTM32F10X)/Libraries +STMLIBDIR = $(APPLIBDIR) +STMSPDDIR = $(STMLIBDIR)/STM32F10x_StdPeriph_Driver +STMUSBDIR = $(STMLIBDIR)/STM32_USB-FS-Device_Driver +STMSPDSRCDIR = $(STMSPDDIR)/src +STMSPDINCDIR = $(STMSPDDIR)/inc +CMSISDIR = $(STMLIBDIR)/CMSIS/Core/CM3 + + +# List C source files here. (C dependencies are automatically generated.) +# use file-extension c for "c-only"-files + +## PipBee: +SRC = pipbee.c +SRC += pios_board.c + +## PIOS Hardware (STM32F10x) +SRC += $(PIOSSTM32F10X)/pios_sys.c +SRC += $(PIOSSTM32F10X)/pios_led.c +SRC += $(PIOSSTM32F10X)/pios_delay.c +SRC += $(PIOSSTM32F10X)/pios_usart.c +SRC += $(PIOSSTM32F10X)/pios_irq.c +SRC += $(PIOSSTM32F10X)/pios_adc.c +SRC += $(PIOSSTM32F10X)/pios_gpio.c +SRC += $(PIOSSTM32F10X)/pios_spi.c + +## PIOS Hardware (Common) +SRC += $(PIOSCOMMON)/pios_com.c +SRC += $(PIOSCOMMON)/printf-stdarg.c + +## CMSIS for STM32 +SRC += $(CMSISDIR)/core_cm3.c +SRC += $(CMSISDIR)/system_stm32f10x.c + +## Used parts of the STM-Library +SRC += $(STMSPDSRCDIR)/stm32f10x_adc.c +SRC += $(STMSPDSRCDIR)/stm32f10x_bkp.c +SRC += $(STMSPDSRCDIR)/stm32f10x_crc.c +SRC += $(STMSPDSRCDIR)/stm32f10x_dac.c +SRC += $(STMSPDSRCDIR)/stm32f10x_dma.c +SRC += $(STMSPDSRCDIR)/stm32f10x_exti.c +SRC += $(STMSPDSRCDIR)/stm32f10x_flash.c +SRC += $(STMSPDSRCDIR)/stm32f10x_gpio.c +SRC += $(STMSPDSRCDIR)/stm32f10x_pwr.c +SRC += $(STMSPDSRCDIR)/stm32f10x_rcc.c +SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c +SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c +SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c +SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c +SRC += $(STMSPDSRCDIR)/misc.c + +# List C source files here which must be compiled in ARM-Mode (no -mthumb). +# use file-extension c for "c-only"-files +## just for testing, timer.c could be compiled in thumb-mode too +SRCARM = + +# List C++ source files here. +# use file-extension .cpp for C++-files (not .C) +CPPSRC = + +# List C++ source files here which must be compiled in ARM-Mode. +# use file-extension .cpp for C++-files (not .C) +#CPPSRCARM = $(TARGET).cpp +CPPSRCARM = + +# List Assembler source files here. +# Make them always end in a capital .S. Files ending in a lowercase .s +# will not be considered source files but generated files (assembler +# output from the compiler), and will be deleted upon "make clean"! +# Even though the DOS/Win* filesystem matches both .s and .S the same, +# it will preserve the spelling of the filenames, and gcc itself does +# care about how the name is spelled on its command-line. +ASRC = $(PIOSSTM32F10X)/startup_stm32f10x_$(MODEL).S + +# List Assembler source files here which must be assembled in ARM-Mode.. +ASRCARM = + +# List any extra directories to look for include files here. +# Each directory must be seperated by a space. +EXTRAINCDIRS += $(PIOS) +EXTRAINCDIRS += $(PIOSINC) +EXTRAINCDIRS += $(FLIGHTLIBINC) +EXTRAINCDIRS += $(PIOSSTM32F10X) +EXTRAINCDIRS += $(PIOSCOMMON) +EXTRAINCDIRS += $(STMSPDINCDIR) +EXTRAINCDIRS += $(CMSISDIR) +EXTRAINCDIRS += $(PIPBEEINC) + +# List any extra directories to look for library files here. +# Also add directories where the linker should search for +# includes from linker-script to the list +# Each directory must be seperated by a space. +EXTRA_LIBDIRS = + +# Extra Libraries +# Each library-name must be seperated by a space. +# i.e. to link with libxyz.a, libabc.a and libefsl.a: +# EXTRA_LIBS = xyz abc efsl +# for newlib-lpc (file: libnewlibc-lpc.a): +# EXTRA_LIBS = newlib-lpc +EXTRA_LIBS = + +# Path to Linker-Scripts +LINKERSCRIPTPATH = $(PIOSSTM32F10X) + +# Optimization level, can be [0, 1, 2, 3, s]. +# 0 = turn off optimization. s = optimize for size. +# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) + +ifeq ($(DEBUG),YES) +OPT = 0 +else +OPT = s +endif + +# Output format. (can be ihex or binary or both) +# binary to create a load-image in raw-binary format i.e. for SAM-BA, +# ihex to create a load-image in Intel hex format +#LOADFORMAT = ihex +#LOADFORMAT = binary +LOADFORMAT = both + +# Debugging format. +DEBUGF = dwarf-2 + +# Place project-specific -D (define) and/or +# -U options for C here. +CDEFS = -DSTM32F10X_$(MODEL) +CDEFS += -DUSE_STDPERIPH_DRIVER +CDEFS += -DUSE_$(BOARD) + +# Place project-specific -D and/or -U options for +# Assembler with preprocessor here. +#ADEFS = -DUSE_IRQ_ASM_WRAPPER +ADEFS = -D__ASSEMBLY__ + +# Compiler flag to set the C Standard level. +# c89 - "ANSI" C +# gnu89 - c89 plus GCC extensions +# c99 - ISO C99 standard (not yet fully implemented) +# gnu99 - c99 plus GCC extensions +CSTANDARD = -std=gnu99 + +#----- + +# Compiler flags. + +# -g*: generate debugging information +# -O*: optimization level +# -f...: tuning, see GCC manual and avr-libc documentation +# -Wall...: warning level +# -Wa,...: tell GCC to pass this to the assembler. +# -adhlns...: create assembler listing +# +# Flags for C and C++ (arm-elf-gcc/arm-elf-g++) + +ifeq ($(DEBUG),YES) +CFLAGS = -g$(DEBUGF) +endif + +CFLAGS += -O$(OPT) +CFLAGS += -mcpu=$(MCU) -mthumb +CFLAGS += $(CDEFS) +CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I. + +CFLAGS += -mapcs-frame +CFLAGS += -fomit-frame-pointer +ifeq ($(CODE_SOURCERY), YES) +CFLAGS += -fpromote-loop-indices +endif + +CFLAGS += -Wall +CFLAGS += -Werror +CFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<)))) +# Compiler flags to generate dependency files: +CFLAGS += -MD -MP -MF $(OUTDIR)/dep/$(@F).d + +# flags only for C +#CONLYFLAGS += -Wnested-externs +CONLYFLAGS += $(CSTANDARD) + +# Assembler flags. +# -Wa,...: tell GCC to pass this to the assembler. +# -ahlns: create listing +ASFLAGS = -mcpu=$(MCU) -mthumb -I. -x assembler-with-cpp +ASFLAGS += $(ADEFS) +ASFLAGS += -Wa,-adhlns=$(addprefix $(OUTDIR)/, $(notdir $(addsuffix .lst, $(basename $<)))) +ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) + +MATH_LIB = -lm + +# Linker flags. +# -Wl,...: tell GCC to pass this to linker. +# -Map: create map file +# --cref: add cross reference to map file +LDFLAGS = -nostartfiles -Wl,-Map=$(OUTDIR)/$(TARGET).map,--cref,--gc-sections +LDFLAGS += $(patsubst %,-L%,$(EXTRA_LIBDIRS)) +LDFLAGS += -lc +LDFLAGS += $(patsubst %,-l%,$(EXTRA_LIBS)) +LDFLAGS += $(MATH_LIB) +LDFLAGS += -lc -lgcc + +# Set linker-script name depending on selected submodel name +LDFLAGS +=-T$(LINKERSCRIPTPATH)/link_stm32f10x_$(MODEL).ld + +# --------------------------------------------------------------------------- +# Options for OpenOCD flash-programming +# see openocd.pdf/openocd.texi for further information +# +OOCD_LOADFILE+=$(OUTDIR)/$(TARGET).elf +# if OpenOCD is in the $PATH just set OPENOCDEXE=openocd +OOCD_EXE=openocd +# debug level +OOCD_CL=-d0 +# interface and board/target settings (using the OOCD target-library here) +OOCD_CL+=-f ../Project/OpenOCD/floss-jtag.ahrs.cfg -f ../Project/OpenOCD/stm32.cfg +# initialize +OOCD_CL+=-c init +# show the targets +OOCD_CL+=-c targets +# commands to prepare flash-write +OOCD_CL+= -c "reset halt" +# flash erase +OOCD_CL+=-c "stm32x mass_erase 0" +# flash-write +OOCD_CL+=-c "flash write_image $(OOCD_LOADFILE)" +# Verify +OOCD_CL+=-c "verify_image $(OOCD_LOADFILE)" +# reset target +OOCD_CL+=-c "reset run" +# terminate OOCD after programming +OOCD_CL+=-c shutdown +# --------------------------------------------------------------------------- + + +# Define programs and commands. +CC = $(TCHAIN_PREFIX)gcc +CPP = $(TCHAIN_PREFIX)g++ +AR = $(TCHAIN_PREFIX)ar +OBJCOPY = $(TCHAIN_PREFIX)objcopy +OBJDUMP = $(TCHAIN_PREFIX)objdump +SIZE = $(TCHAIN_PREFIX)size +NM = $(TCHAIN_PREFIX)nm +REMOVE = $(REMOVE_CMD) -f +###SHELL = sh +###COPY = cp + + +# Define Messages +# English +MSG_ERRORS_NONE = Errors: none +MSG_BEGIN = "-------- begin (mode: $(RUN_MODE)) --------" +MSG_END = -------- end -------- +MSG_SIZE_BEFORE = Size before: +MSG_SIZE_AFTER = Size after build: +MSG_LOAD_FILE = Creating load file: +MSG_EXTENDED_LISTING = Creating Extended Listing/Disassembly: +MSG_SYMBOL_TABLE = Creating Symbol Table: +MSG_LINKING = "**** Linking :" +MSG_COMPILING = "**** Compiling C :" +MSG_COMPILING_ARM = "**** Compiling C (ARM-only):" +MSG_COMPILINGCPP = "Compiling C++ :" +MSG_COMPILINGCPP_ARM = "Compiling C++ (ARM-only):" +MSG_ASSEMBLING = "**** Assembling:" +MSG_ASSEMBLING_ARM = "****Assembling (ARM-only):" +MSG_CLEANING = Cleaning project: +MSG_FORMATERROR = Can not handle output-format +MSG_ASMFROMC = "Creating asm-File from C-Source:" +MSG_ASMFROMC_ARM = "Creating asm-File from C-Source (ARM-only):" + +# List of all source files. +ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC) +# List of all source files without directory and file-extension. +ALLSRCBASE = $(notdir $(basename $(ALLSRC))) + +# Define all object files. +ALLOBJ = $(addprefix $(OUTDIR)/, $(addsuffix .o, $(ALLSRCBASE))) + +# Define all listing files (used for make clean). +LSTFILES = $(addprefix $(OUTDIR)/, $(addsuffix .lst, $(ALLSRCBASE))) +# Define all depedency-files (used for make clean). +DEPFILES = $(addprefix $(OUTDIR)/dep/, $(addsuffix .o.d, $(ALLSRCBASE))) + +elf: $(OUTDIR)/$(TARGET).elf +lss: $(OUTDIR)/$(TARGET).lss +sym: $(OUTDIR)/$(TARGET).sym +hex: $(OUTDIR)/$(TARGET).hex +bin: $(OUTDIR)/$(TARGET).bin + +# Default target. +#all: begin gccversion sizebefore build sizeafter finished end +all: begin gccversion build sizeafter finished end + +ifeq ($(LOADFORMAT),ihex) +build: elf hex lss sym +else +ifeq ($(LOADFORMAT),binary) +build: elf bin lss sym +else +ifeq ($(LOADFORMAT),both) +build: elf hex bin lss sym +else +$(error "$(MSG_FORMATERROR) $(FORMAT)") +endif +endif +endif + + +# Eye candy. +begin: +## @echo + @echo $(MSG_BEGIN) + +finished: +## @echo $(MSG_ERRORS_NONE) + +end: + @echo $(MSG_END) +## @echo + +# Display sizes of sections. +ELFSIZE = $(SIZE) -A $(OUTDIR)/$(TARGET).elf +##ELFSIZE = $(SIZE) --format=Berkeley --common $(OUTDIR)/$(TARGET).elf +sizebefore: +# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi + +sizeafter: +# @if [ -f $(OUTDIR)/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi + @echo $(MSG_SIZE_AFTER) + $(ELFSIZE) + +# Display compiler version information. +gccversion : + @$(CC) --version +# @echo $(ALLOBJ) + +# Program the device. +ifeq ($(FLASH_TOOL),OPENOCD) +# Program the device with Dominic Rath's OPENOCD in "batch-mode", needs cfg and "reset-script". +program: $(OUTDIR)/$(TARGET).elf + @echo "Programming with OPENOCD" + $(OOCD_EXE) $(OOCD_CL) +endif + +# Create final output file (.hex) from ELF output file. +%.hex: %.elf +## @echo + @echo $(MSG_LOAD_FILE) $@ + $(OBJCOPY) -O ihex $< $@ + +# Create final output file (.bin) from ELF output file. +%.bin: %.elf +## @echo + @echo $(MSG_LOAD_FILE) $@ + $(OBJCOPY) -O binary $< $@ + +# Create extended listing file/disassambly from ELF output file. +# using objdump testing: option -C +%.lss: %.elf +## @echo + @echo $(MSG_EXTENDED_LISTING) $@ + $(OBJDUMP) -h -S -C -r $< > $@ +# $(OBJDUMP) -x -S $< > $@ + +# Create a symbol table from ELF output file. +%.sym: %.elf +## @echo + @echo $(MSG_SYMBOL_TABLE) $@ + $(NM) -n $< > $@ + +# Link: create ELF output file from object files. +.SECONDARY : $(TARGET).elf +.PRECIOUS : $(ALLOBJ) +%.elf: $(ALLOBJ) + @echo + @echo $(MSG_LINKING) $@ +# use $(CC) for C-only projects or $(CPP) for C++-projects: + $(CC) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) +# $(CPP) $(THUMB) $(CFLAGS) $(ALLOBJ) --output $@ $(LDFLAGS) + + +# Assemble: create object files from assembler source files. +define ASSEMBLE_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) +## @echo + @echo $(MSG_ASSEMBLING) $$< "->" $$@ + $(CC) -c $(THUMB) $$(ASFLAGS) $$< -o $$@ +endef +$(foreach src, $(ASRC), $(eval $(call ASSEMBLE_TEMPLATE, $(src)))) + +# Assemble: create object files from assembler source files. ARM-only +define ASSEMBLE_ARM_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) +## @echo + @echo $(MSG_ASSEMBLING_ARM) $$< "->" $$@ + $(CC) -c $$(ASFLAGS) $$< -o $$@ +endef +$(foreach src, $(ASRCARM), $(eval $(call ASSEMBLE_ARM_TEMPLATE, $(src)))) + + +# Compile: create object files from C source files. +define COMPILE_C_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) +## @echo + @echo $(MSG_COMPILING) $$< "->" $$@ + $(CC) -c $(THUMB) $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ +endef +$(foreach src, $(SRC), $(eval $(call COMPILE_C_TEMPLATE, $(src)))) + +# Compile: create object files from C source files. ARM-only +define COMPILE_C_ARM_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) +## @echo + @echo $(MSG_COMPILING_ARM) $$< "->" $$@ + $(CC) -c $$(CFLAGS) $$(CONLYFLAGS) $$< -o $$@ +endef +$(foreach src, $(SRCARM), $(eval $(call COMPILE_C_ARM_TEMPLATE, $(src)))) + + +# Compile: create object files from C++ source files. +define COMPILE_CPP_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) +## @echo + @echo $(MSG_COMPILINGCPP) $$< "->" $$@ + $(CC) -c $(THUMB) $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ +endef +$(foreach src, $(CPPSRC), $(eval $(call COMPILE_CPP_TEMPLATE, $(src)))) + +# Compile: create object files from C++ source files. ARM-only +define COMPILE_CPP_ARM_TEMPLATE +$(OUTDIR)/$(notdir $(basename $(1))).o : $(1) +## @echo + @echo $(MSG_COMPILINGCPP_ARM) $$< "->" $$@ + $(CC) -c $$(CFLAGS) $$(CPPFLAGS) $$< -o $$@ +endef +$(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CPP_ARM_TEMPLATE, $(src)))) + + +# Compile: create assembler files from C source files. ARM/Thumb +$(SRC:.c=.s) : %.s : %.c + @echo $(MSG_ASMFROMC) $< to $@ + $(CC) $(THUMB) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@ + +# Compile: create assembler files from C source files. ARM only +$(SRCARM:.c=.s) : %.s : %.c + @echo $(MSG_ASMFROMC_ARM) $< to $@ + $(CC) -S $(CFLAGS) $(CONLYFLAGS) $< -o $@ + +# Generate Doxygen documents +docs: + doxygen $(DOXYGENDIR)/doxygen.cfg + +# Target: clean project. +clean: begin clean_list finished end + +clean_list : +## @echo + @echo $(MSG_CLEANING) + $(REMOVE) $(OUTDIR)/$(TARGET).map + $(REMOVE) $(OUTDIR)/$(TARGET).elf + $(REMOVE) $(OUTDIR)/$(TARGET).hex + $(REMOVE) $(OUTDIR)/$(TARGET).bin + $(REMOVE) $(OUTDIR)/$(TARGET).sym + $(REMOVE) $(OUTDIR)/$(TARGET).lss + $(REMOVE) $(ALLOBJ) + $(REMOVE) $(LSTFILES) + $(REMOVE) $(DEPFILES) + $(REMOVE) $(SRC:.c=.s) + $(REMOVE) $(SRCARM:.c=.s) + $(REMOVE) $(CPPSRC:.cpp=.s) + $(REMOVE) $(CPPSRCARM:.cpp=.s) + + +# Create output files directory +# all known MS Windows OS define the ComSpec environment variable +ifdef ComSpec +$(shell md $(OUTDIR) 2>NUL) +else +$(shell mkdir $(OUTDIR) 2>/dev/null) +endif + +# Include the dependency files. +ifdef ComSpec +-include $(shell md $(OUTDIR)\dep 2>NUL) $(wildcard $(OUTDIR)/dep/*) +else +-include $(shell mkdir $(OUTDIR) 2>/dev/null) $(shell mkdir $(OUTDIR)/dep 2>/dev/null) $(wildcard $(OUTDIR)/dep/*) +endif + + + +# Listing of phony targets. +.PHONY : all begin finish end sizebefore sizeafter gccversion \ +build elf hex bin lss sym clean clean_list program + diff --git a/flight/PipXtreme/inc/pios_board.h b/flight/PipXtreme/inc/pios_board.h new file mode 100644 index 000000000..ff236f73c --- /dev/null +++ b/flight/PipXtreme/inc/pios_board.h @@ -0,0 +1,255 @@ + /** + ****************************************************************************** + * + * @file pios_board.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Defines board hardware for the OpenPilot Version 1.1 hardware. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef PIOS_BOARD_H +#define PIOS_BOARD_H + + +//------------------------ +// Timers and Channels Used +//------------------------ +/* +Timer | Channel 1 | Channel 2 | Channel 3 | Channel 4 +------+-----------+-----------+-----------+---------- +TIM1 | | | | +TIM2 | --------------- PIOS_DELAY ----------------- +TIM3 | | | | +TIM4 | | | | +TIM5 | | | | +TIM6 | | | | +TIM7 | | | | +TIM8 | | | | +------+-----------+-----------+-----------+---------- +*/ + +//------------------------ +// DMA Channels Used +//------------------------ +/* Channel 1 - */ +/* Channel 2 - */ +/* Channel 3 - */ +/* Channel 4 - */ +/* Channel 5 - */ +/* Channel 6 - */ +/* Channel 7 - */ +/* Channel 8 - */ +/* Channel 9 - */ +/* Channel 10 - */ +/* Channel 11 - */ +/* Channel 12 - */ + +//------------------------ +// PIOS_LED +//------------------------ +#define PIOS_LED_LED1_GPIO_PORT GPIOA // USB Activity LED +#define PIOS_LED_LED1_GPIO_PIN GPIO_Pin_3 +#define PIOS_LED_LED1_GPIO_CLK RCC_APB2Periph_GPIOA + +#define PIOS_LED_LED2_GPIO_PORT GPIOB // LINK LED +#define PIOS_LED_LED2_GPIO_PIN GPIO_Pin_5 +#define PIOS_LED_LED2_GPIO_CLK RCC_APB2Periph_GPIOB + +#define PIOS_LED_LED3_GPIO_PORT GPIOB // RX LED +#define PIOS_LED_LED3_GPIO_PIN GPIO_Pin_6 +#define PIOS_LED_LED3_GPIO_CLK RCC_APB2Periph_GPIOB + +#define PIOS_LED_LED4_GPIO_PORT GPIOB // TX LED +#define PIOS_LED_LED4_GPIO_PIN GPIO_Pin_7 +#define PIOS_LED_LED4_GPIO_CLK RCC_APB2Periph_GPIOB + +#define PIOS_LED_NUM 4 +#define PIOS_LED_PORTS { PIOS_LED_LED1_GPIO_PORT, PIOS_LED_LED2_GPIO_PORT, PIOS_LED_LED3_GPIO_PORT, PIOS_LED_LED4_GPIO_PORT } +#define PIOS_LED_PINS { PIOS_LED_LED1_GPIO_PIN, PIOS_LED_LED2_GPIO_PIN, PIOS_LED_LED3_GPIO_PIN, PIOS_LED_LED4_GPIO_PIN } +#define PIOS_LED_CLKS { PIOS_LED_LED1_GPIO_CLK, PIOS_LED_LED2_GPIO_CLK, PIOS_LED_LED3_GPIO_CLK, PIOS_LED_LED4_GPIO_CLK } + +#define USB_LED_ON PIOS_LED_On(LED1) +#define USB_LED_OFF PIOS_LED_Off(LED1) +#define USB_LED_TOGGLE PIOS_LED_Toggle(LED1) +#define LINK_LED_ON PIOS_LED_On(LED2) +#define LINK_LED_OFF PIOS_LED_Off(LED2) +#define LINK_LED_TOGGLE PIOS_LED_Toggle(LED2) +#define RX_LED_ON PIOS_LED_On(LED3) +#define RX_LED_OFF PIOS_LED_Off(LED3) +#define RX_LED_TOGGLE PIOS_LED_Toggle(LED3) +#define TX_LED_ON PIOS_LED_On(LED4) +#define TX_LED_OFF PIOS_LED_Off(LED4) +#define TX_LED_TOGGLE PIOS_LED_Toggle(LED4) + +//------------------------- +// Delay Timer +//------------------------- +#define PIOS_DELAY_TIMER TIM2 +#define PIOS_DELAY_TIMER_RCC_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE) + +//------------------------- +// System Settings +//------------------------- +#define PIOS_MASTER_CLOCK 72000000 +#define PIOS_PERIPHERAL_CLOCK (PIOS_MASTER_CLOCK / 2) +#if defined(USE_BOOTLOADER) +#define PIOS_NVIC_VECTTAB_FLASH ((uint32_t)0x08006000) +#else +#define PIOS_NVIC_VECTTAB_FLASH ((uint32_t)0x08000000) +#endif + +//------------------------- +// Interrupt Priorities +//------------------------- +#define PIOS_IRQ_PRIO_LOW 12 // lower than RTOS +#define PIOS_IRQ_PRIO_MID 8 // higher than RTOS +#define PIOS_IRQ_PRIO_HIGH 5 // for SPI, ADC, I2C etc... +#define PIOS_IRQ_PRIO_HIGHEST 4 // for USART etc... + +//------------------------- +// SPI +// +// See also pios_board.c +//------------------------- +#define PIOS_SPI_PERIF 0 + +//------------------------- +// PIOS_USART +//------------------------- + +#define PIOS_USART_RX_BUFFER_SIZE 512 +#define PIOS_USART_TX_BUFFER_SIZE 256 + +#define PIOS_COM_SERIAL 0 + +#define PIOS_COM_DEBUG PIOS_COM_SERIAL + +//------------------------- + +#if 0 +//------------------------- +// ADC +// PIOS_ADC_PinGet(0) = Accel Z +// PIOS_ADC_PinGet(1) = +// PIOS_ADC_PinGet(2) = +// PIOS_ADC_PinGet(3) = +// PIOS_ADC_PinGet(4) = Accel ? +// PIOS_ADC_PinGet(5) = +// PIOS_ADC_PinGet(6) = +// PIOS_ADC_PinGet(7) = +//------------------------- +//#define PIOS_ADC_OVERSAMPLING_RATE 1 +#define PIOS_ADC_USE_TEMP_SENSOR 0 +#define PIOS_ADC_TEMP_SENSOR_ADC ADC1 +#define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 1 + +#define PIOS_ADC_PIN1_GPIO_PORT GPIOB // PB1 (PSU Voltage) +#define PIOS_ADC_PIN1_GPIO_PIN GPIO_Pin_1 // ADC12_IN9 +#define PIOS_ADC_PIN1_GPIO_CHANNEL ADC_Channel_9 +#define PIOS_ADC_PIN1_ADC ADC2 +#define PIOS_ADC_PIN1_ADC_NUMBER 4 + +#define PIOS_ADC_NUM_PINS 1 + +#define PIOS_ADC_PORTS { PIOS_ADC_PIN1_GPIO_PORT } +#define PIOS_ADC_PINS { PIOS_ADC_PIN1_GPIO_PIN } +#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL } +#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC } +#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER } +#define PIOS_ADC_NUM_CHANNELS (PIOS_ADC_NUM_PINS + PIOS_ADC_USE_TEMP_SENSOR) +#define PIOS_ADC_NUM_ADC_CHANNELS 2 +#define PIOS_ADC_USE_ADC2 1 +#define PIOS_ADC_CLOCK_FUNCTION RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE) +#define PIOS_ADC_ADCCLK RCC_PCLK2_Div8 + /* RCC_PCLK2_Div2: ADC clock = PCLK2/2 */ + /* RCC_PCLK2_Div4: ADC clock = PCLK2/4 */ + /* RCC_PCLK2_Div6: ADC clock = PCLK2/6 */ + /* RCC_PCLK2_Div8: ADC clock = PCLK2/8 */ +#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_239Cycles5 + /* Sample time: */ + /* With an ADCCLK = 14 MHz and a sampling time of 293.5 cycles: */ + /* Tconv = 239.5 + 12.5 = 252 cycles = 18�s */ + /* (1 / (ADCCLK / CYCLES)) = Sample Time (�S) */ +#define PIOS_ADC_IRQ_PRIO PIOS_IRQ_PRIO_HIGH +#endif + +//------------------------- +// ADC +// PIOS_ADC_PinGet(0) = Accel Z +// PIOS_ADC_PinGet(1) = +// PIOS_ADC_PinGet(2) = +// PIOS_ADC_PinGet(3) = +// PIOS_ADC_PinGet(4) = Accel ? +// PIOS_ADC_PinGet(5) = +// PIOS_ADC_PinGet(6) = +// PIOS_ADC_PinGet(7) = +//------------------------- +//#define PIOS_ADC_OVERSAMPLING_RATE 1 +#define PIOS_ADC_USE_TEMP_SENSOR 0 +#define PIOS_ADC_TEMP_SENSOR_ADC ADC1 +#define PIOS_ADC_TEMP_SENSOR_ADC_CHANNEL 1 + +#define PIOS_ADC_PIN1_GPIO_PORT GPIOB // PB1 (PSU Voltage) +#define PIOS_ADC_PIN1_GPIO_PIN GPIO_Pin_1 // ADC12_IN9 +#define PIOS_ADC_PIN1_GPIO_CHANNEL ADC_Channel_9 +#define PIOS_ADC_PIN1_ADC ADC2 +#define PIOS_ADC_PIN1_ADC_NUMBER 4 + +#define PIOS_ADC_NUM_PINS 1 + +#define PIOS_ADC_PORTS { PIOS_ADC_PIN1_GPIO_PORT } +#define PIOS_ADC_PINS { PIOS_ADC_PIN1_GPIO_PIN } +#define PIOS_ADC_CHANNELS { PIOS_ADC_PIN1_GPIO_CHANNEL } +#define PIOS_ADC_MAPPING { PIOS_ADC_PIN1_ADC } +#define PIOS_ADC_CHANNEL_MAPPING { PIOS_ADC_PIN1_ADC_NUMBER } +#define PIOS_ADC_NUM_CHANNELS (PIOS_ADC_NUM_PINS + PIOS_ADC_USE_TEMP_SENSOR) +#define PIOS_ADC_NUM_ADC_CHANNELS 2 +#define PIOS_ADC_USE_ADC2 1 +#define PIOS_ADC_CLOCK_FUNCTION RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2, ENABLE) +#define PIOS_ADC_ADCCLK RCC_PCLK2_Div8 + /* RCC_PCLK2_Div2: ADC clock = PCLK2/2 */ + /* RCC_PCLK2_Div4: ADC clock = PCLK2/4 */ + /* RCC_PCLK2_Div6: ADC clock = PCLK2/6 */ + /* RCC_PCLK2_Div8: ADC clock = PCLK2/8 */ +#define PIOS_ADC_SAMPLE_TIME ADC_SampleTime_239Cycles5 + /* Sample time: */ + /* With an ADCCLK = 14 MHz and a sampling time of 293.5 cycles: */ + /* Tconv = 239.5 + 12.5 = 252 cycles = 18�s */ + /* (1 / (ADCCLK / CYCLES)) = Sample Time (�S) */ +#define PIOS_ADC_IRQ_PRIO PIOS_IRQ_PRIO_HIGH + +//------------------------- +// GPIO +//------------------------- + +#define PIOS_GPIO_1_PORT GPIOB +#define PIOS_GPIO_1_PIN GPIO_Pin_15 +#define PIOS_GPIO_1_GPIO_CLK RCC_APB2Periph_GPIOB +#define PIOS_GPIO_PORTS { PIOS_GPIO_1_PORT } +#define PIOS_GPIO_PINS { PIOS_GPIO_1_PIN } +#define PIOS_GPIO_CLKS { PIOS_GPIO_1_GPIO_CLK } +#define PIOS_GPIO_NUM 1 + +#define SET_RTS PIOS_GPIO_On(0); +#define CLEAR_RTS PIOS_GPIO_Off(0); + +//------------------------- + +#endif /* PIOS_BOARD_H */ diff --git a/flight/PipXtreme/inc/pios_config.h b/flight/PipXtreme/inc/pios_config.h new file mode 100644 index 000000000..e9df5eb1c --- /dev/null +++ b/flight/PipXtreme/inc/pios_config.h @@ -0,0 +1,43 @@ +/** + ****************************************************************************** + * + * @file pios_config.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief PiOS configuration header. + * - Central compile time config for the project. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef PIOS_CONFIG_H +#define PIOS_CONFIG_H + +/* Enable/Disable PiOS Modules */ +#define PIOS_INCLUDE_ADC +#define PIOS_INCLUDE_DELAY +#define PIOS_INCLUDE_IRQ +#define PIOS_INCLUDE_LED +#define PIOS_INCLUDE_SPI +#define PIOS_INCLUDE_SYS +#define PIOS_INCLUDE_USART +#define PIOS_INCLUDE_COM +#define PIOS_INCLUDE_GPIO + + +#endif /* PIOS_CONFIG_H */ diff --git a/flight/PipXtreme/inc/pipbee.h b/flight/PipXtreme/inc/pipbee.h new file mode 100644 index 000000000..72d22dfb0 --- /dev/null +++ b/flight/PipXtreme/inc/pipbee.h @@ -0,0 +1,34 @@ +/** + ****************************************************************************** + * + * @file pipbee.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Main PipBee header. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef PIPBEE_H +#define PIPBEE_H + + +/* PIOS Includes */ +#include + +#endif /* PIPBEE_H */ diff --git a/flight/PipXtreme/pios_board.c b/flight/PipXtreme/pios_board.c new file mode 100644 index 000000000..30cdf3fbe --- /dev/null +++ b/flight/PipXtreme/pios_board.c @@ -0,0 +1,262 @@ +/** + ****************************************************************************** + * + * @file pios_board.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Defines board specific static initializers for hardware for the PipBee board. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#if defined(PIOS_INCLUDE_SPI) + +#include + +/* OP Interface + * + * NOTE: Leave this declared as const data so that it ends up in the + * .rodata section (ie. Flash) rather than in the .bss section (RAM). + */ +void PIOS_SPI_perif_irq_handler(void); +void DMA1_Channel5_IRQHandler() __attribute__ ((alias ("PIOS_SPI_perif_irq_handler"))); +void DMA1_Channel4_IRQHandler() __attribute__ ((alias ("PIOS_SPI_perif_irq_handler"))); +static const struct pios_spi_cfg pios_spi_perif_cfg = +{ + .regs = SPI1, + .init = + { + .SPI_Mode = SPI_Mode_Master, + .SPI_Direction = SPI_Direction_2Lines_FullDuplex, + .SPI_DataSize = SPI_DataSize_8b, + .SPI_NSS = SPI_NSS_Soft, + .SPI_FirstBit = SPI_FirstBit_MSB, + .SPI_CRCPolynomial = 7, + .SPI_CPOL = SPI_CPOL_High, + .SPI_CPHA = SPI_CPHA_2Edge, + .SPI_BaudRatePrescaler = 7 << 3, /* Maximum divider (ie. slowest clock rate) */ + }, + .dma = + { + .ahb_clk = RCC_AHBPeriph_DMA1, + .irq = + { + .handler = PIOS_SPI_perif_irq_handler, + .flags = (DMA1_FLAG_TC4 | DMA1_FLAG_TE4 | DMA1_FLAG_HT4 | DMA1_FLAG_GL4), + .init = + { + .NVIC_IRQChannel = DMA1_Channel4_IRQn, + .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH, + .NVIC_IRQChannelSubPriority = 0, + .NVIC_IRQChannelCmd = ENABLE, + }, + }, + .rx = + { + .channel = DMA1_Channel4, + .init = + { + .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR), + .DMA_DIR = DMA_DIR_PeripheralSRC, + .DMA_PeripheralInc = DMA_PeripheralInc_Disable, + .DMA_MemoryInc = DMA_MemoryInc_Enable, + .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte, + .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte, + .DMA_Mode = DMA_Mode_Normal, + .DMA_Priority = DMA_Priority_Medium, + .DMA_M2M = DMA_M2M_Disable, + }, + }, + .tx = + { + .channel = DMA1_Channel5, + .init = + { + .DMA_PeripheralBaseAddr = (uint32_t)&(SPI1->DR), + .DMA_DIR = DMA_DIR_PeripheralDST, + .DMA_PeripheralInc = DMA_PeripheralInc_Disable, + .DMA_MemoryInc = DMA_MemoryInc_Enable, + .DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte, + .DMA_MemoryDataSize = DMA_MemoryDataSize_Byte, + .DMA_Mode = DMA_Mode_Normal, + .DMA_Priority = DMA_Priority_Medium, + .DMA_M2M = DMA_M2M_Disable, + }, + }, + }, + .ssel = + { + .gpio = GPIOA, + .init = + { + .GPIO_Pin = GPIO_Pin_4, + .GPIO_Speed = GPIO_Speed_10MHz, + .GPIO_Mode = GPIO_Mode_IN_FLOATING, + }, + }, + .sclk = + { + .gpio = GPIOA, + .init = + { + .GPIO_Pin = GPIO_Pin_5, + .GPIO_Speed = GPIO_Speed_10MHz, + .GPIO_Mode = GPIO_Mode_IN_FLOATING, + }, + }, + .miso = + { + .gpio = GPIOA, + .init = + { + .GPIO_Pin = GPIO_Pin_6, + .GPIO_Speed = GPIO_Speed_10MHz, + .GPIO_Mode = GPIO_Mode_AF_PP, + }, + }, + .mosi = + { + .gpio = GPIOA, + .init = + { + .GPIO_Pin = GPIO_Pin_7, + .GPIO_Speed = GPIO_Speed_10MHz, + .GPIO_Mode = GPIO_Mode_IN_FLOATING, + }, + }, +}; + +/* + * Board specific number of devices. + */ +struct pios_spi_dev pios_spi_devs[] = +{ + { + .cfg = &pios_spi_perif_cfg, + }, +}; + +uint8_t pios_spi_num_devices = NELEMENTS(pios_spi_devs); + +void PIOS_SPI_perif_irq_handler(void) +{ + /* Call into the generic code to handle the IRQ for this specific device */ + PIOS_SPI_IRQ_Handler(PIOS_SPI_PERIF); +} + +#endif /* PIOS_INCLUDE_SPI */ + +#if defined(PIOS_INCLUDE_USART) +#include + +/* + * SERIAL USART + */ +void PIOS_USART_serial_irq_handler(void); +void USART1_IRQHandler() __attribute__ ((alias ("PIOS_USART_serial_irq_handler"))); + +const struct pios_usart_cfg pios_usart_serial_cfg = +{ + .regs = USART1, + .init = + { + .USART_BaudRate = 57600, + .USART_WordLength = USART_WordLength_8b, + .USART_Parity = USART_Parity_No, + .USART_StopBits = USART_StopBits_1, + .USART_HardwareFlowControl = USART_HardwareFlowControl_None, + .USART_Mode = USART_Mode_Rx | USART_Mode_Tx, + }, + .irq = + { + .handler = PIOS_USART_serial_irq_handler, + .init = + { + .NVIC_IRQChannel = USART1_IRQn, + .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH, + .NVIC_IRQChannelSubPriority = 0, + .NVIC_IRQChannelCmd = ENABLE, + }, + }, + .rx = + { + .gpio = GPIOA, + .init = + { + .GPIO_Pin = GPIO_Pin_10, + .GPIO_Speed = GPIO_Speed_2MHz, + .GPIO_Mode = GPIO_Mode_IPU, + }, + }, + .tx = + { + .gpio = GPIOA, + .init = + { + .GPIO_Pin = GPIO_Pin_9, + .GPIO_Speed = GPIO_Speed_2MHz, + .GPIO_Mode = GPIO_Mode_AF_PP, + }, + }, +}; + +/* + * Board specific number of devices. + */ +struct pios_usart_dev pios_usart_devs[] = +{ +#define PIOS_USART_SERIAL 0 + { + .cfg = &pios_usart_serial_cfg, + }, +}; + +uint8_t pios_usart_num_devices = NELEMENTS(pios_usart_devs); + +void PIOS_USART_serial_irq_handler(void) +{ + PIOS_USART_IRQ_Handler(PIOS_USART_SERIAL); +} + +#endif /* PIOS_INCLUDE_USART */ + +#if defined(PIOS_INCLUDE_COM) +#include + +/* + * COM devices + */ + +/* + * Board specific number of devices. + */ +extern const struct pios_com_driver pios_usart_com_driver; + +struct pios_com_dev pios_com_devs[] = +{ + { + .id = PIOS_USART_SERIAL, + .driver = &pios_usart_com_driver, + }, +}; + +const uint8_t pios_com_num_devices = NELEMENTS(pios_com_devs); + +#endif /* PIOS_INCLUDE_COM */ +