Newer
Older
# vim:ft=make
MCU = atmega328p
SERIAL_PORT ?= /dev/ttyUSB0
BAUD = 57600
ifdef CONFIG_arch_arduino_nano_mega168
MCU = atmega168
BAUD = 19200
endif
cpu_freq ?= 16000000
COMMON_FLAGS += -Werror=overflow
COMMON_FLAGS += -mmcu=${MCU} -DMULTIPASS_ARCH_arduino_nano
COMMON_FLAGS += -DF_CPU=${cpu_freq}UL
COMMON_FLAGS += -DMULTIPASS_ARCH_HAS_I2C
ifeq (${stack_usage}, )
COMMON_FLAGS += -flto
endif
CC = avr-gcc
CXX = avr-g++
NM = avr-nm
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
ifeq (${aspectc}, 1)
CXX = ag++ -r build/repo.acp -v 0 --c_compiler avr-g++ -p . --Xcompiler
endif
CXX_TARGETS += src/arch/arduino-nano/arch.cc
CXX_TARGETS += src/arch/arduino-nano/driver/gpio.cc
CXX_TARGETS += src/arch/arduino-nano/driver/stdout.cc
ifneq ($(findstring softi2c,${drivers}), )
else ifneq ($(findstring i2c,${arch_drivers}), )
CONFIG_arch_arduino_nano_driver_i2c = y
ifneq ($(findstring adc,${arch_drivers}), )
CONFIG_arch_arduino_nano_driver_adc = y
ifneq ($(findstring spi,${arch_drivers}), )
CONFIG_arch_arduino_nano_driver_spi = y
ifneq ($(findstring stdin,${arch_drivers}), )
CONFIG_arch_arduino_nano_driver_stdin = y
ifneq ($(findstring timer,${arch_drivers}), )
CONFIG_arch_arduino_nano_driver_timer = y
Birte Kristina Friesel
committed
ifneq ($(findstring counter,${arch_drivers}), )
CONFIG_arch_arduino_nano_driver_counter = y
Birte Kristina Friesel
committed
endif
ifneq ($(findstring neopixel,${arch_drivers}), )
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
CONFIG_arch_arduino_nano_driver_neopixel = y
endif
ifeq (${timer_s}, 1)
CONFIG_arch_arduino_nano_driver_uptime = y
endif
# Kconfig driver selection
ifdef CONFIG_arch_arduino_nano_driver_i2c
CXX_TARGETS += src/arch/arduino-nano/driver/i2c.cc
endif
ifdef CONFIG_arch_arduino_nano_driver_adc
CXX_TARGETS += src/arch/arduino-nano/driver/adc.cc
endif
ifdef CONFIG_arch_arduino_nano_driver_spi
CXX_TARGETS += src/arch/arduino-nano/driver/spi.cc
endif
ifdef CONFIG_arch_arduino_nano_driver_stdin
CXX_TARGETS += src/arch/arduino-nano/driver/stdin.cc
endif
ifdef CONFIG_arch_arduino_nano_driver_timer
CXX_TARGETS += src/arch/arduino-nano/driver/timer.cc
endif
ifdef CONFIG_arch_arduino_nano_driver_counter
CXX_TARGETS += src/arch/arduino-nano/driver/counter.cc
endif
ifdef CONFIG_arch_arduino_nano_driver_neopixel
CXX_TARGETS += src/arch/arduino-nano/driver/neopixel.cc
endif
ifdef CONFIG_arch_arduino_nano_driver_uptime
COMMON_FLAGS += -DTIMER_S
CXX_TARGETS += src/arch/arduino-nano/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
COMMON_FLAGS += -DBAUD=${uart_baud}UL
OBJECTS = ${CXX_TARGETS:.cc=.o} ${C_TARGETS:.c=.o}
${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
.c.o:
${QUIET}${CC} ${INCLUDES} ${COMMON_FLAGS} ${CFLAGS} -c -o $@ ${@:.o=.c}
${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} $@
${QUIET}avrdude -p ${MCU} -c arduino -P ${SERIAL_PORT} -b ${BAUD} -U flash:w:build/system.hex
${QUIET}rm -f ${OBJECTS} build/system.hex
${QUIET}screen ${SERIAL_PORT} ${uart_baud}
size: build/system.elf
${QUIET}avr-size --format=avr --mcu=atmega328p build/system.elf | fgrep Program | perl -nE 'if (m{(\d+) bytes \(([0-9.]+%)}) { print("$$1;$$2;") }'
${QUIET}avr-size --format=avr --mcu=atmega328p build/system.elf | fgrep Data | perl -nE 'if (m{(\d+) bytes \(([0-9.]+%)}) { print("$$1;$$2;") }'
${QUIET}echo
arch_help:
@echo "arduino-nano 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}"
.PHONY: arch_clean arch_help arch_info monitor program size