Subversion Repositories group.electronics

Rev

Rev 60 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 60 Rev 94
Line 1... Line 1...
1
# WinAVR cross-compiler toolchain is used here
1
DEVICE=atmega168
-
 
2
DEV_CODE=16384
2
CC = avr-gcc
3
DEV_DATA=1024
3
OBJCOPY = avr-objcopy
4
F_CPU=20000000
-
 
5
HID_SIZE=81
4
DUDE = avrdude
6
H_FUSE=0xdf
-
 
7
L_FUSE=0xff
5
 
8
 
6
# If you are not using ATtiny2313 and the USBtiny programmer, 
-
 
7
# update the lines below to match your configuration
-
 
8
CFLAGS = -Wall -Os -Iusbdrv -I. -mmcu=atmega168a
9
HD_FUSE=0xdf
9
OBJFLAGS = -j .text -j .data -O ihex
10
LD_FUSE=0x62
-
 
11
 
10
DUDEFLAGS = -p atmega168 -P usb -c avrispmkii -v
12
AVRDUDE = avrdude -c avrispmkii -P usb -p $(DEVICE)
-
 
13
 
-
 
14
COMPILE = avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -DHID_SIZE=$(HID_SIZE) -DDEBUG_LEVEL=0
11
 
15
 
12
# Object files for the firmware (usbdrv/oddebug.o not strictly needed I think)
-
 
13
#OBJECTS = usbdrv/usbdrv.o usbdrv/oddebug.o usbdrv/usbdrvasm.o main.o
-
 
14
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o main.o twi.o wire.o util.o lcd.o
16
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o main.o twi.o wire.o util.o lcd.o
15
 
17
 
-
 
18
# symbolic targets:
-
 
19
all:	main.hex
-
 
20
 
-
 
21
.c.o:
-
 
22
	$(COMPILE) -c $< -o $@
-
 
23
 
-
 
24
.S.o:
-
 
25
	$(COMPILE) -x assembler-with-cpp -c $< -o $@
-
 
26
 
-
 
27
.c.s:
-
 
28
	$(COMPILE) -S $< -o $@
-
 
29
 
-
 
30
flash:	all
-
 
31
	$(AVRDUDE) -U flash:w:main.hex:i
-
 
32
 
-
 
33
 
-
 
34
fuse:
-
 
35
	$(AVRDUDE) -U hfuse:w:$(H_FUSE):m -U lfuse:w:$(L_FUSE):m
-
 
36
 
-
 
37
fusedef:
-
 
38
	$(AVRDUDE) -U hfuse:w:$(HD_FUSE):m -U lfuse:w:$(LD_FUSE):m
-
 
39
 
-
 
40
readcal:
-
 
41
	$(AVRDUDE) -U calibration:r:/dev/stdout:i | head -1
-
 
42
 
-
 
43
 
-
 
44
clean:
-
 
45
	rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.bin *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s usbtest
-
 
46
 
-
 
47
# file targets:
-
 
48
main.bin:	$(OBJECTS)
-
 
49
	$(COMPILE) -o main.bin $(OBJECTS)
-
 
50
 
-
 
51
main.hex:	main.bin
-
 
52
	rm -f main.hex main.eep.hex
-
 
53
	avr-objcopy -j .text -j .data -O ihex main.bin main.hex
-
 
54
	./checksize main.bin $(DEV_CODE) $(DEV_DATA)
-
 
55
# do the checksize script as our last action to allow successful compilation
-
 
56
# on Windows with WinAVR where the Unix commands will fail.
-
 
57
 
-
 
58
disasm:	main.bin
-
 
59
	avr-objdump -d main.bin
-
 
60
 
-
 
61
cpp:
-
 
62
	$(COMPILE) -E main.c
-
 
63
 
16
# Command-line client
64
# Command-line client
17
CMDLINE = usbtest
65
CMDLINE = usbtest
18
 
66
 
19
# By default, build the firmware and command-line client, but do not flash
-
 
20
#all: main.hex $(CMDLINE)
-
 
21
all: main.hex 
-
 
22
 
-
 
23
# With this, you can flash the firmware by just typing "make flash" on command-line
-
 
24
flash: main.hex
-
 
25
	$(DUDE) $(DUDEFLAGS) -U flash:w:$<
-
 
26
 
-
 
27
# One-liner to compile the command-line client from usbtest.c
67
# One-liner to compile the command-line client from usbtest.c
28
$(CMDLINE): usbtest.c
68
$(CMDLINE): usbtest.c
29
	gcc -I ./libusb/include -L ./libusb/lib/gcc -O -Wall usbtest.c -o usbtest -lusb
69
	gcc -I ./libusb/include -L ./libusb/lib/gcc -O -Wall usbtest.c -o usbtest -lusb
30
 
-
 
31
# Housekeeping if you want it
-
 
32
clean:
-
 
33
	$(RM) *.o *.hex *.elf usbdrv/*.o usbtest
-
 
34
 
-
 
35
# From .elf file to .hex
-
 
36
%.hex: %.elf
-
 
37
	$(OBJCOPY) $(OBJFLAGS) $< $@
-
 
38
 
-
 
39
# Main.elf requires additional objects to the firmware, not just main.o
-
 
40
main.elf: $(OBJECTS)
-
 
41
	$(CC) $(CFLAGS) $(OBJECTS) -o $@
-
 
42
 
-
 
43
# Without this dependance, .o files will not be recompiled if you change 
-
 
44
# the config! I spent a few hours debugging because of this...
-
 
45
$(OBJECTS): usbconfig.h hiddesc.h twi.h wire.h lcd.h util.h
-
 
46
 
-
 
47
# From C source to .o object file
-
 
48
%.o: %.c	
-
 
49
	$(CC) $(CFLAGS) -c $< -o $@
-
 
50
 
-
 
51
# From assembler source to .o object file
-
 
52
%.o: %.S
-
 
53
	$(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@
-