Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Makefile for Atmel AVR programs and associated utilities
- ## Copyleft (!C) Mark A. Post, 2007
- # Target environment
- FREQUENCY=14745600
- #FREQUENCY=1843200
- #FREQUENCY=8000000
- #FREQUENCY=1000000
- BAUDRATE=115200
- #BAUDRATE=9600
- MCU=atmega644p
- #MCU=atmega1281
- #MCU=atmega168
- #MCU=attiny461
- #MCU=attiny2313
- PROG_METHOD=avrispmkII
- #PROG_METHOD=stk500v2
- PORT=usb
- #PORT=/dev/ttyUSB1
- # Development environment
- CC=avr-gcc
- DEVCC=gcc
- OBJCOPY=avr-objcopy
- STRIP=avr-strip
- PROG=avrdude
- OBJDUMP=avr-objdump
- AR=avr-ar
- # Build options
- CDEFINES=-DF_CPU=$(FREQUENCY) -DBAUD=$(BAUDRATE)
- #for <4MHz MCU, OPTS=-B 4, reliable at -B 10 for USB
- ifeq ($(PORT),usb)
- OPTS=-B 10
- else
- OPTS=-B 2
- endif
- #for optimization: CFLAGS=-mmcu=$(MCU) -Wall -Os -mcall-prologues
- #WARNING: any optimization levels above -O0 may cause instability
- CFLAGS=-mmcu=$(MCU) -Wall $(CDEFINES) -O0 -Iyaml-0.1.4/include
- #for i686 and x86_64 in Gentoo Linux:
- LDFLAGS=-L. -lm -lc -lm -luavr -L/usr/i686-pc-linux-gnu/avr/lib -L/usr/x86_64-pc-linux-gnu/avr/lib
- # Libraries
- LIBS=libuavr.a
- LIBSRCS=\
- lib/general.c\
- lib/interrupt.c\
- lib/timer.c\
- lib/serial.c\
- lib/spi.c\
- lib/i2c.c\
- lib/adc.c\
- lib/eeprom.c\
- lib/motor.c\
- lib/terminal.c\
- $(NULL)
- LIBOBJS=$(LIBSRCS:.c=.o)
- YAML=libyaml.a
- YAMLSRCS=yaml-0.1.4/src/yaml_private.h \
- yaml-0.1.4/src/api.c\
- yaml-0.1.4/src/reader.c\
- yaml-0.1.4/src/scanner.c\
- yaml-0.1.4/src/parser.c\
- yaml-0.1.4/src/loader.c writer.c\
- yaml-0.1.4/src/emitter.c\
- yaml-0.1.4/src/dumper.c\
- $(NULL)
- YAMLOBJS=$(YAMLSRCS:.c=.o)
- # Rules
- %: %.hex
- %.o: %.c
- $(CC) -c $^ -o $@ $(CFLAGS)
- %.bin: %.o $(LIBS)
- $(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
- %.asm: %.bin
- $(OBJDUMP) -S -d $^ > $@
- %-stripped: %.bin
- $(STRIP) $^ -o $@
- %.srec: %-stripped
- $(OBJCOPY) -O srec $^ $@
- %.hex: %-stripped
- $(OBJCOPY) -O ihex $^ $@
- # Targets
- default: getd sendd
- getd: getd.c
- $(DEVCC) -o getd getd.c
- sendd: sendd.c
- $(DEVCC) -o sendd sendd.c
- libs: $(LIBS)
- libuavr.a: $(LIBOBJS)
- $(AR) rcs $@ $?
- libyaml.a: $(YAMLOBJS)
- $(AR) rcs $@ $?
- clean:
- rm -f *.srec *.o *.bin *.asm $(LIBOBJS) $(LIBS)
- erase:
- # $(UISP) -dprog=$(PROG_METHOD) -dpart=$(MCU) --segment=flash -dserial=$(PORT) -dspeed=115200 --erase
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -e
- program_%: %.srec
- # $(UISP) -dprog=$(PROG_METHOD) -dpart=$(MCU) --segment=flash -dserial=$(PORT) -dspeed=115200 --upload if=$^
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U flash:w:$^:s
- verify_%: %.srec
- # $(UISP) -dprog=$(PROG_METHOD) -dpart=$(MCU) --segment=flash -dserial=$(PORT) -dspeed=115200 --verify if=$^
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U flash:v:$^:s
- download_%: %.srec
- # $(UISP) -dprog=$(PROG_METHOD) -dpart=$(MCU) --segment=flash -dserial=$(PORT) -dspeed=115200 --download of=$^
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U flash:r:$^:s
- # Fuses:
- fuse-nojtag:
- #ATMega Fuses: turn off JTAG on hfuse
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U hfuse:w:0xD9:m
- fuse-intclk1:
- #ATMega Fuses: set to internal 8MHz/8 oscillator on lfuse
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0x62:m
- fuse-intclk8:
- #ATMega Fuses: set to internal 8MHz/1 oscillator on lfuse
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0xE2:m
- fuse-extclkd:
- #ATMega Fuses: set to external 8-16MHz/8 crystal oscillator on lfuse
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0x6E:m
- fuse-extclk1:
- #ATMega Fuses: set to external 1-8MHz/1 crystal oscillator on lfuse
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0xEC:m
- fuse-extclk8:
- #ATMega Fuses: set to external 8-16MHz/1 crystal oscillator on lfuse
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0xEE:m
- fuse-extclkfs:
- #ATMega Fuses: set to external full-swing crystal oscillator on lfuse
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0xF7:m
- fuse-extclkfsd:
- #ATMega Fuses: set to external full-swing crystal oscillator/8 on lfuse
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -U lfuse:w:0x77:m
- fuses: fuse-nojtag fuse-extclkfs
- status:
- #Verbose output to test connection and fuses
- $(PROG) -p $(MCU) -c $(PROG_METHOD) -P $(PORT) $(OPTS) -v
- printm:
- $(CC) -dM -E - < /dev/null
Advertisement
Add Comment
Please, Sign In to add comment