Makefile 4.02 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
41
42
43
44
45
46
47
48
49
50
51
52
################################################################################
# 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
#
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
53
else
Martin Horauer's avatar
Martin Horauer committed
54
55
  RM = rm -rf
  FixPath = $1
Martin Horauer's avatar
Martin Horauer committed
56
57
endif

Martin Horauer's avatar
Martin Horauer committed
58
59
60
61
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
62

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

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

Martin Horauer's avatar
Martin Horauer committed
71
72
################################################################################
# BUILD RULES
Martin Horauer's avatar
Martin Horauer committed
73
all: $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).elf
Martin Horauer's avatar
Martin Horauer committed
74
75


Martin Horauer's avatar
Martin Horauer committed
76
$(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).elf: $(wildcard *.cpp)
Martin Horauer's avatar
Martin Horauer committed
77
78
79
	@echo "----------------------------------------------------------------------"
	@echo "Building"
	@echo ""
Martin Horauer's avatar
Martin Horauer committed
80
	$(MBED) compile -m $(BOARD) -t $(TOOLCHAIN) -N main
Martin Horauer's avatar
Martin Horauer committed
81
	@echo ""
Martin Horauer's avatar
Martin Horauer committed
82

Martin Horauer's avatar
Martin Horauer committed
83
84
85
86
87
88
89
90
################################################################################
# DEBUG RULES
debug: $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).elf
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
91
endif
Martin Horauer's avatar
Martin Horauer committed
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
118
	$(GDB) -q  $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).elf $(GDB_ARGS)

################################################################################
# FLASH RULES
flash: $(BUILDDIR)/$(BOARD)/$(TOOLCHAIN)/$(TARGET).hex
	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
doc: $(wildcard *.cpp)
	doxygen

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

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