-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
82 lines (53 loc) · 1.96 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
##########################################################################
# STM32F4 Project Template Makefile #
##########################################################################
TARGET:=main
TOOLCHAIN_PATH:=~/Development/sat/bin
TOOLCHAIN_PREFIX:=arm-none-eabi
OPTLVL:=3 # Optimization level, can be [0, 1, 2, 3, s].
PROJECT_NAME:=$(notdir $(lastword $(CURDIR)))
LINKER_SCRIPT=stm32_flash.ld
INCLUDE=-I$(CURDIR)/inc
INCLUDE+=-I$(CURDIR)/lib/inc
INCLUDE+=-I$(CURDIR)/lib/cmsis
# vpath is used so object files are written to the current directory instead
# of the same directory as their source files
vpath %.c $(CURDIR)/lib/src
vpath %.s $(STARTUP)
ASRC=startup_stm32f4xx.s
# Project Source Files
# Standard Peripheral Source Files
SRC+=$(wildcard $(CURDIR)/*.c)
SRC+=$(wildcard $(CURDIR)/lib/src/*.c)
CDEFS=-DSTM32F4XX
CDEFS+=-DUSE_STDPERIPH_DRIVER
MCUFLAGS=-mcpu=cortex-m4 -mthumb -std=c99
#MCUFLAGS=-mcpu=cortex-m4 -mthumb -mlittle-endian -mfpu=fpa -mfloat-abi=hard -mthumb-interwork
#MCUFLAGS=-mcpu=cortex-m4 -mfpu=vfpv4-sp-d16 -mfloat-abi=hard
COMMONFLAGS=-O$(OPTLVL) -g -Wall
CFLAGS=$(COMMONFLAGS) $(MCUFLAGS) $(INCLUDE) $(CDEFS)
LDLIBS=
LDFLAGS=$(COMMONFLAGS) -fno-exceptions -ffunction-sections -fdata-sections \
-nostartfiles -Wl,--gc-sections,-T$(LINKER_SCRIPT)
#####
#####
OBJ = $(SRC:%.c=%.o) $(ASRC:%.s=%.o)
CC=$(TOOLCHAIN_PATH)/$(TOOLCHAIN_PREFIX)-gcc
LD=$(TOOLCHAIN_PATH)/$(TOOLCHAIN_PREFIX)-gcc
OBJCOPY=$(TOOLCHAIN_PATH)/$(TOOLCHAIN_PREFIX)-objcopy
AS=$(TOOLCHAIN_PATH)/$(TOOLCHAIN_PREFIX)-as
AR=$(TOOLCHAIN_PATH)/$(TOOLCHAIN_PREFIX)-ar
GDB=$(TOOLCHAIN_PATH)/$(TOOLCHAIN_PREFIX)-gdb
all: bin
bin: $(OBJ)
$(CC) -o $(TARGET).elf $(LDFLAGS) $(OBJ) $(LDLIBS)
$(OBJCOPY) -O ihex $(TARGET).elf $(TARGET).hex
$(OBJCOPY) -O binary $(TARGET).elf $(TARGET).bin
flash: bin
st-flash write $(TARGET).bin 0x08000000
.PHONY: clean
clean:
rm -f $(OBJ)
rm -f $(TARGET).elf
rm -f $(TARGET).hex
rm -f $(TARGET).bin