-
Notifications
You must be signed in to change notification settings - Fork 73
/
Makefile.stm32f1
56 lines (42 loc) · 1.56 KB
/
Makefile.stm32f1
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
PLATFORM ?= bluepill
LOADER ?= noloader
OBJS := src/dirtyjtag.$(PLATFORM).o src/jtag.$(PLATFORM).o src/usb.$(PLATFORM).o src/delay.$(PLATFORM).o src/cmd.$(PLATFORM).o
PREFIX ?= arm-none-eabi
DEFS += -DSTM32F1
ARCH_FLAGS := -mthumb -mcpu=cortex-m3 -msoft-float -mfix-cortex-m3-ldrd
LD_SCRIPT := ld/stm32f1-$(LOADER).ld
UCMX_DIR := $(realpath unicore-mx)
UCMX_INCLUDE_DIR := $(UCMX_DIR)/include
UCMX_LIB_DIR := $(UCMX_DIR)/lib
CFLAGS = -g -O2 -std=c99
CFLAGS += -Wall -Wextra -Werror
CFLAGS += -fno-common -ffunction-sections -fdata-sections
CFLAGS += -std=gnu11
CFLAGS += -DPLATFORM='HW_$(PLATFORM)' $(DEFS)
CPPFLAGS = -MD -g
CPPFLAGS += -Wall -Wundef
CPPFLAGS += -I$(UCMX_INCLUDE_DIR) $(DEFS)
LDFLAGS += --static -nostartfiles
LDFLAGS += -L"$(UCMX_LIB_DIR)"
LDFLAGS += -T$(LD_SCRIPT)
LDFLAGS += -Wl,-Map=$(*).map
LDFLAGS += -Wl,--gc-sections # Remove deadcode
LDLIBS += -lucmx_stm32f1
LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
CC := $(PREFIX)-gcc
LD := $(PREFIX)-ld
AR := $(PREFIX)-ar
AS := $(PREFIX)-as
SIZE := $(PREFIX)-size
OBJCOPY := $(PREFIX)-objcopy
all: src/dirtyjtag.$(PLATFORM).$(LOADER).elf src/dirtyjtag.$(PLATFORM).$(LOADER).bin
clean:
$(Q)$(RM) src/*.d src/*.o src/*.map src/*.bin src/*.elf *.bin *.elf
%.bin: %.elf
$(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin
%.$(LOADER).elf %.$(LOADER).map: $(OBJS) $(LD_SCRIPT)
$(Q)$(CC) $(LDFLAGS) $(ARCH_FLAGS) $(OBJS) $(LDLIBS) -o $(*).$(LOADER).elf
$(Q)$(SIZE) $(*).$(LOADER).elf
%.$(PLATFORM).o: %.c $(UCMX_LIB_DIR)/libucmx_stm32f1.a
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $@ -c $<
.PHONY: all clean