Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # =====================================================================================
  2. #
  3. # ________ .__ __ ________ ____ ________
  4. # \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/
  5. # / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \
  6. # / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \
  7. # \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ /
  8. # \__> \/ \/ \/ \/ \/
  9. # www.optixx.org
  10. #
  11. #
  12. # Version: 1.0
  13. # Created: 07/21/2009 03:32:16 PM
  14. # Author: david@optixx.org
  15. # Based on: custom-class, a basic USB example
  16. # Author: Christian Starkjohann
  17. # =====================================================================================
  18. DEBUG = 1
  19. TTY = /dev/tty.PL2303-00002126
  20. DEVICE = atmega644
  21. F_CPU = 20000000 # in Hz
  22. TARGET = main
  23. AVRDUDE = avrdude -c usbasp -p $(DEVICE)
  24. SIZE = avr-size
  25. ifeq ($(DEBUG),1)
  26. LDFLAGS = -Wl,-u,vfprintf -lprintf_flt
  27. CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
  28. OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o
  29. else
  30. LDFLAGS = -Wl,-u
  31. CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO
  32. OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o
  33. endif
  34. COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
  35. ##############################################################################
  36. # Fuse values for particular devices
  37. ##############################################################################
  38. # http://www.engbedded.com/fusecalc/
  39. FUSE_L = 0xf7
  40. FUSE_H = 0xda
  41. all: hex
  42. help:
  43. @echo "This Makefile has no default rule. Use one of the following:"
  44. @echo "make hex ....... to build main.hex"
  45. @echo "make program ... to flash fuses and firmware"
  46. @echo "make fuse ...... to flash the fuses"
  47. @echo "make flash ..... to flash the firmware (use this on metaboard)"
  48. @echo "make clean ..... to delete objects and hex file"
  49. hex: main.hex
  50. @echo "==============================="
  51. @echo "$(TARGET) compiled for: $(DEVICE)"
  52. @echo -n "size is: "
  53. @$(SIZE) -A $(TARGET).hex | grep "\.sec1" | tr -s " " | cut -d" " -f2
  54. @echo "==============================="
  55. program: flash fuse
  56. # rule for programming fuse bits:
  57. fuse:
  58. @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \
  59. { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; }
  60. $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m
  61. flash: main.hex
  62. $(AVRDUDE) -U flash:w:main.hex:i
  63. .c.o:
  64. $(COMPILE) -c $< -o $@
  65. .S.o:
  66. $(COMPILE) -x assembler-with-cpp -c $< -o $@
  67. .c.s:
  68. $(COMPILE) -S $< -o $@
  69. usbdrv:
  70. cp -r ../../../usbdrv .
  71. main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it
  72. $(COMPILE) -o main.elf $(OBJECTS) $(LDFLAGS)
  73. main.hex: main.elf
  74. rm -f main.hex main.eep.hex
  75. avr-objcopy -j .text -j .data -O ihex main.elf main.hex
  76. avr-size main.hex
  77. disasm: main.elf
  78. avr-objdump -d main.elf
  79. cpp:
  80. $(COMPILE) -E main.c
  81. clean:
  82. rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s