aboutsummaryrefslogtreecommitdiffstats
path: root/demos/AVR/RT-TEENSY2-USB/Makefile
blob: 9b217e9bd5ccdc89bdcb3e8e265264c968e71bfe (plain)
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
##############################################################################
#
# @file   Makefile.
#
# @brief  AVR Make file, it can be use to build, and program an application to
#         an AVR MCU like atmega328p, atmega2560 and so on.
#
# @author Theodore Ateba, tf.ateba@gmail.com
#
##############################################################################

##############################################################################
# Building and programming global options.
# NOTE: Can be overridden externally.
#

# Compiler options here.
ifeq ($(USE_OPT),)
  USE_OPT = -O2
endif

# C specific options here (added to USE_OPT).
ifeq ($(USE_COPT),)
  USE_COPT =
endif

# C++ specific options here (added to USE_OPT).
ifeq ($(USE_CPPOPT),)
  USE_CPPOPT =
endif

# Enable this if you want to see the full log while compiling.
ifeq ($(USE_VERBOSE_COMPILE),)
  USE_VERBOSE_COMPILE = no
endif

# If enabled, this option makes the build process faster by not compiling
# modules not used in the current configuration.
ifeq ($(USE_SMART_BUILD),)
  USE_SMART_BUILD = yes
endif

# If enable, this option arase the counter cycle after device programming.
ifeq ($(USE_AVRDUDE_ERASE_COUNTER),)
	USE_AVRDUDE_ERASE_COUNTER = no
endif

# If enable, this option perform a verification after device programming.
ifeq ($(USE_AVRDUDE_NO_VERIFY),)
	USE_AVRDUDE_NO_VERIFY = no
endif

# If enabled, this option increase the programming verbosity level.
ifeq ($(USE_VERBOSE_PROGRAMMATION),)
  USE_VERBOSE_PROGRAMMATION = no
endif

# Enable this if you want to use AVRDUDE programmer.
ifeq ($(USE_AVRDUDE_PROGRAMMER),)
  USE_AVRDUDE_PROGRAMMER = yes
endif

# Enable this if you want to use DFU programmer.
ifeq ($(USE_DFU_PROGRAMMER),)
  USE_DFU_PROGRAMMER = no
endif

# Enable this if you want to use MICRONUCLEUS programmer.
ifeq ($(USE_MICRONUCLEUS_PROGRAMMER),)
  USE_MICRONUCLEUS_PROGRAMMER = no
endif

#
# Building and programming global options.
##############################################################################

##############################################################################
# Project, sources and paths.
#

# Define project name here.
PROJECT = ch

# Imported source files and paths
CHIBIOS = ../../..

# Licensing files.
include $(CHIBIOS)/os/license/license.mk

# HAL-OSAL files (optional).
include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/hal/boards/PJRC_TEENSY_2PLUSPLUS/board.mk
include $(CHIBIOS)/os/hal/ports/AVR/MEGA/ATMEGAxx/platform.mk
include $(CHIBIOS)/os/hal/osal/rt/osal.mk

# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/AVR/compilers/GCC/mk/port.mk

# Other files (optional).
include $(CHIBIOS)/os/hal/lib/streams/streams.mk
include $(CHIBIOS)/os/various/shell/shell.mk

# List C source files here. (C dependencies are automatically generated.)
CSRC =  $(ALLCSRC)  \
        usbcfg.c    \
        main.c

# List C++ sources file here.
CPPSRC = $(ALLCPPSRC)

# Header files here.
INCDIR =  $(ALLINC)

#
# Project, sources and paths.
##############################################################################

##############################################################################
# Compiler settings.
#

# Micro-Controller Unit.
MCU = at90usb1286

# MCU frequency (Hz).
F_CPU = 16000000

# Output format. (can be srec, ihex, binary)
FORMAT = ihex

# C and C++ Compiler name.
TRGT = avr-
CC   = $(TRGT)gcc
CPPC = $(TRGT)g++

# Enable loading with g++ only if you need C++ runtime support.
# NOTE: You can use C++ even without C++ support if you are careful. C++
#       runtime support makes code size explode.
LD    = $(TRGT)gcc
CP    = $(TRGT)objcopy
AR    = $(TRGT)ar rcs
OD    = $(TRGT)objdump
NM    = $(TRGT)nm
SZ    = $(TRGT)size
HEX   = $(CP) -O ihex
BIN   = $(CP) -O binary

# Size of the elf binary file.
ELFSIZE = $(SZ) --mcu=$(MCU) --format=avr $(BUILDDIR)/$(PROJECT).elf

# MCU specific options here.
MOPT =

# Define C warning options here.
CWARN = -Wall -Wstrict-prototypes

# Define C++ warning options here.
CPPWARN =

#
# Compiler settings.
##############################################################################

##############################################################################
# Start of user section.
#

# List all user C define here, like -D_DEBUG=1.
UDEFS =

# Define ASM defines here.
UADEFS =

# List all user directories here.
UINCDIR =

# List the user directory to look for the libraries here.
ULIBDIR =

# List all user libraries here.
ULIBS =

#
# End of user defines.
##############################################################################

##############################################################################
# Start of programming Options.
#

# List of available AVR programmer.
AVRDUDE_PROGRAMMER    = avrdude
AVRDUDE_PROGRAMMER_ID = wiring
DFU_PROGRAMMER        = dfu-programmer
MICRONUCLEUS          = micronucleus

# Set the AVR programmer according to the selection..
ifeq ($(USE_AVRDUDE_PROGRAMMER),yes)
	AVR_PROGRAMMER = $(AVRDUDE_PROGRAMMER)
else ifeq ($(USE_DFU_PROGRAMMER),yes)
	AVR_PROGRAMMER = $(DFU_PROGRAMMER)
else ifeq ($(USE_MICRONUCLEUS_PROGRAMMER),yes)
	AVR_PROGRAMMER = $(MICRONUCLEUS_PROGRAMMER)
else
  $(error ERROR: Please you need to configure the AVR programmer!)
endif

# AVR serial port.
AVRDUDE_PORT = /dev/ttyUSB0

AVRDUDE_WRITE_FLASH = -D -U flash:w:$(BUILDDIR)/$(PROJECT).hex

# Check if the counter cycle erase must be performed after device programming.
ifeq ($(USE_AVRDUDE_ERASE_COUNTER),yes)
	AVRDUDE_ERASE_COUNTER = -y
endif

# Check if a verification must be performed after device programming.
ifeq ($(USE_AVRDUDE_NO_VERIFY),no)
	AVRDUDE_NO_VERIFY = -V
endif

# Check verbosity level activation.
ifeq ($(USE_VERBOSE_PROGRAMMATION),yes)
	AVRDUDE_VERBOSE = -v -v
endif

# AVR programmer flags for AVRDUDE programmer.
ifeq ($(AVR_PROGRAMMER),$(AVRDUDE_PROGRAMMER))
AVRDUDE_FLAGS = -p $(MCU)
AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)
AVRDUDE_FLAGS += -b 115200
AVRDUDE_FLAGS += -c $(AVRDUDE_PROGRAMMER_ID)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
endif

# AVR programmer flags for DFU programmer.
ifeq ($(AVR_PROGRAMMER),$(DFU_PROGRAMMER))
DFU_WRITE_FLASH = flash --force
DFU_ERASE_FLASH = erase
DFU_RESET=reset
endif

# AVR programmer flags for MICRONUCLEUS programmer.
ifeq ($(AVR_PROGRAMMER),$(MICRONUCLEUS_PROGRAMMER))
MICRONUCLEUS_TIMEOUT_ARG = --timeout 60
MICRONUCLEUS_RUN_ARG = --run
MICRONUCLEUS_TYPE_ARG = --type raw
MICRONUCLEUS_DUMP_PROGRESS = --dump-progress
MICRONUCLEUS_FLAGS=$(MICRONUCLEUS_TYPE_ARG)
MICRONUCLEUS_FLAGS+=$(MICRONUCLEUS_TIMEOUT_ARG)
MICRONUCLEUS_FLAGS+=$(MICRONUCLEUS_RUN_ARG)
endif

#
# End of Programming Options.
##############################################################################

##############################################################################
# Include file.
#

RULESPATH = $(CHIBIOS)/os/common/ports/AVR/compilers/GCC
include $(RULESPATH)/rules.mk

#
# End of include file.
##############################################################################

##############################################################################
# Programming rules
#

# AVRDUDE programming rules.
ifeq ($(AVR_PROGRAMMER),$(AVRDUDE_PROGRAMMER))
program: $(BUILDDIR)/$(PROJECT).hex
	@echo
	@echo Programming $(MCU) device.
	$(AVR_PROGRAMMER) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $<
	@echo Done.
endif

# DFU programming rules.
ifeq ($(AVR_PROGRAMMER),$(DFU_PROGRAMMER))
program: $(BUILDDIR)/$(PROJECT).hex
	@echo
	@echo Programming $(MCU) device.
	$(AVR_PROGRAMMER) $(MCU) $(DFU_WRITE_FLASH) $<
	$(AVR_PROGRAMMER) $(MCU) $(DFU_RESET)
	@echo Done.

erase:
	@echo
	@echo Erasing $(MCU) device.
	$(AVR_PROGRAMMER) $(MCU) $(DFU_ERASE_FLASH)
	@echo Done.
endif

# MICRONUCLEUS programming rules.
ifeq ($(AVR_PROGRAMMER),$(MICRONUCLEUS_PROGRAMMER))
program: $(BUILDDIR)/$(PROJECT).bin
	@echo
	@echo Programming $(MCU) device.
	$(AVR_PROGRAMMER) $(MICRONUCLEUS_FLAGS) $<
	@echo Done.
endif

#
# End of programming rules.
##############################################################################

# EOF