This repository has been archived by the owner on Aug 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
/
Makefile-AVR
214 lines (185 loc) · 8.95 KB
/
Makefile-AVR
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
##############################################################################
# #
# 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 <[email protected]> #
# #
# 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 AVR (ATmega-based) targets. Use it with #
# #
# make -f Makefile-AVR #
# #
# or copy/link it to Makefile for convenience. #
# #
##############################################################################
##############################################################################
# #
# Change these to suit your hardware #
# #
##############################################################################
# MCU ?= atmega168
# MCU ?= atmega328p
MCU ?= atmega644
# MCU ?= atmega644
# MCU ?= atmega1284p
# MCU ?= atmega1280
# MCU ?= atmega2560
# MCU ?= at90usb1286
# MCU ?= atmega32u4
# CPU clock rate
# F_CPU ?= 8000000L
F_CPU ?= 16000000L
# F_CPU ?= 20000000L
##############################################################################
# #
# Where to find your compiler and linker. Later, this is completed like #
# CC = $(TOOLCHAIN)gcc #
# #
##############################################################################
TOOLCHAIN = avr-
# TOOLCHAIN = /usr/bin/avr-
# TOOLCHAIN = <path-to-arduino-folder>/hardware/tools/avr/bin/avr-
##############################################################################
# #
# Programmer settings for "make program" #
# #
##############################################################################
# avrdude, typical for AVR-based architectures.
#
# Flags:
# -c <programmer-type> Typically stk500 or stk500v2.
# -b <baudrate> Upload baud rate. Depends on the bootloader in
# use. Not used for USB programmers.
# -p <mcu type> See MCU above.
# -P <port> Serial port the electronics is connected to.
# -C <config file> Optional, default is /etc/avrdude.conf.
UPLOADER ?= avrdude
# UPLOADER = <path-to-arduino-folder>/hardware/tools/avrdude
ifndef UPLOADER_FLAGS
UPLOADER_FLAGS = -c stk500v2
# UPLOADER_FLAGS += -b 19200
# UPLOADER_FLAGS += -b 57600
UPLOADER_FLAGS += -b 115200
UPLOADER_FLAGS += -p $(MCU)
# UPLOADER_FLAGS += -P COM1
# UPLOADER_FLAGS += -P /dev/ttyACM0
UPLOADER_FLAGS += -P /dev/ttyUSB0
# UPLOADER_FLAGS += -C <path-to-arduino-folder>/hardware/tools/avrdude.conf
endif
##############################################################################
# #
# 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)
# Link time optimization is on by default
ifeq ($(USE_FLTO),)
USE_FLTO=yes
endif
CFLAGS = $(EXTRA_CFLAGS)
CFLAGS += -DF_CPU=$(F_CPU)
CFLAGS += -DMCU_STR=\"$(MCU)\"
CFLAGS += -mmcu=$(MCU)
CFLAGS += -g
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -std=gnu99
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -Winline
CFLAGS += -fno-move-loop-invariants
CFLAGS += -fno-tree-scev-cprop
CFLAGS += -Os
CFLAGS += -ffunction-sections
CFLAGS += -finline-functions-called-once
CFLAGS += -mcall-prologues
ifeq ($(USE_FLTO),yes)
CFLAGS += -flto
endif
CFLAGS += -Wa,-adhlns=$(@:.o=.al)
#CFLAGS += -dM -E # To list all predefined macros into the .o file.
LDFLAGS = -Wl,--as-needed
LDFLAGS += -Wl,--gc-sections
ifneq ($(realpath ../simulavr/src/simulavr_info.h),)
# Neccessary for simulavr support, doesn't hurt others.
CFLAGS += -DSIMINFO
LDFLAGS += -Wl,--section-start=.siminfo=0x900000
LDFLAGS += -u siminfo_device
LDFLAGS += -u siminfo_cpufrequency
LDFLAGS += -u siminfo_serial_in
LDFLAGS += -u siminfo_serial_out
endif
LIBS = -lm
-include Makefile-common
# Architecture specific targets
.PHONY: all program size
all: $(PROGRAM).hex $(BUILDDIR)/$(PROGRAM).lst $(BUILDDIR)/$(PROGRAM).sym size
program: $(PROGRAM).hex config.h
$(UPLOADER) $(UPLOADER_FLAGS) -U flash:w:$(PROGRAM).hex
## Interpret TARGET section sizes wrt different AVR chips.
## Usage: $(call show_size,section-name,section-regex,168-size,328p-size,644p-size,1280-size)
define show_size
@$(SIZE) -A $^ | perl -MPOSIX -ne \
'/\.($2)\s+([0-9]+)/g && \
do {$$data += $$2}; \
END { printf "%8s %6d bytes %3d%% %3d%% %3d%% %3d%%\n", \
$1, $$data, \
ceil($$data * 100 / ($3 * 1024)), \
ceil($$data * 100 / ($4 * 1024)), \
ceil($$data * 100 / ($5 * 1024)), \
ceil($$data * 100 / ($6 * 1024));\
}'
endef
size: $(BUILDDIR)/$(PROGRAM).elf
@echo "ATmega sizes '168 '328(P) '644(P) '1280"
$(call show_size,FLASH,text|data|bootloader,14,30,62,126)
$(call show_size,RAM,data|bss|noinit,1,2,4,8)
$(call show_size,EEPROM,eeprom,1,2,2,4)
.PHONY: simulavr-check simulavr performancetest
simulavr-check:
@if [ ! -x ../simulavr/src/simulavr ]; then \
echo "Can't find SimulAVR executable in ../simulavr/src/simulavr."; \
echo "Please install and build it next to the Teacup_Firmware folder."; \
echo "Sources can be found at https://github.com/Traumflug/simulavr"; \
false; \
fi
simulavr:
@$(MAKE) --no-print-directory -f Makefile-AVR simulavr-check
@echo "Compiling for SimulAVR and running the result in SimulAVR."
$(MAKE) -f Makefile-AVR USER_CONFIG=testcases/config.h.Profiling \
MCU=atmega644 F_CPU=20000000UL all
../simulavr/src/simulavr -f build/testcases/config.h.Profiling/teacup.elf
performancetest:
@$(MAKE) --no-print-directory -f Makefile-AVR simulavr-check
@echo "Compiling for SimulAVR and running performance tests."
$(MAKE) -f Makefile-AVR USER_CONFIG=testcases/config.h.Profiling \
MCU=atmega644 F_CPU=20000000UL all
cd testcases && USER_CONFIG=config.h.Profiling \
./run-in-simulavr.sh short-moves.gcode smooth-curves.gcode triangle-odd.gcode