firmware/Makefile

Fri, 12 May 2017 15:33:22 +0200

author
Malte Di Donato <mdd@neo-soft.org>
date
Fri, 12 May 2017 15:33:22 +0200
changeset 0
bdcf2c76d86e
permissions
-rw-r--r--

initial firmware working

0
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
1 # Name: Makefile
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
2 # Project: hid-data example
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
3 # Author: Christian Starkjohann
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
4 # Creation Date: 2008-04-07
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
5 # Tabsize: 4
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
6 # Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
7 # License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
8
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
9 DEVICE = attiny2313
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
10 F_CPU = 8000000 # in Hz
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
11 AVRDUDE = avrdude -c usbasp -p $(DEVICE) -B .5 -P USB -u
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
12
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
13 CFLAGS = -I. -DDEBUG_LEVEL=0
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
14 OBJECTS = main.o
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
15
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
16 COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
17
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
18 FUSE_H = 0x9f
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
19 FUSE_L = 0xe4
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
20
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
21 # symbolic targets:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
22 help:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
23 @echo "This Makefile has no default rule. Use one of the following:"
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
24 @echo "make hex ....... to build main.hex"
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
25 @echo "make program ... to flash fuses and firmware"
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
26 @echo "make fuse ...... to flash the fuses"
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
27 @echo "make flash ..... to flash the firmware (use this on metaboard)"
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
28 @echo "make clean ..... to delete objects and hex file"
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
29
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
30 hex: main.hex
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
31
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
32 program: flash fuse
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
33
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
34 # rule for programming fuse bits:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
35 fuse:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
36 @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
37 { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; }
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
38 $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
39
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
40 # rule for uploading firmware:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
41 flash: main.hex
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
42 $(AVRDUDE) -U flash:w:main.hex:i
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
43
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
44 # rule for deleting dependent files (those which can be built by Make):
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
45 clean:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
46 rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o main.s
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
47
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
48 # Generic rule for compiling C files:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
49 .c.o:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
50 $(COMPILE) -c $< -o $@
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
51
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
52 # Generic rule for assembling Assembler source files:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
53 .S.o:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
54 $(COMPILE) -x assembler-with-cpp -c $< -o $@
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
55 # "-x assembler-with-cpp" should not be necessary since this is the default
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
56 # file type for the .S (with capital S) extension. However, upper case
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
57 # characters are not always preserved on Windows. To ensure WinAVR
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
58 # compatibility define the file type manually.
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
59
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
60 # Generic rule for compiling C to assembler, used for debugging only.
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
61 .c.s:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
62 $(COMPILE) -S $< -o $@
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
63
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
64 # file targets:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
65
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
66 main.elf: $(OBJECTS) # usbdrv dependency only needed because we copy it
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
67 $(COMPILE) -o main.elf $(OBJECTS)
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
68
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
69 main.hex: main.elf
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
70 rm -f main.hex main.eep.hex
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
71 avr-objcopy -j .text -j .data -O ihex main.elf main.hex
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
72 avr-size main.hex
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
73
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
74 # debugging targets:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
75
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
76 disasm: main.elf
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
77 avr-objdump -d main.elf
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
78
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
79 cpp:
bdcf2c76d86e initial firmware working
Malte Di Donato <mdd@neo-soft.org>
parents:
diff changeset
80 $(COMPILE) -E main.c

mercurial