Revision e75a39881befb1d84749919b28e0dd03f1a03efb authored by Felix Ruess on 29 May 2012, 20:27:07 UTC, committed by Felix Ruess on 29 May 2012, 20:27:07 UTC
* currently only used for rotorcrafts
* created and imu_nps implementation instead of using the sim arch to implement simulation of every IMU separately
* updated makefiles and airframe files to new nps simulator
1 parent fedf204
Raw File
Makefile.stm32
# Hey Emacs, this is a -*- makefile -*-
#
#   $Id$
#   Copyright (C) 2009 Antoine Drouin
#
# 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.
#

#
# This is the common Makefile for the stm32-target.
#

SRC_ARCH = arch/stm32

# Pretty Printer
# Call with "make Q=''" to get full command display
Q=@

MCU   = cortex-m3
#DEBUG = dwarf-2
OPT   = s
#OPT   = 2
#OPT   = 0

# Programs location
TOOLCHAIN=$(shell find -L /opt/paparazzi/arm-multilib ~/sat /opt/paparazzi/stm32 -maxdepth 1 -type d -name arm-none-eabi 2>/dev/null | head -n 1)
ifneq ($(TOOLCHAIN),)
TOOLCHAIN_DIR=$(shell dirname $(TOOLCHAIN))
GCC_BIN_DIR=$(TOOLCHAIN_DIR)/bin
GCC_LIB_DIR=$(TOOLCHAIN_DIR)/arm-none-eabi/lib

# Define programs and commands.
GCC_BIN_PREFIX=$(GCC_BIN_DIR)/arm-none-eabi
CC   = $(GCC_BIN_PREFIX)-gcc
LD   = $(GCC_BIN_PREFIX)-gcc
CP   = $(GCC_BIN_PREFIX)-objcopy
DMP  = $(GCC_BIN_PREFIX)-objdump
NM   = $(GCC_BIN_PREFIX)-nm
SIZE = $(GCC_BIN_PREFIX)-size
GDB  = $(GCC_BIN_PREFIX)-gdb
RM   = rm

# If we can't find the toolchain then try picking up the compilers from the path
else
CC   = $(shell which arm-none-eabi-gcc)
LD   = $(shell which arm-none-eabi-gcc)
CP   = $(shell which arm-none-eabi-objcopy)
DMP  = $(shell which arm-none-eabi-objdump)
NM   = $(shell which arm-none-eabi-nm)
SIZE = $(shell which arm-none-eabi-size)
GDB  = $(shell which arm-none-eabi-gdb)
RM   = rm
TOOLCHAIN_DIR=$(shell dirname `which arm-none-eabi-gcc`)
GCC_LIB_DIR=$(TOOLCHAIN_DIR)/../arm-none-eabi/lib
endif

# Detect if we are using the new libopencm3 or the old libopenstm32
LIBOPENCM3_LIB=$(shell if [ -e "$(GCC_LIB_DIR)/libopencm3_stm32f1.a" ]; then echo "opencm3_stm32f1"; else echo "opencm3_stm32"; fi)
LIBOPENCM3_DEFS=$(shell if [ -e "$(GCC_LIB_DIR)/libopencm3_stm32f1.a" ]; then echo "-DSTM32F1"; fi)

ifndef $(PYTHON)
PYTHON = $(shell which python)
endif

#first try to find OpenOCD in the path
OOCD = $(shell which openocd)
#if OpenOCD could not be found in the path, try the toolchain dir
ifeq ($(OOCD),)
ifneq ($(TOOLCHAIN),)
OOCD = $(shell if test -e $(TOOLCHAIN_DIR)/bin/openocd ; then echo $(TOOLCHAIN_DIR)/bin/openocd ; else echo "Warning: OpenOCD not found"; fi)
endif
endif

ifneq ($(BOARD_SERIAL),)
OOCD_OPTIONS = -c "ft2232_serial $(BOARD_SERIAL)"
endif

LOADER=/home/poine/work/stm32/stm32loader-a3c51c26ad6c/stm32loader.py

ifndef $(TARGET).OOCD_INTERFACE
OOCD_INTERFACE = lisa-l
else
OOCD_INTERFACE =  $($(TARGET).OOCD_INTERFACE)
endif

ifndef $(TARGET).OOCD_BOARD
OOCD_BOARD = lisa-l
else
OOCD_BOARD =  $($(TARGET).OOCD_BOARD)
endif

# default: assume the luftboot bootloader is used
# if luftboot is not used define NO_LUFTBOOT to a value != 0
OOCD_START_SECTOR = 4
ASSUMING_LUFTBOOT = "yes"
ifdef NO_LUFTBOOT
$(shell echo luftboot: $(NO_LUFTBOOT))
ifneq ($(NO_LUFTBOOT),0)
OOCD_START_SECTOR = 0
ASSUMING_LUFTBOOT = "no"
endif
endif

# input files
SRCS = $($(TARGET).srcs)
#ASRC =

# object files
COBJ    = $(SRCS:%.c=$(OBJDIR)/%.o)
AOBJ    = $(ASRC:%.S=$(OBJDIR)/%.o)

# linker script :
#   if LDSCRIPT is defined in the airframe use that independantly of TARGET
#   if not, and a TARGET.LDSCRIPT is defined, use that
#   if not, use the default STM32f103re_flash.ld
ifndef LDSCRIPT
ifndef $(TARGET).LDSCRIPT
LDSCRIPT = $(SRC_ARCH)/stm32f103re_flash.ld
else
LDSCRIPT = $($(TARGET).LDSCRIPT)
endif
endif

#UNAME = $(shell uname -s)
MULTILIB = $(shell if $(CC) --print-multi-lib | grep thumb2 > /dev/null ; then echo "yes"; else echo "no"; fi)

CFLAGS = -I. -I./$(ARCH) $(INCLUDES) -D__thumb2__ -Wall -msoft-float -O$(OPT)
CFLAGS += -Wl,--gc-sections
CFLAGS += -mcpu=$(MCU) -mthumb -ansi
ifeq ("$(MULTILIB)","yes")
CFLAGS += -mfix-cortex-m3-ldrd
endif
CFLAGS += -std=gnu99
#CFLAGS += -malignment-traps
CFLAGS += -fno-common
CFLAGS += -g$(DEBUG)
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -Wimplicit
CFLAGS += -Wcast-align
CFLAGS += -Wpointer-arith -Wswitch
CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow -Wunused
CFLAGS += -Wa,-adhlns=$(OBJDIR)/$(notdir $(subst $(suffix $<),.lst,$<))
CFLAGS += -Wnested-externs
CFLAGS += -Wmissing-prototypes
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wmissing-declarations
CFLAGS += -Wswitch-default
CFLAGS += $(LIBOPENCM3_DEFS)

CFLAGS += $($(TARGET).CFLAGS)

AFLAGS  = -ahls -mapcs-32
ifeq ("$(MULTILIB)","yes")
AFLAGS += -mcpu=$(MCU) -mthumb
endif
AFLAGS += -x assembler-with-cpp -Wa,-adhlns=$(OBJDIR)/$(<:.S=.lst),--g$(DEBUG)

ifeq ("$(MULTILIB)","yes")
LDFLAGS = -T$(LDSCRIPT) -nostartfiles -O$(OPT) -mthumb -march=armv7 -mfix-cortex-m3-ldrd -msoft-float
else
LDFLAGS = -D__thumb2__ -T$(LDSCRIPT) -nostartfiles  -L$(GCC_LIB_DIR) -O$(OPT)
endif
LDFLAGS += -Wl,-Map=$(OBJDIR)/$(TARGET).map,--cref,--gc-sections
LDLIBS  += -lc -lm -lgcc -lcmsis -lstm32 -l$(LIBOPENCM3_LIB)

CPFLAGS = -j .isr_vector -j .text -j .data
CPFLAGS_BIN = -Obinary
CPFLAGS_HEX = -Oihex

ODFLAGS = -S



# Default target.
all: printcommands printmultilib sizebefore build sizeafter

printcommands:
	@echo "Using CC   = $(CC)"
	@echo "Using LD   = $(LD)"
	@echo "Using CP   = $(CP)"
	@echo "Using DMP  = $(DMP)"
	@echo "Using NM   = $(NM)"
	@echo "Using SIZE = $(SIZE)"
	@echo "GCC version:"
	@$(CC) --version | head -1

ifeq ("$(MULTILIB)","yes")
printmultilib:
	@echo "*** Using multilib ***"
	@echo "--------------------------------------"
else
printmultilib:
	@echo "*** NOT using multilib ***"
	@echo "--------------------------------------"
endif

build: elf bin hex
# lss sym

elf: $(OBJDIR)/$(TARGET).elf
bin: $(OBJDIR)/$(TARGET).bin
hex: $(OBJDIR)/$(TARGET).hex
lss: $(OBJDIR)/$(TARGET).lss
sym: $(OBJDIR)/$(TARGET).sym

# Display size of file.
ELFSIZE = $(SIZE) -Ax $(OBJDIR)/$(TARGET).elf
sizebefore:
	@if [ -f $(OBJDIR)/$(TARGET).elf ]; then echo; echo "Previous size:"; $(ELFSIZE); fi

sizeafter:
	@if [ -f $(OBJDIR)/$(TARGET).elf ]; then echo; echo "Current size:"; $(ELFSIZE); fi



%.bin: %.elf
	@echo OBJCB $@
	$(Q)$(CP) $(CPFLAGS) $(CPFLAGS_BIN) $< $@

%.hex: %.elf
	@echo OBJCH $@
	$(Q)$(CP) $(CPFLAGS) $(CPFLAGS_HEX) $< $@

# Create extended listing file from ELF output file.
# testing: option -C
%.lss: %.elf
	@echo OBJD $@
	$(Q)$(DMP) -h -S -C $< > $@


# Create a symbol table from ELF output file.
%.sym: %.elf
	@echo NM $@
	$(Q)$(NM) -n $< > $@


# Link: create ELF output file from object files.
.SECONDARY : $(OBJDIR)/$(TARGET).elf
.PRECIOUS : $(COBJ) $(AOBJ)
%.elf:  $(COBJ) $(AOBJ)
	@echo LD $@
	$(Q)$(LD) $(LDFLAGS) $($(TARGET).LDFLAGS) -o $@ $(COBJ) $(AOBJ) $(LDLIBS)

# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.c $(OBJDIR)/../Makefile.ac
	@echo CC $@
	$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
	$(Q)$(CC) -c $(CFLAGS) $< -o $@

# Assemble: create object files from assembler source files. ARM/Thumb
$(AOBJ) : $(OBJDIR)/%.o : %.S
	@echo AS $@
	$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
	$(Q)$(CC) -c $(AFLAGS) $< -o $@

ifeq ($(FLASH_MODE),DFU)
upload: $(OBJDIR)/$(TARGET).bin
	@echo "Using stm32 mem dfu loader"
	$(PYTHON) $(PAPARAZZI_SRC)/sw/tools/dfu/stm32_mem.py $^
else ifeq ($(FLASH_MODE),SERIAL)
upload: $(OBJDIR)/$(TARGET).bin
	$(LOADER) -p /dev/ttyUSB0  -b 115200 -e -w -v $^
else ifeq ($(FLASH_MODE),JTAG)
ifeq ($(BMP_PORT),)
upload: $(OBJDIR)/$(TARGET).hex
	@echo "Assuming luftboot bootloader: $(ASSUMING_LUFTBOOT)"
	@echo "Using OOCD = $(OOCD)"
	@echo "  OOCD\t$<"
	$(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
		-f board/$(OOCD_BOARD).cfg $(OOCD_OPTIONS) \
		-c init \
		-c "reset halt" \
		-c "reset init" \
		-c "flash erase_sector 0 $(OOCD_START_SECTOR) last" \
		-c "flash write_image $<" \
		-c reset \
		-c shutdown
else
upload: $(OBJDIR)/$(TARGET).elf
	@echo "Using Black Magic Probe"
	@echo "Using GDB = $(GDB)"
	@echo "  BMP\t$<"
	$(Q)$(GDB) --batch \
		   -ex 'target extended-remote $(BMP_PORT)' \
		   -x $(TOOLCHAIN_DIR)/arm-none-eabi/share/libopencm3/scripts/black_magic_probe_flash.scr \
		   $<
endif
else
upload:
	@echo unknown flash_mode $(FLASH_MODE)
endif


start_gdb:
	xterm -e "$(OOCD) -f interface/$(OOCD_INTERFACE).cfg  -f target/$(OOCD_TARGET).cfg" &
	xterm -e "$(OOCD) -f interface/lisa-l.cfg -f board/lisa-l.cfg"&
	xterm -e "$(OOCD) -f interface/flossjtag.cfg -f board/lisa-l.cfg"&

start_telnet:
	xterm -e "telnet localhost 4444" &
#reset halt
#flash probe 0
#stm32x mass_erase 0
#flash write_bank 0 main.bin 0
#reset halt

#/opt/paparazzi/stm32/bin/arm-none-eabi-gdbtui --eval-command="target remote localhost:3333"
#/opt/paparazzi/stm32/bin/arm-none-eabi-gdbtui --eval-command="target remote localhost:3333" var/BOOZ2_A6/ap/ap.elf


# Target: clean project.
clean: clean_list


clean_list :
	@echo
	$(RM) $(OBJDIR)/$(TARGET).hex
	$(RM) $(OBJDIR)/$(TARGET).obj
	$(RM) $(OBJDIR)/$(TARGET).elf
	$(RM) $(OBJDIR)/$(TARGET).map
	$(RM) $(OBJDIR)/$(TARGET).obj
	$(RM) $(OBJDIR)/$(TARGET).a90
	$(RM) $(OBJDIR)/$(TARGET).sym
	$(RM) $(OBJDIR)/$(TARGET).lnk
	$(RM) $(OBJDIR)/$(TARGET).lss
	$(RM) $(COBJ)
	$(RM) $(AOBJ)
	$(RM) $(COBJARM)
	$(RM) $(AOBJARM)
	$(RM) $(LST)
	$(RM) $(SRC:.c=.s)
	$(RM) $(SRC:.c=.d)
	$(RM) $(SRCARM:.c=.s)
	$(RM) $(SRCARM:.c=.d)
	$(RM) .dep/*
	$(RM) *~


# Listing of phony targets.
.PHONY : all sizebefore sizeafter \
build elf bin lss sym clean clean_list upload


#
# Dependencies
#

$(OBJDIR)/.depend:
	@echo DEPEND $@
	@test -d $(OBJDIR) || mkdir -p $(OBJDIR)
	$(Q)$(CC) -MM -MG $(THUMB) $(CFLAGS) $($(TARGET).srcs) | sed 's|\([^\.]*\.o\)|$(OBJDIR)/\1|' > $@

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),erase)
-include $(OBJDIR)/.depend
endif
endif
back to top