1-Wire tester, shows ROM code and temperature on an LCD screen

Makefile 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #############################################
  2. # CPU type
  3. MCU = atmega328p
  4. # CPU frequency [Hz]
  5. F_CPU = 16000000
  6. # Fuses (refer to datasheet)
  7. LFUSE = 0xFF
  8. HFUSE = 0xDE
  9. EFUSE = 0x05
  10. # AVRDUDE settings
  11. PROG_BAUD = 57600
  12. PROG_DEV = /dev/ttyUSB0
  13. PROG_TYPE = arduino
  14. # Build the final AVRDUDE arguments
  15. PROG_ARGS = -c $(PROG_TYPE) -p $(MCU) -b $(PROG_BAUD) -P $(PROG_DEV)
  16. #############################################
  17. # Main file
  18. BINARY = main
  19. # Obj files to be built <- add .o for any .c files you add!
  20. OBJS = $(BINARY).o
  21. OBJS += lib/usart.o
  22. OBJS += lib/iopins.o
  23. OBJS += lib/spi.o
  24. OBJS += lib/adc.o
  25. OBJS += lcd.o
  26. OBJS += onewire.o
  27. # Dirs with header files
  28. INCL_DIRS = . lib/
  29. # Pre-defined macros
  30. DEFS = -DF_CPU=$(F_CPU)UL
  31. #############################################
  32. # C flags
  33. CFLAGS = -std=gnu99 -mmcu=$(MCU) $(DEFS) $(INCL_DIRS:%=-I%)
  34. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffreestanding
  35. CFLAGS += -Wall -Wno-main -Wno-strict-prototypes -Wno-comment
  36. CFLAGS += -g2 -Wextra -Wfatal-errors -Wno-unused-but-set-variable
  37. CFLAGS += -ffunction-sections -fdata-sections -Os
  38. LDFLAGS = -Wl,--gc-sections -Wl,--relax -lm
  39. #LD_FLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf
  40. #LD_FLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf
  41. #############################################
  42. ## Defined programs / locations
  43. CC = avr-gcc
  44. OBJCOPY = avr-objcopy
  45. OBJDUMP = avr-objdump
  46. AVRSIZE = avr-size
  47. AVRDUDE = avrdude
  48. JUNK = *.o *.d *.elf *.bin *.hex *.srec *.list *.lst *.map *.dis *.disasm *.eep *.eeprom *.lss
  49. .SUFFIXES: .elf .bin .hex .lst .map .eeprom .pre
  50. .SECONDEXPANSION:
  51. .SECONDARY:
  52. .PHONY: all elf bin hex lst pre ee eeprom dis size clean flash flashe shell fuses show_fuses set_default_fuses
  53. all: hex size
  54. elf: $(BINARY).elf
  55. bin: $(BINARY).bin
  56. hex: $(BINARY).hex
  57. lst: $(BINARY).lst
  58. pre: $(BINARY).pre
  59. ee: $(BINARY).eeprom
  60. eeprom: $(BINARY).eeprom
  61. dis: lst
  62. # Show how big the resulting program is
  63. size: elf
  64. $(AVRSIZE) -C --mcu=$(MCU) $(BINARY).elf
  65. # --- Magic build targets ----------------
  66. %.hex: %.elf
  67. $(OBJCOPY) -R .eeprom -O ihex $< $@
  68. %.elf %.map: $(OBJS)
  69. $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(*).elf
  70. %.pre: %.c
  71. $(CC) $(CFLAGS) -E $(*).c --output $@
  72. %.eeprom: %.elf
  73. $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
  74. %.lst: %.elf
  75. $(Q)$(OBJDUMP) -S $(*).elf > $(*).lst
  76. %.o: %.c
  77. $(CC) $(CFLAGS) -o $(*).o -c $(*).c
  78. %.o: %.s
  79. $(CC) $(CFLAGS) -o $(*).o -c $(*).s
  80. # Clean all produced trash
  81. clean:
  82. rm -f $(JUNK)
  83. cd lib && rm -f $(JUNK)
  84. ## === avrdude ===
  85. flash: $(BINARY).hex
  86. $(AVRDUDE) $(PROG_ARGS) -U flash:w:$<
  87. flashe: $(BINARY).eeprom
  88. $(AVRDUDE) $(PROG_ARGS) -U eeprom:w:$<
  89. shell:
  90. $(AVRDUDE) $(PROG_ARGS) -nt
  91. # === fuses ===
  92. # this may not work with the arduino programmer, I haven't tried.
  93. FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
  94. fuses:
  95. $(AVRDUDE) $(PROG_ARGS) $(FUSE_STRING)
  96. show_fuses:
  97. $(AVRDUDE) $(PROG_ARGS) -nv