author | Tero Marttila <terom@paivola.fi> |
Thu, 03 Apr 2014 18:54:50 +0300 | |
changeset 50 | e4ac5a591dcd |
parent 48 | 50dc2f4d90fd |
child 51 | ec6271f0637b |
permissions | -rw-r--r-- |
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
1 |
PROG = hello |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
2 |
# console |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
3 |
# dmx |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
4 |
|
50 | 5 |
HEX = build/src/$(PROG).hex |
6 |
||
7 |
all: $(HEX) |
|
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
8 |
|
48 | 9 |
build: |
50 | 10 |
mkdir -p build/src |
48 | 11 |
|
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
12 |
## Compiler |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
13 |
MCU = atmega328p |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
14 |
|
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
15 |
# CPU clock frequency |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
16 |
CPU = 16000000 |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
17 |
|
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
18 |
CC = avr-gcc |
48 | 19 |
CPPFLAGS = -DF_CPU=$(CPU)UL |
20 |
CFLAGS = -g -mmcu=$(MCU) -Os |
|
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
21 |
|
50 | 22 |
build/%.elf: %.c |
48 | 23 |
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $*.c |
24 |
$(CC) -MM $(CPPFLAGS) -MT $@ -MF build/$*.d $*.c |
|
25 |
||
26 |
# existing .d files for rebuilding existing .o's |
|
27 |
-include $(wildcard build/*.d) |
|
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
28 |
|
50 | 29 |
build/%.hex: build/%.elf |
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
30 |
avr-objcopy -O ihex -R .eeprom $< $@ |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
31 |
|
50 | 32 |
.PRECIOUS: build/%.elf |
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
33 |
|
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
34 |
## Assembler |
5 | 35 |
AS = avra |
36 |
ASFLAGS = |
|
37 |
||
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
38 |
matrix.hex: spi.inc matrix.inc timer.inc delay.inc macros.inc font.inc font.def |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
39 |
led7seg.hex: spi.inc led7seg.inc adc.inc timer.inc delay.inc macros.inc |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
40 |
timer.hex: timer.inc macros.inc |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
41 |
|
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
42 |
%.hex: %.s |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
43 |
$(AS) $(ASFLAGS) $< |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
44 |
mv $<.hex $@ |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
45 |
|
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
46 |
# fonts |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
47 |
font.inc: font.def |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
48 |
|
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
49 |
font.def: font.txt font-compile.py |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
50 |
python font-compile.py $< $@ > /dev/null |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
51 |
|
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
52 |
|
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
53 |
## Flashing |
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
54 |
# Arduino Duemilanove |
5 | 55 |
AD_PART = m328p |
56 |
AD_PROG = arduino |
|
57 |
AD_BAUD = 57600 |
|
43 | 58 |
AD_PORT = /dev/arduino |
5 | 59 |
|
60 |
AD = avrdude |
|
61 |
ADFLAGS = -p $(AD_PART) -c $(AD_PROG) -b $(AD_BAUD) -P $(AD_PORT) |
|
62 |
||
50 | 63 |
upload: $(HEX) |
17
a7c668003a19
split led7seg.s into .inc modules, and update Makefile to use .s -> .hex, and above .inc's for led7seg
Tero Marttila <terom@fixme.fi>
parents:
10
diff
changeset
|
64 |
$(AD) $(ADFLAGS) -U flash:w:$< |
5 | 65 |
|
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
66 |
## Console |
10 | 67 |
SERIAL_BAUD = 9600 |
68 |
SERIAL_FLOW = n |
|
69 |
SERIAL_PARITY = n |
|
70 |
SERIAL_BITS = 8 |
|
71 |
SERIAL_PORT = $(AD_PORT) |
|
72 |
||
73 |
SERIAL_TERM = picocom |
|
74 |
SERIAL_FLAGS = -b $(SERIAL_BAUD) -f $(SERIAL_FLOW) -p $(SERIAL_PARITY) -d $(SERIAL_BITS) |
|
75 |
||
47
7f930a94ee1e
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
Tero Marttila <terom@paivola.fi>
parents:
45
diff
changeset
|
76 |
console: |
10 | 77 |
$(SERIAL_TERM) $(SERIAL_FLAGS) $(SERIAL_PORT) |
78 |