Skip to content

Commit

Permalink
converted to git, reformatted code and made it compatible with recent…
Browse files Browse the repository at this point in the history
… versions of avr-gcc and avr-libc

Signed-off-by: Christian Kroll <[email protected]>
  • Loading branch information
tunix79 committed Dec 25, 2015
1 parent 105bb3c commit f064241
Show file tree
Hide file tree
Showing 3 changed files with 335 additions and 207 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.o
*.d
*.swp
image.bin
image_eeprom.bin
image_eeprom.hex
image_eeprom.srec
image.elf
image.hex
image.lst
image.map
image.srec
82 changes: 78 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,81 @@
MCU_TARGET=atmega8
DEFS = -DF_CPU=8000000 -DATMEGA8
# Default values
OBJ = main.o
OUT ?= image
MCU_TARGET ?= atmega8
MCU_CC ?= avr-gcc
OPTIMIZE ?= -Os
WARNINGS ?= -Wall
DEFS ?= -DF_CPU=16000000
CFLAGS += -MMD -g -std=c99 -mmcu=$(MCU_TARGET) $(OPTIMIZE) $(WARNINGS) $(DEFS)
ASFLAGS ?= -g $(DEFS)
LDFLAGS ?= -Wl,-Map,$(OUT).map

OBJ = main.o
# External Tools
OBJCOPY ?= avr-objcopy
OBJDUMP ?= avr-objdump
FLASH ?= avrdude -c usbasp -p $(MCU_TARGET) -U flash:w:image.hex

include ../../make/avr.mk
#############################################################################
# Rules
all: $(OUT).elf lst text eeprom

clean:
rm -rf $(OUT) *.o *.d *.lst *.map $(OUT).hex $(OUT)_eeprom.hex *.bin *.srec
rm -rf *.srec $(OUT).elf

flash: $(OUT).hex
$(FLASHCMD)

#############################################################################
# Building Rules
$(OUT).elf: $(OBJ)
$(MCU_CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)

%.o: %.c
$(MCU_CC) $(CFLAGS) -c $<

%.o: %.S
$(MCU_CC) -mmcu=$(MCU_TARGET) $(ASFLAGS) -c $<

lst: $(OUT).lst

%.lst: %.elf
$(OBJDUMP) -h -S $< > $@

# Rules for building the .text rom images
text: hex bin srec

hex: $(OUT).hex
bin: $(OUT).bin
srec: $(OUT).srec

%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@

%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@

%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@

# Rules for building the .eeprom rom images

eeprom: ehex ebin esrec

ehex: $(OUT)_eeprom.hex
ebin: $(OUT)_eeprom.bin
esrec: $(OUT)_eeprom.srec

%_eeprom.hex: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@

%_eeprom.srec: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O srec $< $@

%_eeprom.bin: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O binary $< $@

DEPS := $(wildcard *.d)
ifneq ($(DEPS),)
include $(DEPS)
endif
Loading

0 comments on commit f064241

Please sign in to comment.