summaryrefslogtreecommitdiff
path: root/src/arch/atmega2560/Makefile.inc
blob: 6d82a1c56eb0e4715f9a96e8edb64aca7a0826f0 (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
# vim:ft=make
#
# Copyright 2021 Birte Kristina Friesel
#
# SPDX-License-Identifier: BSD-2-Clause

MCU = atmega2560
SERIAL_PORT ?= /dev/ttyUSB0
BAUD = 115200

ifdef CONFIG_arch_atmega2560_cpufreq
	cpu_freq = ${CONFIG_arch_atmega2560_cpufreq}
endif

cpu_freq ?= 16000000

COMMON_FLAGS += -Werror=overflow
COMMON_FLAGS += -mmcu=${MCU} -DMULTIPASS_ARCH_atmega2560
COMMON_FLAGS += -DF_CPU=${cpu_freq}UL

ifeq (${stack_usage}, )
	COMMON_FLAGS += -flto
endif

CC = avr-gcc
CXX = avr-g++
NM = avr-nm
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump

ARCH_SHORTNAME = avr

ifdef CONFIG_aspectc
	CXX = ag++ -r build/repo.acp -v 0 --c_compiler avr-g++ -p . --Xcompiler
endif

CXX_TARGETS += src/arch/atmega2560/arch.cc
CXX_TARGETS += src/arch/atmega2560/driver/gpio.cc
CXX_TARGETS += src/arch/atmega2560/driver/stdout.cc

# Command-line driver selection

ifneq ($(findstring softi2c,${drivers}), )
else ifneq ($(findstring i2c,${arch_drivers}), )
	CONFIG_arch_atmega2560_driver_i2c = y
endif

ifneq ($(findstring adc,${arch_drivers}), )
	CONFIG_arch_atmega2560_driver_adc = y
endif

ifneq ($(findstring spi,${arch_drivers}), )
	CONFIG_arch_atmega2560_driver_spi = y
endif

ifneq ($(findstring stdin,${arch_drivers}), )
	CONFIG_arch_atmega2560_driver_stdin = y
endif

ifneq ($(findstring timer,${arch_drivers}), )
	CONFIG_arch_atmega2560_driver_timer = y
endif

ifneq ($(findstring counter,${arch_drivers}), )
	CONFIG_arch_atmega2560_driver_counter = y
endif

ifneq ($(findstring neopixel,${arch_drivers}), )
	CONFIG_arch_atmega2560_driver_neopixel = y
endif

ifeq (${timer_s}, 1)
	CONFIG_arch_atmega2560_driver_uptime = y
endif

# Kconfig driver selection

ifdef CONFIG_arch_atmega2560_driver_i2c
	CXX_TARGETS += src/arch/atmega2560/driver/i2c.cc
endif

ifdef CONFIG_arch_atmega2560_driver_adc
	CXX_TARGETS += src/arch/atmega2560/driver/adc.cc
endif

ifdef CONFIG_arch_atmega2560_driver_dmx1
	CXX_TARGETS += src/arch/atmega2560/driver/dmx1.cc
endif

ifdef CONFIG_arch_atmega2560_driver_dmx2
	CXX_TARGETS += src/arch/atmega2560/driver/dmx2.cc
endif

ifdef CONFIG_arch_atmega2560_driver_dmx3
	CXX_TARGETS += src/arch/atmega2560/driver/dmx3.cc
endif

ifdef CONFIG_arch_atmega2560_driver_spi
	CXX_TARGETS += src/arch/atmega2560/driver/spi.cc
endif

ifdef CONFIG_arch_atmega2560_driver_stdout1
	CXX_TARGETS += src/arch/atmega2560/driver/stdout1.cc
endif

ifdef CONFIG_arch_atmega2560_driver_stdout2
	CXX_TARGETS += src/arch/atmega2560/driver/stdout2.cc
endif

ifdef CONFIG_arch_atmega2560_driver_stdout3
	CXX_TARGETS += src/arch/atmega2560/driver/stdout3.cc
endif

ifdef CONFIG_arch_atmega2560_driver_stdin
	CXX_TARGETS += src/arch/atmega2560/driver/stdin.cc
endif

ifdef CONFIG_arch_atmega2560_driver_stdin1
	CXX_TARGETS += src/arch/atmega2560/driver/stdin1.cc
endif

ifdef CONFIG_arch_atmega2560_driver_stdin2
	CXX_TARGETS += src/arch/atmega2560/driver/stdin2.cc
endif

ifdef CONFIG_arch_atmega2560_driver_stdin3
	CXX_TARGETS += src/arch/atmega2560/driver/stdin3.cc
endif

ifdef CONFIG_arch_atmega2560_driver_timer
	CXX_TARGETS += src/arch/atmega2560/driver/timer.cc
endif

ifdef CONFIG_arch_atmega2560_driver_counter
	CXX_TARGETS += src/arch/atmega2560/driver/counter.cc
endif

ifdef CONFIG_arch_atmega2560_driver_neopixel
	CXX_TARGETS += src/arch/atmega2560/driver/neopixel.cc
endif

ifdef CONFIG_arch_atmega2560_driver_uptime
	COMMON_FLAGS += -DTIMER_S
	CXX_TARGETS += src/arch/atmega2560/driver/uptime.cc
endif

ifeq (${cpu_freq}, 16000000)
	uart_baud = 57600
else ifeq (${cpu_freq}, 8000000)
	uart_baud = 38400
else ifeq (${cpu_freq}, 4000000)
	uart_baud = 38400
else ifeq (${cpu_freq}, 2000000)
	uart_baud = 19200
else ifeq (${cpu_freq}, 1000000)
	uart_baud = 9600
else ifeq (${cpu_freq}, 500000)
	uart_baud = 4800
else ifeq (${cpu_freq}, 250000)
	uart_baud = 2400
else ifeq (${cpu_freq}, 125000)
	uart_baud = 1200
else ifeq (${cpu_freq}, 62500)
	uart_baud = 300
else
	uart_baud = 9600
endif

COMMON_FLAGS += -DBAUD=${uart_baud}UL

OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o}

%.o : %.cc | include/config.h
	${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}

%.o : %.c | include/config.h
	${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} ${CFLAGS} -c -o $@ ${@:.o=.c}

build/system.elf: ${OBJECTS}
	${QUIET}mkdir -p build
	${QUIET}${CXX} ${COMMON_FLAGS} ${CXXFLAGS} -Wl,--gc-sections -o $@ ${OBJECTS}
	${QUIET}avr-size --format=avr --mcu=${MCU} $@
	${QUIET}test $$(avr-size --format=avr --mcu=${MCU} build/system.elf | fgrep Program | grep -o '[0-9.]*%' | cut -d . -f 1) -lt 100

build/system.hex: build/system.elf
	${QUIET}${OBJCOPY} -O ihex ${@:.hex=.elf} $@

program: build/system.hex
	${QUIET}avrdude -p ${MCU} -c wiring -P ${SERIAL_PORT} -b ${BAUD} -D -U flash:w:build/system.hex

arch_clean:
	${QUIET}rm -f ${OBJECTS} build/system.hex

cat:
	${QUIET}script/cat.py ${SERIAL_PORT} ${uart_baud} ${cpu_freq} 65536

monitor:
	${QUIET}screen ${SERIAL_PORT} ${uart_baud}

size: build/system.elf
	${QUIET}avr-size --format=avr --mcu=${MCU} build/system.elf | fgrep Program | perl -nE 'if (m{(\d+) bytes \(([0-9.]+%)}) { print("$$1;$$2;") }'
	${QUIET}avr-size --format=avr --mcu=${MCU} build/system.elf | fgrep Data | perl -nE 'if (m{(\d+) bytes \(([0-9.]+%)}) { print("$$1;$$2;") }'
	${QUIET}echo

arch_help:
	@echo "atmega2560 specific flags:"
	@echo " SERIAL_PORT = ${SERIAL_PORT}"
	@echo "        BAUD = ${BAUD} (only used for programming)"

arch_info:
	@echo "CPU   Freq: ${cpu_freq} Hz"
	@echo "Timer Freq: ${timer_freq} Hz"
	@echo "I2C   Freq: ${i2c_freq} Hz"
	@echo "Counter Overflow: 65536/255"
	@echo "Monitor: ${SERIAL_PORT} ${uart_baud}"

attributes: build/system.elf
	${QUIET}script/size.py avr-size text,data data,bss

nfpvalues: build/system.elf
	${QUIET}script/nfpvalues.py avr-size text,data data,bss

.PHONY: arch_clean arch_help arch_info attributes cat monitor program size