-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
48 lines (35 loc) · 1.02 KB
/
Makefile
File metadata and controls
48 lines (35 loc) · 1.02 KB
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
# Toolchain
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
SIZE = arm-none-eabi-size
# Flags
CFLAGS = -mcpu=cortex-m4 -mthumb -Wall -g -O0 -ffreestanding -nostdlib
LDFLAGS = -TSTM32F446RETX_FLASH.ld -nostdlib
ASFLAGS = -mcpu=cortex-m4 -mthumb
# Directories
SRC_DIR = src
INC_DIR = inc
STARTUP_DIR = startup
BUILD_DIR = build
# Source files
C_SOURCES := $(wildcard $(SRC_DIR)/*.c)
OBJECTS := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(C_SOURCES)) $(BUILD_DIR)/startup.o
INCLUDES = -I$(INC_DIR)
# Target
TARGET = $(BUILD_DIR)/main.elf
# Rules
all: $(TARGET)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
$(BUILD_DIR)/startup.o: $(STARTUP_DIR)/startup_stm32f446retx.s | $(BUILD_DIR)
$(CC) $(ASFLAGS) -c $< -o $@
$(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(SIZE) $@
clean:
rm -rf $(BUILD_DIR)
flash:
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg \
-c "program build/main.elf verify reset; resume; exit" || true