stmbl/bootloader/Makefile

192 lines
4.6 KiB
Makefile
Raw Permalink Normal View History

2016-01-09 16:09:19 +00:00
# Optimization level, can be [0, 1, 2, 3, s].
2015-12-30 07:14:51 +00:00
# 0 = turn off optimization. s = optimize for size.
2016-01-09 16:09:19 +00:00
#
2015-12-30 07:14:51 +00:00
OPT = -O1 -flto
# OPT = -O1 # for debugging
# Object files directory
# Warning: this will be removed by make clean!
#
OBJDIR = obj_boot
# Target file name (without extension)
TARGET = $(OBJDIR)/blboot
# Define all C source files (dependencies are generated automatically)
INCDIRS += inc
INCDIRS += bootloader/src
INCDIRS += shared
SOURCES += bootloader/src/main.c
SOURCES += bootloader/src/version.c
SOURCES += bootloader/src/stm32f4xx_it.c
SOURCES += bootloader/src/system_stm32f4xx.c
# Standard peripheral library
CPPFLAGS += -DUSE_STDPERIPH_DRIVER
#CPPFLAGS += -DUSE_FULL_ASSERT
2016-01-09 16:09:19 +00:00
PERIPH_DRV_DIR = lib/STM32F4xx_StdPeriph_Driver-V1.6.0
INCDIRS += $(PERIPH_DRV_DIR)/inc
INCDIRS += lib/CMSIS/Include
INCDIRS += lib/CMSIS/Device/ST/STM32F4xx/Include
2016-01-09 16:09:19 +00:00
SOURCES += $(PERIPH_DRV_DIR)/src/stm32f4xx_flash.c
SOURCES += $(PERIPH_DRV_DIR)/src/stm32f4xx_crc.c
SOURCES += $(PERIPH_DRV_DIR)/src/stm32f4xx_gpio.c
SOURCES += $(PERIPH_DRV_DIR)/src/stm32f4xx_pwr.c
SOURCES += $(PERIPH_DRV_DIR)/src/stm32f4xx_rcc.c
SOURCES += $(PERIPH_DRV_DIR)/src/stm32f4xx_usart.c
SOURCES += $(PERIPH_DRV_DIR)/src/misc.c
SOURCES += lib/CMSIS/Device/ST/STM32F4xx/Source/startup_stm32f40_41xxx.s
CPPFLAGS += -DSTM32F40_41xxx
2016-01-02 21:11:42 +00:00
CPPFLAGS += -DHSE_VALUE=8000000
2015-12-30 07:14:51 +00:00
LDSCRIPT = bootloader/stm32_flash.ld
#============================================================================
OBJECTS += $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(SOURCES))))
CPPFLAGS += $(addprefix -I,$(INCDIRS))
#---------------- Preprocessor Options ----------------
# -fsingle... make better use of the single-precision FPU
# -g generate debugging information
# -save-temps preserve .s and .i-files
#
CPPFLAGS += -fsingle-precision-constant
CPPFLAGS += -g
# CPPFLAGS += -save-temps=obj
#---------------- C Compiler Options ----------------
# -O* optimization level
# -f... tuning, see GCC documentation
# -Wall... warning level
#
CFLAGS += $(OPT)
CFLAGS += -std=gnu11
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += -Wall
CFLAGS += -fno-builtin ## from old
CFLAGS += -nostartfiles
2016-02-15 14:28:30 +00:00
CFLAGS += -Wfatal-errors
2015-12-30 07:14:51 +00:00
#CFLAGS += -Wstrict-prototypes
#CFLAGS += -Wextra
#CFLAGS += -Wpointer-arith
#CFLAGS += -Winline
#CFLAGS += -Wunreachable-code
#CFLAGS += -Wundef
# Use a friendly C dialect
CPPFLAGS += -fno-strict-aliasing
CPPFLAGS += -fwrapv
#---------------- C++ Compiler Options ----------------
#
CXXFLAGS += $(OPT)
CXXFLAGS += -ffunction-sections
CXXFLAGS += -fdata-sections
CXXFLAGS += -Wall
#---------------- Assembler Options ----------------
# -Wa,... tell GCC to pass this to the assembler
#
#---------------- Linker Options ----------------
# -Wl,... tell GCC to pass this to linker
# -Map create map file
# --cref add cross reference to map file
#
LDFLAGS += $(OPT)
LDFLAGS += -lm
LDFLAGS += -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += -Wl,--gc-sections
# LDFLAGS += -specs=nano.specs -u _printf_float -u _scanf_float
LDFLAGS += -T$(LDSCRIPT)
#============================================================================
# Define programs and commands
#
TOOLCHAIN = arm-none-eabi-
CC = $(TOOLCHAIN)gcc
OBJCOPY = $(TOOLCHAIN)objcopy
OBJDUMP = $(TOOLCHAIN)objdump
SIZE = $(TOOLCHAIN)size
NM = $(TOOLCHAIN)nm
MKDIR = mkdir
2015-12-30 07:23:10 +00:00
POSTLD = tools/add_version_info.py # -q
2015-12-30 07:14:51 +00:00
# Compiler flags to generate dependency files
#
GENDEPFLAGS = -MMD -MP
# Combine all necessary flags and optional flags
# Add target processor to flags.
#
CPU = -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS += $(CPU)
CXXFLAGS += $(CPU)
ASFLAGS += $(CPU)
LDFLAGS += $(CPU)
# Default target
#
all: gccversion build showsize
build: elf hex bin lss sym
elf: $(TARGET).elf
hex: $(TARGET).hex
bin: $(TARGET).bin
lss: $(TARGET).lss
sym: $(TARGET).sym
# Display compiler version information
#
2016-01-09 16:09:19 +00:00
gccversion:
2015-12-30 07:14:51 +00:00
@$(CC) --version
# Show the final program size
#
showsize: build
@echo
@$(SIZE) $(TARGET).elf 2>/dev/null
2016-01-09 16:09:19 +00:00
# Flash the device
2015-12-30 07:14:51 +00:00
#
btflash: build showsize
2015-11-23 18:25:45 +00:00
#change this to your device
printf "bootloader\r" > `ls /dev/cu.usbmodem*` || true
printf "bootloader\r" > `ls /dev/ttyACM*` || true
sleep 1
2015-12-30 07:14:51 +00:00
dfu-util -a 0 -d 0483:df11 -s 0x08000000:leave -D $(TARGET).bin
2015-11-23 18:25:45 +00:00
2015-12-30 07:14:51 +00:00
flash: build showsize
st-flash --reset write $(TARGET).bin 0x08000000
2015-11-23 18:25:45 +00:00
2015-12-30 07:14:51 +00:00
# Target: clean project
#
2015-11-23 18:25:45 +00:00
clean:
2015-12-30 07:14:51 +00:00
@echo Cleaning project:
rm -rf $(OBJDIR)
2015-12-30 07:14:51 +00:00
# Include the base rules
#
include base.mak
# Include the dependency files
#
-include $(OBJECTS:.o=.d)
# Listing of phony targets
#
.PHONY: all build flash btfash clean \
boot boot_clean boot_flash \
elf lss sym \
showsize gccversion