Makefile 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. TTY = /dev/tty.PL2303-00002126
  2. DEVICE = atmega644
  3. F_CPU = 20000000 # in Hz
  4. TARGET = main
  5. AVRDUDE = avrdude -c usbasp -p $(DEVICE)
  6. SIZE = avr-size
  7. CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
  8. 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
  9. COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
  10. ##############################################################################
  11. # Fuse values for particular devices
  12. ##############################################################################
  13. # http://www.engbedded.com/fusecalc/
  14. FUSE_L = 0xf7
  15. FUSE_H = 0xda
  16. # symbolic targets:
  17. help:
  18. @echo "This Makefile has no default rule. Use one of the following:"
  19. @echo "make hex ....... to build main.hex"
  20. @echo "make program ... to flash fuses and firmware"
  21. @echo "make fuse ...... to flash the fuses"
  22. @echo "make flash ..... to flash the firmware (use this on metaboard)"
  23. @echo "make clean ..... to delete objects and hex file"
  24. all: hex
  25. hex: main.hex
  26. @echo "==============================="
  27. @echo "$(TARGET) compiled for: $(DEVICE)"
  28. @echo -n "size is: "
  29. @$(SIZE) -A $(TARGET).hex | grep "\.sec1" | tr -s " " | cut -d" " -f2
  30. @echo "==============================="
  31. program: flash fuse
  32. # rule for programming fuse bits:
  33. fuse:
  34. @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \
  35. { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; }
  36. $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m
  37. # rule for uploading firmware:
  38. flash: main.hex
  39. $(AVRDUDE) -U flash:w:main.hex:i
  40. # rule for deleting dependent files (those which can be built by Make):
  41. clean:
  42. 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
  43. # Generic rule for compiling C files:
  44. .c.o:
  45. $(COMPILE) -c $< -o $@
  46. # Generic rule for assembling Assembler source files:
  47. .S.o:
  48. $(COMPILE) -x assembler-with-cpp -c $< -o $@
  49. # "-x assembler-with-cpp" should not be necessary since this is the default
  50. # file type for the .S (with capital S) extension. However, upper case
  51. # characters are not always preserved on Windows. To ensure WinAVR
  52. # compatibility define the file type manually.
  53. # Generic rule for compiling C to assembler, used for debugging only.
  54. .c.s:
  55. $(COMPILE) -S $< -o $@
  56. # file targets:
  57. # Since we don't want to ship the driver multipe times, we copy it into this project:
  58. usbdrv:
  59. cp -r ../../../usbdrv .
  60. main.elf: usbdrv $(OBJECTS) # usbdrv dependency only needed because we copy it
  61. $(COMPILE) -o main.elf $(OBJECTS) -Wl,-u,vfprintf -lprintf_flt
  62. main.hex: main.elf
  63. rm -f main.hex main.eep.hex
  64. avr-objcopy -j .text -j .data -O ihex main.elf main.hex
  65. avr-size main.hex
  66. # debugging targets:
  67. disasm: main.elf
  68. avr-objdump -d main.elf
  69. cpp:
  70. $(COMPILE) -E main.c