| 1 | # $Id: Makefile,v 1.3 2010/06/27 22:19:15 simimeie Exp $ |
| 2 | # Makefile for HaWo Moodlight |
| 3 | |
| 4 | CC = avr-gcc |
| 5 | OBJDUMP = avr-objdump |
| 6 | OBJCOPY = avr-objcopy |
| 7 | #AVRDUDE = avrdude |
| 8 | AVRDUDE = /opt/avrdude-5.10/bin/avrdude |
| 9 | INCDIR = . |
| 10 | # There are a few additional defines that en- or disable certain features, |
| 11 | # mainly to save space in case you are running out of flash. |
| 12 | # You can add them here. |
| 13 | # -DJOKECMDS Just some joke commands |
| 14 | ADDDEFS = -DJOKECMDS |
| 15 | |
| 16 | # target mcu (atmega328p or atmega168p) |
| 17 | MCU = atmega328p |
| 18 | # Since avrdude is generally crappy software (I liked uisp a lot better, too |
| 19 | # bad the project is dead :-/), it cannot use the MCU name everybody else |
| 20 | # uses, it has to invent its own name for it. So this defines the same |
| 21 | # MCU as above, but with the name avrdude understands. |
| 22 | AVRDMCU = m328p |
| 23 | |
| 24 | # Some more settings |
| 25 | # Clock Frequency of the AVR. Needed for various calculations. |
| 26 | CPUFREQ = 8000000UL |
| 27 | # desired baudrate of serial debug console |
| 28 | BAUDRATE = 9600UL |
| 29 | |
| 30 | SRCS = console.c ledpwm.c ircontrol.c timers.c main.c |
| 31 | PROG = moodlight |
| 32 | |
| 33 | # compiler flags |
| 34 | CFLAGS = -g -Os -Wall -Wno-pointer-sign -mmcu=$(MCU) $(ADDDEFS) |
| 35 | |
| 36 | # linker flags |
| 37 | LDFLAGS = -g -mmcu=$(MCU) -Wl,-Map,$(PROG).map |
| 38 | |
| 39 | CFLAGS += -DCPUFREQ=$(CPUFREQ) -DF_CPU=$(CPUFREQ) -DBAUDRATE=$(BAUDRATE) |
| 40 | |
| 41 | OBJS = $(SRCS:.c=.o) |
| 42 | |
| 43 | all: compile dump text eeprom |
| 44 | @echo -n "Compiled size: " && ls -l ${PROG}.bin |
| 45 | |
| 46 | compile: $(OBJS) |
| 47 | $(CC) $(LDFLAGS) -o $(PROG).elf $(OBJS) |
| 48 | |
| 49 | dump: compile |
| 50 | $(OBJDUMP) -h -S $(PROG).elf > $(PROG).lst |
| 51 | |
| 52 | %o : %c |
| 53 | $(CC) $(CFLAGS) -I$(INCDIR) -c $< -o $@ |
| 54 | |
| 55 | # Create the flash contents |
| 56 | text: compile |
| 57 | $(OBJCOPY) -j .text -j .data -O ihex $(PROG).elf $(PROG).hex |
| 58 | $(OBJCOPY) -j .text -j .data -O srec $(PROG).elf $(PROG).srec |
| 59 | $(OBJCOPY) -j .text -j .data -O binary $(PROG).elf $(PROG).bin |
| 60 | |
| 61 | # Rules for building the .eeprom rom images |
| 62 | eeprom: compile |
| 63 | $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $(PROG).elf $(PROG)_eeprom.hex |
| 64 | $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $(PROG).elf $(PROG)_eeprom.srec |
| 65 | $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $(PROG).elf $(PROG)_eeprom.bin |
| 66 | |
| 67 | clean: |
| 68 | rm -f $(PROG) *~ *.elf *.rom *.bin *.eep *.o *.lst *.map *.srec *.hex |
| 69 | |
| 70 | upload: uploadflash uploadeeprom |
| 71 | |
| 72 | uploadflash: |
| 73 | $(AVRDUDE) -c stk500v2 -p $(AVRDMCU) -P /dev/ttyS0 -U flash:w:$(PROG).srec:s |
| 74 | |
| 75 | uploadeeprom: |
| 76 | $(AVRDUDE) -c stk500v2 -p $(AVRDMCU) -P /dev/ttyS0 -U eeprom:w:$(PROG)_eeprom.srec:s |