-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
119 lines (95 loc) · 2.91 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
# path to STM32F103 standard peripheral library
# STD_PERIPH_LIBS ?= ./STM32F10x_StdPeriph_Lib_V3.5.0/
# list of source files
SOURCES = main.c
SOURCES += cmsis/src/system_stm32f1xx.c
SOURCES += core/enc28j60/enc28j60.c
SOURCES += core/enc28j60/spi/enc28j60_spi.c
SOURCES += core/delay/delay.c
SOURCES += core/buart/buart.c
SOURCES += core/tcp_ip/lan.c
SOURCES += core/tcp_ip/1network/ethernet.c
SOURCES += core/tcp_ip/1network/arp.c
SOURCES += core/tcp_ip/2internet/ip.c
SOURCES += core/tcp_ip/2internet/icmp.c
SOURCES += core/tcp_ip/3transport/udp.c
SOURCES += core/tcp_ip/4application/ntp.c
# add startup file to build
SOURCES += ./startup/startup_stm32f103xb.s
# name for output binary files
PROJECT ?= test
# compiler, objcopy (should be in PATH)
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
SIZE = arm-none-eabi-size
DBG = arm-none-eabi-gdb
# path to st-flash (or should be specified in PATH)
ST_FLASH ?= st-flash
ST_LINK ?= ST-LINK_CLI
ST_INFO = st-info
OCD = openocd
# specify compiler flags
CFLAGS = -g -O0 -Wall
CFLAGS += -T ./startup/STM32F103XB_FLASH.ld
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3 -mthumb-interwork
CFLAGS += -DSTM32F103xB
CFLAGS += -Wl,--gc-sections
CFLAGS += -I.
CFLAGS += -I ./cmsis/inc/
# main header
CFLAGS += -I ./core
# delay header
CFLAGS += -I ./core/delay/
# burat header
CFLAGS += -I ./core/buart/
# enc28j60 headers
CFLAGS += -I ./core/enc28j60/
CFLAGS += -I ./core/enc28j60/spi
# tcp_ip headers
CFLAGS += -I ./core/tcp_ip
CFLAGS += -I ./core/tcp_ip/1network
CFLAGS += -I ./core/tcp_ip/2internet
CFLAGS += -I ./core/tcp_ip/3transport
CFLAGS += -I ./core/tcp_ip/4application
OBJS = $(SOURCES:.c=.o)
all: $(PROJECT).elf size
# compile
$(PROJECT).elf: $(SOURCES)
$(CC) $(CFLAGS) $^ -o $@
$(OBJCOPY) -O ihex $(PROJECT).elf $(PROJECT).hex
$(OBJCOPY) -O binary $(PROJECT).elf $(PROJECT).bin
# remove binary files
clean:
rm -f *.o *.elf *.hex *.bin
# flash
burn:
$(ST_FLASH) write $(PROJECT).bin 0x8000000
burn_win:
$(ST_LINK) -c SWD -P $(PROJECT).hex 0x8000000 -Rst
ocd_burn:
$(OCD) -f /usr/share/openocd/scripts/interface/stlink-v2.cfg \
-f /usr/share/openocd/scripts/target/stm32f1x.cfg -c \
"init; reset halt; flash write_image erase test.hex; reset; exit"
debug:
$(DBG) $(PROJECT).elf \
-ex 'target remote localhost:3333' \
-ex 'monitor reset halt'
# -ex 'tui enable'
ocd_open:
$(OCD) -f /usr/share/openocd/scripts/interface/stlink-v2.cfg \
-f /usr/share/openocd/scripts/target/stm32f1x.cfg \
# -l ./ocd_log &
ocd_open_win:
$(OCD) -f "C:/xpack-openocd-0.11.0-5/scripts/interface/stlink-v2.cfg" \
-f "C:/xpack-openocd-0.11.0-5/scripts/target/stm32f1x.cfg" \
# -l ./ocd_log &
ocd_burn_win:
$(OCD) -f "C:/xpack-openocd-0.11.0-5/scripts/interface/stlink-v2.cfg" \
-f "C:/xpack-openocd-0.11.0-5/scripts/target/stm32f1x.cfg" \
-c "init; reset halt; flash write_image erase test.hex; reset; exit"
# size info
size:
@$(SIZE) -B -d ./$(PROJECT).elf
# MCU info
info:
@$(ST_INFO) --probe