Files
paparazzi/conf/Makefile.stm32
T
2009-07-12 23:59:09 +00:00

224 lines
5.5 KiB
Makefile

# 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.
#
# Pretty Printer
# Call with "make Q=''" to get full command display
Q=@
MCU = cortex-m3
#DEBUG = dwarf-2
OPT = s
# Programs location
GCC_DIR=/opt/stm32/toolchain/arm-none-eabi
#GCC_DIR=/home/poine/arm-none-eabi
GCC_BIN_DIR=$(GCC_DIR)/bin
GCC_LIB_DIR=$(GCC_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)-ld
CP = $(GCC_BIN_PREFIX)-objcopy
DMP = $(GCC_BIN_PREFIX)-objdump
NM = $(GCC_BIN_PREFIX)-nm
SIZE = $(GCC_BIN_PREFIX)-size
RM = rm
OOCD = openocd
LOADER=$(STM32_DIR)/stm32loader-a3c51c26ad6c/stm32loader.py
OOCD_INTERFACE = arm-usb-ocd
OOCD_TARGET = olimex_stm32_h103
# inpput files
SRCS = $($(TARGET).srcs)
#ASRC =
# object files
COBJ = $(SRCS:%.c=$(OBJDIR)/%.o)
AOBJ = $(ASRC:%.S=$(OBJDIR)/%.o)
# linker script
LD_SCRIPT = $(SRC_FYA)/stm32f10x_flash_md.ld
CFLAGS = -I. -I./$(ARCHI) $(INCLUDES) -Wall -ansi -std=c99 -c -fno-common -Os -g -mcpu=cortex-m3 -mthumb -ffunction-sections -fdata-sections -c
CFLAGS += -Wl,gc-sections
#CFLAGS = -mcpu=$(MCU) -mthumb -ansi
#CFLAGS += -std=c99
#CFLAGS += -malignment-traps
#CFLAGS += -fno-common -O$(OPT) -g$(DEBUG)
#CFLAGS += -ffunction-sections -fdata-sections
#CFLAGS += -Wall -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 += $($(TARGET).CFLAGS)
AFLAGS = -ahls -mapcs-32
AFLAGS += -x assembler-with-cpp -Wa,-adhlns=$(OBJDIR)/$(<:.S=.lst),--g$(DEBUG)
LDFLAGS = -T$(LD_SCRIPT) -nostartfiles -L$(GCC_LIB_DIR) -O$(OPT) --gc-sections
#LDFLAGS += -Wl,-Map=$(OBJDIR)/$(TARGET).map,--cref,--gc-sections
LDLIBS += -lcmsis -lstm32
CPFLAGS = -j .isr_vector -j .text -j .data -Obinary
ODFLAGS = -S
# Default target.
all: sizebefore build sizeafter
build: elf bin
# lss sym
elf: $(OBJDIR)/$(TARGET).elf
bin: $(OBJDIR)/$(TARGET).bin
lss: $(OBJDIR)/$(TARGET).lss
sym: $(OBJDIR)/$(TARGET).sym
# Display size of file.
ELFSIZE = $(SIZE) -A $(OBJDIR)/$(TARGET).elf
sizebefore:
@if [ -f $(OBJDIR)/$(TARGET).elf ]; then echo; $(ELFSIZE); echo; fi
sizeafter:
@if [ -f $(OBJDIR)/$(TARGET).elf ]; then echo; $(ELFSIZE); echo; fi
%.bin: %.elf
@echo OBJC $@
$(Q)$(CP) $(CPFLAGS) $< $@
# 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 $@
#upload: $(OBJDIR)/$(TARGET).bin
# $(LOADER) -p /dev/ttyUSB1 -b 115200 -e -w -v $^
upload: $(OBJDIR)/$(TARGET).bin
@echo -e " OOCD\t$<"
$(Q)$(OOCD) -f interface/$(OOCD_INTERFACE).cfg \
-f board/$(OOCD_TARGET).cfg \
-c init \
-c "reset halt" \
-c "flash write_image erase $(OBJDIR)/$(TARGET).bin 0x08000000" \
-c reset \
-c shutdown
# 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).CFLAGS) $($(TARGET).srcs) | sed 's|\([^\.]*\.o\)|$(OBJDIR)/\1|' > $@
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),erase)
-include $(OBJDIR)/.depend
endif
endif