-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile.atmega
119 lines (97 loc) · 3.46 KB
/
Makefile.atmega
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
# Pulse & Bloom
# Author: Samuel Clay
# Date: 2014-04-27
# Copyright: (c) 2014
DEVICE = atmega328p
DEVICE_MCCU = atmega328p # See http://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html
PROGRAMMER ?= usbtiny
F_CPU = 16000000
# Ext Clock
FUSE_L = 0xFF
FUSE_H = 0xD9
# Int Clock
# FUSE_L = 0xE2
# FUSE_H = 0xD9
FUSE_E = 0x01
AVRDUDE_FUSE= avrdude -v -c $(PROGRAMMER) -p $(DEVICE) -P usb -F
AVRDUDE = $(AVRDUDE_FUSE) -B1
LIBS = -I./libs/arduino
LIBS += -I./libs/atmega328
LIBS += -I./libs/avr
LIBS += -I./libs/neopixel
LIBS += -I./libs/si114
LIBS += -I./libs/easing
LIBS += -I./libs
LIBS += -I./src
LIBS += -I.
CFLAGS = $(LIBS) \
-fno-exceptions -ffunction-sections -fdata-sections \
-Wl,--gc-sections
CPPFLAGS = -std=c++0x \
-felide-constructors
C_SRC := libs/arduino/wiring.o \
libs/arduino/wiring_analog.o \
libs/arduino/wiring_digital.o \
libs/arduino/wiring_pulse.o \
libs/arduino/wiring_shift.o \
libs/arduino/hooks.o
CPP_SRC := libs/arduino/main.o \
libs/arduino/HardwareSerial.o \
libs/arduino/Print.o \
libs/arduino/Tone.o \
libs/arduino/WMath.o \
libs/arduino/WString.o \
libs/neopixel/Adafruit_NeoPixel.o \
libs/si1143/si1143.o \
libs/easing/EasingBase.o \
libs/easing/QuadraticEase.o
SRC := src/pulse.o \
src/sensor.o \
src/smooth.o
OBJECTS = $(C_SRC:.c=.o) $(CPP_SRC:.cpp=.o) $(SRC:.cpp=.o)
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE_MCCU)
all: clean pulse.hex fuse program
# symbolic targets:
help:
@echo "Use one of the following:"
@echo "make program ... to flash fuses and firmware"
@echo "make fuse ...... to flash the fuses"
@echo "make flash ..... to flash the firmware (use this on metaboard)"
@echo "make hex ....... to build pulse.hex"
@echo "make clean ..... to delete objects and hex file"
hex: pulse.hex
# Add fuse to program once you're in production
program: flash
# rule for programming fuse bits:
fuse:
@[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \
{ echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; }
$(AVRDUDE_FUSE) -U lfuse:w:$(FUSE_L):m -U hfuse:w:$(FUSE_H):m -U efuse:w:$(FUSE_E):m
# rule for uploading firmware:
flash: pulse.hex
$(AVRDUDE) -U flash:w:build/pulse.hex:i
read:
$(AVRDUDE_FUSE) -U lfuse:r:lfuse.txt:h -U hfuse:r:hfuse.txt:h -U efuse:r:efuse.txt:h -U lock:r:lock.txt:h
# rule for deleting dependent files (those which can be built by Make):
clean:
rm -f build/* *.o **/*.o **/**/*.o *.d **/*.d **/**/*.d **/**/*.lst
# Generic rule for compiling C files:
.c.o:
$(COMPILE) -g -c $< -o $@
.cpp.o:
$(COMPILE) $(CPPFLAGS) -g -c $< -o $@
# Generic rule for compiling C to assembler, used for debugging only.
.c.s:
$(COMPILE) -S $< -o $@
core:
avr-ar rcs build/core.a $(C_SRC:.c=.o) $(CPP_SRC:.cpp=.o)
# file targets:
pulse.elf: $(OBJECTS) core
$(COMPILE) -o build/pulse.elf $(SRC:.cpp=.o) build/core.a -L. -lm
pulse.hex: pulse.elf
rm -f build/pulse.hex build/pulse.eep.hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 -O ihex build/pulse.elf build/pulse.hex
avr-objcopy -O ihex -R .eeprom build/pulse.elf build/pulse.hex
avr-size build/pulse.hex
disasm: pulse.elf
avr-objdump -d build/pulse.elf