forked from ArduPilot/ardupilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
board_avr.mk
200 lines (158 loc) · 6.06 KB
/
board_avr.mk
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
TOOLCHAIN = AVR
include $(MK_DIR)/find_arduino.mk
include $(MK_DIR)/find_tools.mk
#
# Tool options
#
DEFINES = -DF_CPU=$(F_CPU)
DEFINES += -DSKETCH=\"$(SKETCH)\" -DAPM_BUILD_DIRECTORY=APM_BUILD_$(SKETCH)
DEFINES += $(EXTRAFLAGS)
DEFINES += -DCONFIG_HAL_BOARD=$(HAL_BOARD)
WARNFLAGS = -Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align
WARNFLAGS += -Wwrite-strings -Wformat=2 -Wno-unused-parameter -Wno-missing-field-initializers
WARNFLAGSCXX = -Wno-reorder
DEPFLAGS = -MD -MT $@
CXXOPTS = -ffunction-sections -fdata-sections -fno-exceptions -fsigned-char -fno-use-cxa-atexit
COPTS = -ffunction-sections -fdata-sections -fsigned-char
ASOPTS = -x assembler-with-cpp
LISTOPTS = -adhlns=$(@:.o=.lst)
NATIVE_CPUFLAGS = -D_GNU_SOURCE
NATIVE_CPULDFLAGS = -g
NATIVE_OPTFLAGS = -O0 -g
AVR_CPUFLAGS = -mmcu=$(MCU) -mcall-prologues
AVR_CPULDFLAGS = -Wl,-m,avr6
AVR_OPTFLAGS = -Os
CPUFLAGS= $($(TOOLCHAIN)_CPUFLAGS)
CPULDFLAGS= $($(TOOLCHAIN)_CPULDFLAGS)
OPTFLAGS= $($(TOOLCHAIN)_OPTFLAGS)
CXXFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(OPTFLAGS)
CXXFLAGS += -std=gnu++11 $(WARNFLAGS) $(WARNFLAGSCXX) $(DEPFLAGS) $(CXXOPTS)
CFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(OPTFLAGS)
CFLAGS += $(WARNFLAGS) $(DEPFLAGS) $(COPTS)
ASFLAGS = -g $(CPUFLAGS) $(DEFINES) -Wa,$(LISTOPTS) $(DEPFLAGS)
ASFLAGS += $(ASOPTS)
LDFLAGS = -g $(CPUFLAGS) $(OPTFLAGS) $(WARNFLAGS)
LDFLAGS += -Wl,--gc-sections -Wl,-Map -Wl,$(SKETCHMAP)
ifneq ($(BOARD),mega)
LDFLAGS += $(CPULDFLAGS)
endif
# under certain situations with certain avr-gcc versions the --relax flag causes
# a bug. Give the user a way to disable this flag per-sketch.
# I know this is a rotten hack but we're really close to sunset on AVR.
EXCLUDE_RELAX := $(wildcard $(SRCROOT)/norelax.inoflag)
ifeq ($(EXCLUDE_RELAX),)
LDFLAGS += -Wl,--relax
endif
LIBS = -lm
ifeq ($(VERBOSE),)
v = @
else
v =
endif
# Library object files
LIBOBJS := $(SKETCHLIBOBJS)
HARDWARE ?= arduino
BOARD ?= mega2560
# Find the hardware directory to use
HARDWARE_DIR := $(firstword $(wildcard $(SKETCHBOOK)/hardware/$(HARDWARE) \
$(ARDUINO)/hardware/$(HARDWARE)/avr \
$(ARDUINO)/hardware/$(HARDWARE) \
)\
)
ifeq ($(HARDWARE_DIR),)
$(error ERROR: hardware directory for $(HARDWARE) not found)
endif
# Find the boards.txt that we are using
BOARDFILE := $(wildcard $(HARDWARE_DIR)/boards.txt)
ifeq ($(BOARDFILE),)
$(error ERROR: could not locate boards.txt for hardware $(HARDWARE))
endif
# Extract needed build parameters from the boardfile
MCU := $(shell grep $(BOARD).build.mcu $(BOARDFILE) | cut -d = -f 2)
F_CPU := $(shell grep $(BOARD).build.f_cpu $(BOARDFILE) | cut -d = -f 2)
HARDWARE_CORE := $(shell grep $(BOARD).build.core $(BOARDFILE) | cut -d = -f 2)
UPLOAD_SPEED := $(shell grep $(BOARD).upload.speed $(BOARDFILE) | cut -d = -f 2)
# User can define USERAVRDUDEFLAGS = -V in their config.mk to skip verification
USERAVRDUDEFLAGS ?=
#make sure the avrdude conf file is referenced correctly in cygwin
ifneq ($(findstring CYGWIN, $(SYSTYPE)),)
USERAVRDUDEFLAGS := -C $(ARDUINO)/hardware/tools/avr/etc/avrdude.conf
endif
#make sure the avrdude conf file is referenced correctly in mingw
ifneq ($(findstring MINGW, $(SYSTYPE)),)
USERAVRDUDEFLAGS := -C $(ARDUINO)/hardware/tools/avr/etc/avrdude.conf
endif
#make sure the avrdude conf file is referenced correctly in darwin
ifneq ($(findstring Darwin, $(SYSTYPE)),)
USERAVRDUDEFLAGS := -C $(ARDUINO)/hardware/tools/avr/etc/avrdude.conf
endif
ifeq ($(UPLOAD_PROTOCOL),)
UPLOAD_PROTOCOL := $(shell grep $(BOARD).upload.protocol $(BOARDFILE) | cut -d = -f 2)
endif
# Adding override for mega since boards.txt uses stk500 instead of
# arduino on 22 release
ifeq ($(BOARD),mega)
UPLOAD_PROTOCOL := arduino
endif
#On Cygwin, the wiring programmer will perform the DTR reset for us
ifneq ($(findstring CYGWIN, $(SYSTYPE)),)
UPLOAD_PROTOCOL := wiring
endif
ifeq ($(MCU),)
$(error ERROR: Could not locate board $(BOARD) in $(BOARDFILE))
endif
################################################################################
# Built products
#
# The ELF file
SKETCHELF = $(BUILDROOT)/$(SKETCH).elf
BUILDELF = $(notdir $(SKETCHELF))
# HEX file
SKETCHHEX = $(BUILDROOT)/$(SKETCH).hex
# EEP file
SKETCHEEP = $(BUILDROOT)/$(SKETCH).eep
# Map file
SKETCHMAP = $(BUILDROOT)/$(SKETCH).map
# All of the objects that may be built
ALLOBJS = $(SKETCHOBJS) $(LIBOBJS)
# All of the dependency files that may be generated
ALLDEPS = $(ALLOBJS:%.o=%.d)
################################################################################
# Targets
#
all: $(SKETCHELF) $(SKETCHEEP) $(SKETCHHEX)
print-%:
echo "$*=$($*)"
.PHONY: upload
upload: $(SKETCHHEX)
$(AVRDUDE) -c $(UPLOAD_PROTOCOL) -p $(MCU) -P $(PORT) -b$(UPLOAD_SPEED) $(USERAVRDUDEFLAGS) -U flash:w:$(SKETCHHEX):i
debug:
$(AVARICE) --mkII --capture --jtag usb :4242 & \
gnome-terminal -x $(GDB) $(SKETCHELF) & \
echo -e '\n\nat the gdb prompt type "target remote localhost:4242"'
# this allows you to flash your image via JTAG for when you
# have completely broken your USB
jtag-program:
$(AVARICE) --mkII --jtag usb --erase --program --file $(SKETCHELF)
################################################################################
# Rules
#
# fetch dependency info from a previous build if any of it exists
-include $(ALLDEPS)
# Link the final object
$(SKETCHELF): $(SKETCHOBJS) $(LIBOBJS)
$(RULEHDR)
$(v)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
$(v)cp $(SKETCHELF) $(BUILDELF)
@echo "Firmware is in $(BUILDELF)"
# Create the hex file
$(SKETCHHEX): $(SKETCHELF)
$(RULEHDR)
$(v)$(OBJCOPY) -O ihex -R .eeprom $< $@
# Create the eep file
$(SKETCHEEP): $(SKETCHELF)
$(RULEHDR)
$(v)$(OBJCOPY) -O ihex -j.eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $@
SKETCH_INCLUDES = $(SKETCHLIBINCLUDES)
SLIB_INCLUDES = -I$(dir $<)/utility $(SKETCHLIBINCLUDES)
include $(MK_DIR)/build_rules.mk