https://github.com/tudelft/paparazzi
Raw File
Tip revision: 62f05b686f1ed43dca9cd5585234903af7c467fa authored by Roland Meertens on 18 January 2016, 13:38:47 UTC
set to explore mode
Tip revision: 62f05b6
Makefile.stm32
# Hey Emacs, this is a -*- makefile -*-
#
#   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=@


#
# find compiler toolchain
#
include $(PAPARAZZI_SRC)/conf/Makefile.arm-embedded-toolchain


ifeq ($(ARCH_L),f4)
MCU   = cortex-m4
else
MCU   = cortex-m3
endif
OPT ?= s
# Slightly bigger .elf files but gains the ability to decode macros
DEBUG_FLAGS ?= -ggdb3

# 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
$(warning Linker script for target "$(TARGET)" on board "$(BOARD)" not defined. Using stm32default.ld.)
LDSCRIPT = $(SRC_ARCH)/stm32default.ld
else
LDSCRIPT = $($(TARGET).LDSCRIPT)
$(info Using "$($(TARGET).LDSCRIPT)" as ldscript for target "$(TARGET)".)
endif
endif

CFLAGS = -I. -I./$(ARCH) -I../ext/libopencm3/include $(INCLUDES)
CFLAGS += -D__thumb2__ -O$(OPT)
CFLAGS += $(DEBUG_FLAGS)
ifeq ($(ARCH_L), )
CFLAGS += -msoft-float
else ifeq ($(ARCH_L),f4)
ifndef HARD_FLOAT
CFLAGS += -msoft-float
else
CFLAGS += -mfloat-abi=softfp -mfpu=fpv4-sp-d16
endif
endif

CSTANDARD = -std=gnu99

CFLAGS += -Wl,--gc-sections
CFLAGS += -mfix-cortex-m3-ldrd
CFLAGS += -mcpu=$(MCU) -mthumb -ansi
CFLAGS += $(CSTANDARD)
#CFLAGS += -malignment-traps
CFLAGS += -fno-common
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += -Wa,-adhlns=$(OBJDIR)/$(notdir $(subst $(suffix $<),.lst,$<))

# flags for warnings
CFLAGS += -Wall -Wextra -Wunused
#CFLAGS += -Wcast-qual
CFLAGS += -Wcast-align
CFLAGS += -Wpointer-arith
CFLAGS += -Wswitch-default
CFLAGS += -Wredundant-decls -Wmissing-declarations
CFLAGS += -Wstrict-prototypes -Wmissing-prototypes
CFLAGS += -Wshadow
CFLAGS += -Wnested-externs

CFLAGS += $(USER_CFLAGS)

#CFLAGS += -fno-diagnostics-show-caret

ifneq ($(ARCH_L), )
ifeq ($(ARCH_L),f4)
CFLAGS += -DSTM32F4
endif
else
CFLAGS += -DSTM32F1
endif

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

AFLAGS  = -ahls -mapcs-32
AFLAGS += -mcpu=$(MCU) -mthumb
AFLAGS += -x assembler-with-cpp -Wa,-adhlns=$(OBJDIR)/$(<:.S=.lst)

LDFLAGS += -L../ext/libopencm3/lib
LDFLAGS += -T$(LDSCRIPT) -nostartfiles -O$(OPT) -mthumb -mcpu=$(MCU)

ifeq ($(ARCH_L), )
LDFLAGS += -mfix-cortex-m3-ldrd -msoft-float
else ifeq ($(ARCH_L),f4)
ifndef HARD_FLOAT
LDFLAGS += -mfix-cortex-m3-ldrd -msoft-float
else
LDFLAGS += -lnosys -D__thumb2__\
           -mfloat-abi=softfp -mfpu=fpv4-sp-d16
endif
endif

LDFLAGS += -Wl,-Map=$(OBJDIR)/$(TARGET).map,--cref,--gc-sections
ifneq ($(ARCH_L), )
LDLIBS  += -lopencm3_stm32$(ARCH_L)
else
LDLIBS  += -lopencm3_stm32f1
endif
LDLIBS  += -lc -lm -lgcc

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

ODFLAGS = -S

# some common informative targets
include $(PAPARAZZI_SRC)/conf/Makefile.arm-embedded-common

# Default target.
all: printcommands sizebefore build sizeafter

# depend order only for parallel make
sizebefore: | printcommands
build: | printcommands sizebefore
sizeafter: | build

build: $(OBJDIR) elf bin hex
# lss sym

$(OBJDIR):
	@echo CREATING object dir $(OBJDIR)
	@test -d $(OBJDIR) || mkdir -p $(OBJDIR)

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

%.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) | $(OBJDIR)
	@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) -MMD -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 $@

# Load upload rules
include $(PAPARAZZI_SRC)/conf/Makefile.stm32-upload

# Listing of phony targets.
.PHONY : all build elf bin lss sym

#
# Dependencies
#
ifneq ($(MAKECMDGOALS),clean)
DEPS = $(addprefix $(OBJDIR)/,$($(TARGET).srcs:.c=.d))
-include $(DEPS)
endif
back to top