annotate Makefile.avr @ 14:d8002c716678

- Actually wait after reading like the spec says. - Add debug item to show a device was found in the search. - Re-enable test for broken bus.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 08 Feb 2012 10:35:13 +1030
parents 4e10d1eef9a5
children bbe75f183cf9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
1 #
9
5f21a1c8ca06 Remove $Id$ and add a brief comment.
Daniel O'Connor <darius@dons.net.au>
parents: 2
diff changeset
2 # Helper makefile to build AVR sources
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
3 #
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
4
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
5 .SUFFIXES: .hex .out .c .o .elf .dmp .s .fuse
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
6
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
7 # Otherwise we get -march=foo
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
8 NO_CPU_CFLAGS=
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
9 _CPUCFLAGS=
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
10
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
11 # Programs
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
12 AS=avr-as
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
13 CC=avr-gcc
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
14 OBJCOPY=avr-objcopy
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
15 OBJDUMP=avr-objdump
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
16 SED=sed
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
17 TAIL=tail
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
18
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
19 # Tell as to generate listings
1
f5022e20d550 Fixup so .lst files end up in the project directory not the library one.
darius@Inchoate
parents: 0
diff changeset
20 CPPFLAGS+=-Wa,-adhlmsn=${<:T:S/.c/.lst/}
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
21
2
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
22 MCU?=notset
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
23 CFLAGS+=-mmcu=${MCU}
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
24
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
25 LDFLAGS+=-Wl,-Map=${PROG}.map,--cref
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
26 LDFLAGS+=${LDADD}
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
27
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
28 RM=rm -f
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
29
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
30 PROGRAMMER=avrdude
2
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
31 PROGTYPE?=alf
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
32
2
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
33 # Need the -B 1 or it is very slow. For slow clocks (eg factory fused) -B 10 works
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
34 PROGOPTS+=-B 10
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
35
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
36 .if defined(WITH_FUSES)
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
37 FUSEFILE=${PROG}.fuse
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
38 PROGOPTS+=`cat ${PROG}.fuse`
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
39 .elf.fuse:
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
40 ${OBJDUMP} -s -j .fuse ${.IMPSRC} | ${TAIL} -1 | ${SED} -nEe 's, [^ ]+ (..)(..)(..).*,-Ulfuse:w:0x\1:m -Uhfuse:w:0x\2:m -Uefuse:w:0x\3:m,p' >${.TARGET}
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
41 .else
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
42 FUSEFILE=
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
43 .endif
2
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
44
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
45 .if ${PROGTYPE} != "dragon_isp" && ${PROGTYPE} != "dragon_jtag"
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
46 PROGEXITS?=vcc,noreset
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
47 .endif
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
48
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
49 .if defined(PROGEXITS) && ${PROGEXITS} != ""
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
50 _PROGEXITS=-E ${PROGEXITS}
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
51 .endif
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
52 .if defined(PROGPORT) && ${PROGPORT} != ""
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
53 _PROGPORT=-P ${PROGPORT}
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
54 .endif
43d3b2bef999 Make the programmer code smarter, default to Dragon.
darius@Inchoate
parents: 1
diff changeset
55
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
56 PROGOPTS+=-p ${PART} -c ${PROGTYPE} ${_PROGPORT} ${_PROGEXITS} -q -U flash:w:${PROG}.hex ${PROGEXTRA}
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
57
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
58 .if !defined(SRCS)
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
59 SRCS= ${PROG}.c
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
60 .endif
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
61
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
62 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
63
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
64 all: ${PROG}.hex ${PROG}.dmp
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
65
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
66 .c.o:
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
67 ${CC} ${CFLAGS} ${CPPFLAGS} -c ${.IMPSRC} -o ${.PREFIX}.o
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
68
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
69 ${PROG}.elf: ${OBJS}
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
70 ${CC} ${CFLAGS} ${LDFLAGS} -g ${OBJS} -o ${PROG}.elf ${LDADD}
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
71
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
72 .elf.hex:
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
73 ${OBJCOPY} -j .text -j .data -j .bss -j .noinit -O ihex $> $@
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
74
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
75 .elf.dmp:
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
76 ${OBJDUMP} -S ${.IMPSRC} > ${.PREFIX}.dmp
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
77
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
78 clean:
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
79 ${RM} ${PROG}.hex ${PROG}.out ${PROG}.elf ${PROG}.map ${OBJS} ${OBJS:S/.o/.lst/} ${PROG}.dmp ${PROG}.fuse
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
80
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
81 prog: ${PROG}.elf ${FUSEFILE}
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
82 ${PROGRAMMER} ${PROGOPTS}
0
3879f487b661 Initial commit of routines I copy and paste.
darius@Inchoate
parents:
diff changeset
83
12
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
84 #########################
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
85 #;;; Local Variables: ***
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
86 #;;; mode:makefile ***
4e10d1eef9a5 Re-jig programming and add WITH_FUSES= to set fuses automatically if
Daniel O'Connor <darius@dons.net.au>
parents: 9
diff changeset
87 #;;; End: ***