-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
executable file
·120 lines (94 loc) · 3.46 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
###############################################################################
# A template Makefile for ST's Cortex-M4 MCUs
#
# References:
# https://github.com/vkottler/diymore-stm32f407/blob/master/Makefile
# https://interrupt.memfault.com/blog/gnu-make-guidelines
###############################################################################
###############################################################################
# Definitions
###############################################################################
# Project
PROJECT = ssd1322_oled
# Build directory
BUILD_DIR := build
# Compiler & Linker
CC = arm-none-eabi-gcc
# Sources
SOURCES += $(shell find src -name '*.c')
# Objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(SOURCES:.c=.o))
OBJECTS += $(BUILD_DIR)/src/startup/startup.o
# Header file include directories
CFLAGS += -Iinclude/
CFLAGS += -Iinclude/cmsis/
CFLAGS += -Iinclude/system/
CFLAGS += -Iinclude/core_drivers/
CFLAGS += -Iinclude/device_drivers/ssd1322
CFLAGS += -Iinclude/device_drivers/hdc1000
CFLAGS += -Iinclude/util
# Processor specific flags
CFLAGS += -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
# Compiler flags to compile for code size
CFLAGS += -O0 -flto -Wall -ffunction-sections -fdata-sections -fno-builtin
# Enable debugging data
CFLAGS += -g3 -gdwarf-2
# Linker flags to link for code size
LDFLAGS += -Wl,--gc-sections --specs=nosys.specs -T./scripts/linker_script.ld
# Generate a map file
LDFLAGS += -Wl,-Map=build/"ssd1322_oled.map"
# Dependency flags
DEPFLAGS += -MMD -MP -MF [email protected]
# Include dependencies
include $(shell find . -name "*.d")
###############################################################################
# Compiling and Linking
###############################################################################
# Target
.DEFAULT_GOAL = all
.PHONY: all
all: $(BUILD_DIR)/$(PROJECT).bin
# Create a build directory before generating objects
$(OBJECTS): | $(BUILD_DIR)
# Rule for actually creating the build directory
$(BUILD_DIR):
@mkdir -p $@
# Assembly source rule
# Create the folder structure for the output file before compiling
$(BUILD_DIR)/%.o: %.S
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@
# C source rule
# Create the folder structure for the output file before compiling
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@
# Invoke linker to generate .elf file
$(BUILD_DIR)/$(PROJECT).elf: $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
# Generate .bin file
$(BUILD_DIR)/$(PROJECT).bin: $(BUILD_DIR)/$(PROJECT).elf
arm-none-eabi-objcopy -O binary $< $@
# Remove compiler outputs
.PHONY: clean
clean:
@echo "Deleting all build outputs ..."
@rm -rf $(BUILD_DIR)
@echo "Done!"
###############################################################################
# Programming
###############################################################################
# Programming via st-link
.PHONY: burn
burn:
st-flash --reset write $(BUILD_DIR)/$(PROJECT).bin 0x8000000
# Programming via JLink
JLINK_FILE = ./temp.jlink
JLINK_ARGS = -device STM32F407VG -if SWD -speed 4000 -autoconnect 1
.PHONY: flash
flash:
@echo "loadbin $(BUILD_DIR)/$(PROJECT).bin, 0x08000000" > $(JLINK_FILE)
@echo "r" >> $(JLINK_FILE)
@echo "exit" >> $(JLINK_FILE)
JLinkExe $(JLINK_ARGS) -CommanderScript $(JLINK_FILE)
@rm $(JLINK_FILE)