Makefile
author Tero Marttila <terom@paivola.fi>
Wed, 02 Apr 2014 19:10:05 +0300
changeset 47 7f930a94ee1e
parent 45 7c684d241675
child 48 50dc2f4d90fd
permissions -rw-r--r--
bravely step into the modern world of C-programming, using avr-gcc for a hello world...
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
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
     5
all: $(PROG).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
     6
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
     7
## 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
     8
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
     9
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
    10
# 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
    11
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
    12
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
CC = avr-gcc
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
CFLAGS = -g -mmcu=$(MCU) -DF_CPU=$(CPU)UL -Os
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
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
%.elf: %.c
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
	$(CC) $(CFLAGS) -o $@ $+
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
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
    19
%.hex: %.elf
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
    20
	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
    21
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
    22
.PRECIOUS: %.elf
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
    23
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
    24
## Assembler
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
AS = avra
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
ASFLAGS = 
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
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
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
    29
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
    30
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
    31
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
    32
%.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
    33
	$(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
    34
	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
    35
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
    36
# 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
    37
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
    38
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
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
    40
	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
    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
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
## 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
    44
# Arduino Duemilanove
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
AD_PART = m328p
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
AD_PROG = arduino
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
AD_BAUD = 57600
43
a0a003083d4c use /dev/arduino for avrdude
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    48
AD_PORT = /dev/arduino
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
AD = avrdude
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
ADFLAGS = -p $(AD_PART) -c $(AD_PROG) -b $(AD_BAUD) -P $(AD_PORT)
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
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
    53
upload: $(PROG).hex
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
    54
	$(AD) $(ADFLAGS) -U flash:w:$<
5
7feeaeb473b5 Makefile
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
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
    56
## Console
10
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    57
SERIAL_BAUD = 9600
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    58
SERIAL_FLOW = n
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    59
SERIAL_PARITY = n
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    60
SERIAL_BITS = 8
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    61
SERIAL_PORT = $(AD_PORT)
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    62
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    63
SERIAL_TERM = picocom
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    64
SERIAL_FLAGS = -b $(SERIAL_BAUD) -f $(SERIAL_FLOW) -p $(SERIAL_PARITY) -d $(SERIAL_BITS)
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    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
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    67
	$(SERIAL_TERM) $(SERIAL_FLAGS) $(SERIAL_PORT)
faca61cf204c add a 'make chat' util
Tero Marttila <terom@fixme.fi>
parents: 9
diff changeset
    68