-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
executable file
·69 lines (51 loc) · 1.61 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
### toolchain ###
CC = arm-none-eabi-gcc
CSIZE = arm-none-eabi-size
CDUMP = arm-none-eabi-objdump
### device and env ###
PWD = $(shell pwd)
PORT = /dev/ttyACM0
TARGET = STM32F103C6
# TARGET = STM32F103C8
# USE_ASSERT = true
### files ###
NAME = MiniRTOS
ELF = build/$(NAME).elf
MAP = build/$(NAME).map
DUMP = build/$(NAME)_dump
ifeq ($(TARGET),STM32F103C6)
LINK = lib/stm32f10xc6.ld
MACRO = -D USE_STDPERIPH_DRIVER -D STM32F10X_LD
STARTUP = lib/startup_stm32f10x_ld.s
endif
ifeq ($(TARGET),STM32F103C8)
LINK = lib/stm32f10xc8.ld
MACRO = -D USE_STDPERIPH_DRIVER -D STM32F10X_MD
STARTUP = lib/startup_stm32f10x_md.s
endif
ifeq ($(USE_ASSERT),true)
MACRO += -D USE_FULL_ASSERT
endif
SRC = lib/*.c src/*.c src/**/*.c
HEAD = lib/*.h src/*.h src/**/*.h
INC = -I lib/ -I src/ $(addprefix -I , $(wildcard src/*/))
### flags ###
CFLAG = -mcpu=cortex-m3 -mthumb -std=gnu17 -Wall -Wextra -O2 -g $(MACRO) $(INC)
LFLAG = --specs=nano.specs --specs=nosys.specs -Wl,-Map=$(MAP) -Wl,--gc-sections
### script ###
.PHONY: build size clean flash flash-st flash-isp
build : $(ELF) $(DUMP) size
$(ELF) : $(SRC) $(HEAD) $(STARTUP) $(LINK) makefile
$(CC) $(CFLAG) $(LFLAG) $(SRC) $(STARTUP) -T $(LINK) -o $@
size :
$(CSIZE) $(ELF) -G
clean :
rm build/*
$(DUMP) : $(ELF)
$(CDUMP) -D $(ELF) > $(DUMP)
flash :
openocd -f interface/cmsis-dap.cfg -f target/stm32f1x.cfg -c init -c halt -c "flash write_image erase $(PWD)/$(ELF)" -c reset -c shutdown
flash-st :
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c halt -c "flash write_image erase $(PWD)/$(ELF)" -c reset -c shutdown
flash-isp :
stm32flash -w $(ELF) -v -g 0x0 $(PORT)