-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
105 lines (82 loc) · 2.54 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
TARGET = ./out/main
SRCS = ./src/main.s
OBJS = $(addsuffix .o, $(basename $(SRCS)))
INCLUDES = -I.
LINKER_SCRIPT = stm32.ld
CFLAGS += -mcpu=cortex-m4 -mthumb # processor setup
CFLAGS += -O0 # optimization is off
CFLAGS += -g3 # generate debug info
CFLAGS += -gdwarf
CFLAGS += -fno-common
CFLAGS += -Wall # turn on warnings
CFLAGS += -pedantic # more warnings
CFLAGS += -Wsign-compare
CFLAGS += -Wcast-align
CFLAGS += -Wconversion # neg int const implicitly converted to uint
CFLAGS += -fsingle-precision-constant
CFLAGS += -fomit-frame-pointer # do not use fp if not needed
CFLAGS += -ffunction-sections -fdata-sections
# Chooses the relevant FPU option
CFLAGS += -mfloat-abi=soft # No FP
#CFLAGS += -mfloat-abi=softfp -mfpu=fpv4-sp-d16 # Soft FP
#CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # Hard FP
#LDFLAGS += -mfloat-abi=softfp -mfpu=fpv4-sp-d16 # Soft FP
#LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # Hard FP
LDFLAGS += -march=armv7e-m # processor setup
LDFLAGS += -nostartfiles # no start files are used
LDFLAGS += --specs=nosys.specs
LDFLAGS += -Wl,-Map=$(TARGET).map #generate map file
LDFLAGS += -T$(LINKER_SCRIPT)
CROSS_COMPILE = arm-none-eabi-
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJDUMP = $(CROSS_COMPILE)objdump
OBJCOPY = $(CROSS_COMPILE)objcopy
SIZE = $(CROSS_COMPILE)size
DBG = $(CROSS_COMPILE)gdb
ifdef OS
RM_CMD = del /F /Q
else
RM_CMD = rm -f
endif
all: clean $(SRCS) build size
@echo "Successfully finished..."
build: $(TARGET).elf $(TARGET).hex $(TARGET).bin $(TARGET).lst
$(TARGET).elf: $(OBJS)
@$(CC) $(LDFLAGS) ./out/$(notdir $(basename $(OBJS))).o -o $@
%.o: %.c
@echo "Building" $<
@$(CC) $(CFLAGS) $(INCLUDES) -c $< -o out/$(notdir $@)
%.o: %.s
@echo "Building" $<
@$(CC) $(CFLAGS) -c $< -o out/$(notdir $@)
%.hex: %.elf
@$(OBJCOPY) -O ihex $< $@
%.bin: %.elf
@$(OBJCOPY) -O binary $< $@
%.lst: %.elf
@$(OBJDUMP) -x -S $(TARGET).elf > $@
size: $(TARGET).elf
@$(SIZE) $(TARGET).elf
disass: $(TARGET).elf
@$(OBJDUMP) -d $(TARGET).elf
disass-all: $(TARGET).elf
@$(OBJDUMP) -D $(TARGET).elf
debug:
@$(DBG) --eval-command="target extended-remote :4242" \
$(TARGET).elf
ocd:
@$(DBG) --eval-command="target extended-remote :3333" \
--eval-command="monitor tpiu config internal swo.log uart off 16000000 1600000" \
$(TARGET).elf
burn:
@st-flash write $(TARGET).bin 0x8000000
clean:
@echo "Cleaning..."
@$(RM_CMD) $(TARGET).elf
@$(RM_CMD) $(TARGET).bin
@$(RM_CMD) $(TARGET).map
@$(RM_CMD) $(TARGET).hex
@$(RM_CMD) $(TARGET).lst
@$(RM_CMD) $(TARGET).o
.PHONY: all build size disass disass-all debug ocd burn clean