Makefile 4.44 KB
Newer Older
Martin Horauer's avatar
Martin Horauer committed
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
################################################################################
# Makefile for XMC4500 RelaxKit using uCOS-III
# v1, 02/2018
# Martin Horauer, UAS Technikum Wien
#
# Supported: Windows, Linux, OSX
# Requirements:
# * GCC ARM https://launchpad.net/gcc-arm-embedded/+download
# * SEGGER JLINK https://www.segger.com/jlink-software.html
# * DOXYGEN http://www.stack.nl/~dimitri/doxygen/

################################################################################
# USAGE
# -----
# make           .... build the program image
# make debug     .... build the program image and invoke gdb
# make flash     .... build an flash the application
# make erase     .... erase the target device
# make doc       .... run doxygen - output will be in > doc
# make clean     .... remove intermediate and generated files

################################################################################
# define the name of the generated output file
#
TARGET        = main

################################################################################
# below only edit with care
#
VENDOR        = Infineon

################################################################################
# define the following symbol -D JLINK_RTT to enable JLINK_RTT tracing
#                             -D SEMI_HOSTING to enable semi hosted tracing
#                             comment the line to disable tracing
TRACE         = -D SEMI_HOSTING

################################################################################
# TOOLS & ARGS
#
Martin Horauer's avatar
Martin Horauer committed
41
SRC           = $(wildcard *.cpp)
Martin Horauer's avatar
Martin Horauer committed
42
43
44
45
46
47
48
49
50
51
52
53
TERMINAL      = gnome-terminal
TOOLCHAIN     = GCC_ARM
BOARD         = XMC_4500_RELAX_KIT
BUILDDIR      = BUILD
DOCDIR        = DOC
MBED          = mbed
GDB           = arm-none-eabi-gdb

# DETERMINE OS
ifdef SystemRoot
  RM = del /Q
  FixPath = $(subst /,\,$1)
Martin Horauer's avatar
Martin Horauer committed
54
else
Martin Horauer's avatar
Martin Horauer committed
55
56
  RM = rm -rf
  FixPath = $1
Martin Horauer's avatar
Martin Horauer committed
57
58
endif

Martin Horauer's avatar
Martin Horauer committed
59
60
61
62
GDB_ARGS      = -ex "target remote :2331"
GDB_ARGS     += -ex "monitor reset"
GDB_ARGS     += -ex "load"
GDB_ARGS     += -ex "monitor reset"
Martin Horauer's avatar
Martin Horauer committed
63

Martin Horauer's avatar
Martin Horauer committed
64
65
66
################################################################################
# SEMI_HOSTED DEBUGGING
GDB_ARGS     += -ex "monitor SWO EnableTarget 16000000 0 1 0"
Martin Horauer's avatar
Martin Horauer committed
67

Martin Horauer's avatar
Martin Horauer committed
68
69
70
# RTT OPTION
#GDB_ARGS     += -ex "monitor exec SetRTTAddr 0x20000000"
#GDB_ARGS     += -ex "monitor exec SetRTTSearchRanges 0x20000000 0x1000"
Martin Horauer's avatar
Martin Horauer committed
71

Martin Horauer's avatar
Martin Horauer committed
72
73
################################################################################
# BUILD RULES
Martin Horauer's avatar
Martin Horauer committed
74
all: $(SRC) build
Martin Horauer's avatar
Martin Horauer committed
75

Martin Horauer's avatar
Martin Horauer committed
76
77
78
################################################################################
# CREATE A DEBUG VESRION
build: $(SRC)
Martin Horauer's avatar
Martin Horauer committed
79
	@echo "----------------------------------------------------------------------"
Martin Horauer's avatar
Martin Horauer committed
80
81
82
83
84
85
86
87
88
89
	@echo "Building with DEBUG Symbols"
	@echo ""
	$(MBED) compile -m $(BOARD) -t $(TOOLCHAIN) -N main --profile mbed-os/tools/profiles/debug.json
	@echo ""

################################################################################
# CREATE A RELEASE VESRION
release: $(SRC)
	@echo "----------------------------------------------------------------------"
	@echo "Build a RELEASE version"
Martin Horauer's avatar
Martin Horauer committed
90
	@echo ""
Martin Horauer's avatar
Martin Horauer committed
91
	$(MBED) compile -m $(BOARD) -t $(TOOLCHAIN) -N main
Martin Horauer's avatar
Martin Horauer committed
92
	@echo ""
Martin Horauer's avatar
Martin Horauer committed
93

Martin Horauer's avatar
Martin Horauer committed
94
95
################################################################################
# DEBUG RULES
Martin Horauer's avatar
Martin Horauer committed
96
debug: build $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).elf
Martin Horauer's avatar
Martin Horauer committed
97
98
99
100
101
ifdef SystemRoot
	@call start JLinkGDBServer -Device XMC4500-1024 -if SWD
else
	$(TERMINAL) -e "JLinkGDBServer -Device XMC4500-1024 -if SWD" &
	sleep 1 && $(TERMINAL) -e "telnet 127.0.0.1 2333" & 
Martin Horauer's avatar
Martin Horauer committed
102
endif
Martin Horauer's avatar
Martin Horauer committed
103
104
105
106
	$(GDB) -q  $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).elf $(GDB_ARGS)

################################################################################
# FLASH RULES
Martin Horauer's avatar
Martin Horauer committed
107
flash: build $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).hex
Martin Horauer's avatar
Martin Horauer committed
108
109
110
111
112
113
114
115
116
	echo -e 'speed 4000\nconnect\nh\nloadbin $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).hex,0xC000000\nr\ng\nq' | JLinkExe -Device XMC4500-1024 -if SWD

################################################################################
# ERASE DEVICE
erase:
	echo -e 'speed 4000\nconnect\nerase\nr\nq' | JLinkExe -Device XMC4500-1024 -if SWD

################################################################################
# DOCUMENTATION RULES
Martin Horauer's avatar
Martin Horauer committed
117
doc: $(SRC)
Martin Horauer's avatar
Martin Horauer committed
118
119
120
121
122
123
124
125
126
127
128
129
	doxygen

################################################################################
# CLEAN RULES
clean:
	$(RM) $(call FixPath, *.pyc)
	$(RM) $(call FixPath, ${BUILDDIR}/*)
	$(RM) $(call FixPath, ${DOCDIR}/html/*)

################################################################################
# EOF
################################################################################