AVR driver for a group of 7-seg displays (with 70hc4094), controlled by UART.

Makefile 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. ## === CPU settings ===
  2. # CPU type
  3. MCU = atmega328p
  4. # CPU frequency
  5. F_CPU = 16000000
  6. # Fuses
  7. LFUSE = 0xFF
  8. HFUSE = 0xDE
  9. EFUSE = 0x05
  10. ## === Source files ===
  11. # Main C file
  12. MAIN = main.c
  13. # Extra C files in this folder
  14. LOCAL_SOURCE =
  15. # Library directory (with C files)
  16. EXTRA_SOURCE_DIR = lib/
  17. # C files in the library directory
  18. EXTRA_SOURCE_FILES = uart.c iopins.c stream.c adc.c dht11.c sonar.c onewire.c
  19. # Files that need config file - uncomment when needed, but also add the configs!
  20. # EXTRA_SOURCE_FILES += sipo_pwm.c
  21. # EXTRA_SOURCE_FILES += lcd.c
  22. # EXTRA_SOURCE_FILES += color.c wsrgb.c
  23. # EXTRA_SOURCE_FILES += debouce.c
  24. ## === Programmer ===
  25. PROGRAMMER_TYPE = arduino
  26. PROGRAMMER_ARGS = -b 57600 -P /dev/ttyUSB0
  27. ## === C flags ===
  28. CFLAGS = -std=gnu99 -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -I. -I$(EXTRA_SOURCE_DIR)
  29. CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
  30. CFLAGS += -Wall -Wno-main -Wno-strict-prototypes -Wno-comment
  31. CFLAGS += -g2 -Wextra -Wfatal-errors -Wno-unused-but-set-variable
  32. CFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--relax
  33. # CFLAGS += -lm ## Math
  34. # CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf
  35. # CFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf
  36. CFLAGS_BUILD = $(CFLAGS) -Os
  37. # ---------------------------------------------------------------------------
  38. ## Defined programs / locations
  39. CC = avr-gcc
  40. OBJCOPY = avr-objcopy
  41. OBJDUMP = avr-objdump
  42. AVRSIZE = avr-size
  43. AVRDUDE = avrdude
  44. ## === File lists ===
  45. TARGET = $(strip $(basename $(MAIN)))
  46. SRC1 = $(TARGET).c
  47. SRC = $(SRC1)
  48. EXTRA_SOURCE = $(addprefix $(EXTRA_SOURCE_DIR), $(EXTRA_SOURCE_FILES))
  49. SRC += $(EXTRA_SOURCE)
  50. SRC += $(LOCAL_SOURCE)
  51. HEADERS = $(SRC:.c=.h)
  52. OBJ = $(SRC:.c=.o)
  53. ## === File generation ===
  54. all: $(TARGET).hex size
  55. pre: $(TARGET).pre
  56. %.hex: %.elf
  57. $(OBJCOPY) -R .eeprom -O ihex $< $@
  58. %.elf: $(SRC)
  59. $(CC) $(CFLAGS_BUILD) $(SRC) --output $@
  60. %.pre: $(SRC1)
  61. $(CC) $(CFLAGS) -E $(SRC1) --output $@
  62. %.eeprom: %.elf
  63. $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
  64. %.lst: %.elf
  65. $(OBJDUMP) -S $< > $@
  66. # Show debug info
  67. debug:
  68. @echo
  69. @echo "Source files:" $(SRC)
  70. @echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD)
  71. @echo
  72. # Disassemble the ELF
  73. disassemble: $(TARGET).lst
  74. dis: disassemble
  75. lst: disassemble
  76. # Make eeprom file
  77. eeprom: $(TARGET).eeprom
  78. # Show how big the resulting program is
  79. size: $(TARGET).elf
  80. $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf
  81. # Clean all produced trash
  82. clean:
  83. rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \
  84. $(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \
  85. $(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \
  86. $(TARGET).eeprom
  87. # Clean all trash
  88. purge:
  89. rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~
  90. ## === avrdude ===
  91. flash: $(TARGET).hex
  92. $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$<
  93. flashe: $(TARGET).eeprom
  94. $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$<
  95. shell:
  96. $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt
  97. fser: all flash ser
  98. ser:
  99. gtkterm -p /dev/ttyUSB0
  100. # === fuses ===
  101. FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
  102. fuses:
  103. $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \
  104. $(PROGRAMMER_ARGS) $(FUSE_STRING)
  105. show_fuses:
  106. $(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv
  107. set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
  108. set_default_fuses: fuses