-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
61 lines (42 loc) · 1.38 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
#Project name
PROJECT = final
# Directories
SRC_DIR = src
BUILD_DIR = build
LD_DIR = linker
#Config files for OpenOCD
OPENOCD_INTERFACE = openocd_cfg/cmsis-dap.cfg
OPENOCD_TARGET = openocd_cfg/stm32g0x.cfg
# Source files and object files
SRCS = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
OUTPUT = $(BUILD_DIR)/$(PROJECT)
LINKER_SCRIPT = $(LD_DIR)/stm32g0_linker.ld
PREFIX = arm-none-eabi-
CFLAGS = -mcpu=cortex-m0plus -mthumb -O0 -Wall -std=gnu11 \
-Wconversion -I.-Wshadow -Werror -g
LDFLAGS = -nostdlib -Wall -g -Wl,-Map,$(OUTPUT).map,--print-memory-usage,--gc-sections
all : $(OUTPUT).bin
$(OUTPUT).bin : $(OUTPUT).elf
@$(PREFIX)objcopy -O binary $^ $@
@echo Binary file created - $(PROJECT).bin
$(OUTPUT).elf : $(OBJ)
$(PREFIX)gcc $(LDFLAGS) -T $(LINKER_SCRIPT) $^ -o $@
$(BUILD_DIR)/%.o : $(SRC_DIR)/%.c | $(BUILD_DIR)
$(PREFIX)gcc $(CFLAGS) -c $^ -o $@
#Flash via OpenOCD, I am using PicoProbe
flash : all
openocd -f $(OPENOCD_INTERFACE) -f $(OPENOCD_TARGET) -c " program $(OUTPUT).elf verify reset exit"
#Start gdb server for debugging
debug : flash
openocd -f $(OPENOCD_INTERFACE) -f $(OPENOCD_TARGET)
# Ensure the build directory exists
$(BUILD_DIR):
mkdir $(BUILD_DIR)
# To auto probe what kind of CPU you have
probe :
openocd -f openocd_cfg/openocd.cfg
# Remove build directory
clean :
rm -rf $(BUILD_DIR)
.PHONY: all clean probe