-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
67 lines (45 loc) · 1.48 KB
/
Makefile
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
PROGRAM=example
SRC=example.c uart/uart.o ms5611/ms5611.c i2chw/twimaster.c
OBJ=$(SRC:.c=.o)
MCU=atmega328p
# AVRDUDE_MCU=$(MCU)
AVRDUDE_MCU=atmega328p
AVRDUDE_PROGRAMMER=arduino
CFLAGS=-Wall -Os -mmcu=$(MCU) -DUSE_LOGGING=1 -DF_CPU=16000000UL -std=gnu99
LDFLAGS=
AVRDUDE_FLAGS= -p$(AVRDUDE_MCU) -c $(AVRDUDE_PROGRAMMER) -P /dev/ttyUSB0 -b 57600
FORMAT=ihex
CC=avr-gcc
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
AVRDUDE=avrdude
all: $(PROGRAM).hex $(PROGRAM).eep
program: $(PROGRAM).hex $(PROGRAM).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(PROGRAM).hex:i -U eeprom:w:$(PROGRAM).eep:i
program_flash: $(PROGRAM).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) -U flash:w:$(PROGRAM).hex:i
program_eeprom: $(PROGRAM).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) eeprom:w:$(PROGRAM).eep:i
dump_eeprom:
$(AVRDUDE) $(AVRDUDE_FLAGS) -U eeprom:r:eeprom.raw:r
od -tx1 eeprom.raw
objdump: $(PROGRAM).elf
$(OBJDUMP) --disassemble $<
.PRECIOUS : $(OBJ) $(PROGRAM).elf
%.hex: %.elf
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
%.elf: $(OBJ)
$(CC) $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)
%.o: %.c Makefile
$(CC) -c $(CFLAGS) $< -o $@
%.s: %.c Makefile
$(CC) -S -c $(CFLAGS) $< -o $@
%.o: %.S
$(CC) -c $(CFLAGS) $< -o $@
clean:
rm -f $(PROGRAM).hex $(PROGRAM).eep $(PROGRAM).elf *.o *.s eeprom.raw \
uart/*.o i2chw/*.o ms5611/*.o
.PHONY: all clean dump_eeprom program program_flash program_eeprom objdump