forked from Traumflug/Teacup_Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile-ARM
219 lines (188 loc) · 8.72 KB
/
Makefile-ARM
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
##############################################################################
# #
# Teacup - Lean and efficient firmware for RepRap printers #
# #
# by Triffid Hunter, Traumflug, jakepoz, many others. #
# #
# This firmware is Copyright (c) ... #
# 2009 - 2010 Michael Moon aka Triffid_Hunter #
# 2010 - 2013 Markus "Traumflug" Hitter <mah@jump-ing.de> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #
# #
##############################################################################
##############################################################################
# #
# Makefile for ARM targets. Use it with #
# #
# make -f Makefile-ARM #
# #
# or copy/link it to Makefile for convenience. #
# #
##############################################################################
##############################################################################
# #
# Change these to suit your hardware #
# #
##############################################################################
MCU ?= lpc1114
# MCU ?= stm32f411
# some size parameters. Not important for flashing and compiling.
ifeq ($(MCU), lpc1114)
FLASH_SIZE = 32
RAM_SIZE = 4
else ifeq ($(MCU), stm32f411)
FLASH_SIZE = 512
RAM_SIZE = 128
endif
# CPU clock rate not defined here, but in the CMSIS headers.
##############################################################################
# #
# Where to find your compiler and linker. Later, this is completed like #
# CC = $(TOOLCHAIN)gcc #
# #
##############################################################################
TOOLCHAIN = arm-none-eabi-
# TOOLCHAIN = <path-to-arduino-folder>/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/arm-none-eabi-
##############################################################################
# #
# Programmer settings for "make program" #
# #
##############################################################################
# Unlike with AVR, there is no one tool for uploading to all chips. Some
# need 'lpc21isp', others (e.g. Arduinos) need 'bossac'.
#
# To deal with this, we simply define the port here and do the rest directly
# in the rules for the 'program' target.
# Frequency of the on-chip R/C oscillator or the on-board quartz crystal.
# Not to confuse with the CPU's clock frequency, which is usually much higher.
F_CRYSTAL ?= 12000000
# This is your uploader with any option before your uploadfile $<
# and your uploadfile (hex, bin or whatelse)
ifeq ($(MCU), lpc1114)
UPLOADER ?= lpc21isp -control
UPLOAD_FILE = $(PROGRAM).hex
else ifeq ($(MCU), stm32f411)
UPLOADER ?= st-flash --reset write
UPLOAD_FILE = $(BUILDDIR)/$(PROGRAM).bin
endif
ifeq ($(MCU), lpc1114)
UPLOADER_FLAGS = $(UPLOADER_PORT)
UPLOADER_FLAGS += 115200
UPLOADER_FLAGS += $(F_CRYSTAL)
else ifeq ($(MCU), stm32f411)
UPLOADER_FLAGS = 0x8000000
endif
# Serial port the electronics is connected to.
#UPLOADER_PORT ?= /dev/ttyUSB0
UPLOADER_PORT ?= /dev/ttyACM0
#UPLOADER_PORT ?= com1
##############################################################################
# #
# Below here, defaults should be ok. #
# #
##############################################################################
PROGRAM = teacup
# The thing we build by default, and also the thing we clean.
TARGET = $(PROGRAM).hex
# Arduino IDE takes the "compile everything available"-approach, so we have
# to keep this working and can take a shortcut:
SOURCES = $(wildcard *.c)
# Other target MCU specific adjustments:
ifeq ($(MCU), lpc1114)
STARTUP_FILE = cmsis-startup_lpc11xx.s
else ifeq ($(MCU), stm32f411)
STARTUP_FILE = cmsis-startup_stm32f411xe.s
endif
# Startup definitions. Not target MCU specific.
CFLAGS = -D__STARTUP_CLEAR_BSS -D__START=main
ifeq ($(MCU), lpc1114)
CFLAGS += -mthumb -mcpu=cortex-m0
CFLAGS += -mtune=cortex-m0
CFLAGS += -D__ARM_LPC1114__
else ifeq ($(MCU), stm32f411)
CFLAGS += -mthumb -mcpu=cortex-m4
CFLAGS += -mtune=cortex-m4
CFLAGS += -D__ARM_STM32F411__
CFLAGS += -mfpu=fpv4-sp-d16
CFLAGS += -mfloat-abi=hard
CFLAGS += -mlittle-endian
CFLAGS += -D__FPU_PRESENT=1
CFLAGS += -fomit-frame-pointer
endif
# Other options ...
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -Os
CFLAGS += -flto
CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
#CFLAGS += -dM -E # To list all predefined macros into the .o file.
LDFLAGS = --specs=nano.specs
LDFLAGS += --specs=nosys.specs
ifeq ($(MCU), lpc1114)
LDFLAGS += -T cmsis-lpc1114.ld
else ifeq ($(MCU), stm32f411)
LDFLAGS += -T cmsis-stm32f411xe.ld
endif
LDFLAGS += -Wl,--as-needed
LDFLAGS += -Wl,--gc-sections
LIBS = -lm
-include Makefile-common
# Architecture specific targets
.PHONY: all program size
all: $(PROGRAM).hex $(BUILDDIR)/$(PROGRAM).lst $(BUILDDIR)/$(PROGRAM).sym size
# TODO: The echo is only for Gen7-ARM LPC1114. The stm flashes don't need this.
# This message could confuse someone. Remove this message for stm or write some
# friendly text for it.
ifeq ($(MCU), lpc1114)
define upload_echo
@echo
@echo "To let the bootloader complete his work, connect now PIO0_1 to GND,"
@echo "then press Reset for a moment. The bootloader should begin uploading."
@echo "After being done, disconnect PIO0_1 and press reset again. On a"
@echo "Gen7-ARM, PIO0_1 is the Step pin of the Z stepper driver."
@echo
endef
else ifeq ($(MCU), stm32f411)
define upload_echo
@echo
@echo "Starting upload..."
@echo "This should normally take no time."
@echo
endef
endif
program: $(UPLOAD_FILE) config.h
$(call upload_echo)
$(UPLOADER) $< $(UPLOADER_FLAGS)
$(BUILDDIR)/teacup.elf: $(BUILDDIR)/startup.o
$(BUILDDIR)/startup.o: $(STARTUP_FILE) | $(BUILDDIR)
@echo " CC $@"
@$(CC) -c $(CFLAGS) -o $@ $<
## Interpret TARGET section sizes wrt different ARM chips
## Usage: $(call show_size,section-name,section-regex,lpc1114-size-in-k)
define show_size
@$(OBJDUMP) -h $^ | \
perl -MPOSIX -ne \
'/.($2)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; \
END { printf " %-7s: %5d bytes %3d%%\n", "$1", $$a, \
ceil($$a * 100 / ($3 * 1024)), \
}'
endef
size: $(BUILDDIR)/$(PROGRAM).elf
@echo " SIZES ARM... $(MCU)"
$(call show_size,FLASH,text,$(FLASH_SIZE))
$(call show_size,RAM,data|bss,$(RAM_SIZE))
$(call show_size,EEPROM,eeprom,0.0001)