This repository has been archived by the owner on Jun 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile
145 lines (102 loc) · 3.06 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#### Project configuration options ####
# Name of target controller
MCU = atmega328p
# Project name
PROJECTNAME = fg100alt
# MCU Clock frequency
CLK_FREQ = 30000000UL
#CLK_FREQ = 20000000UL
# DAC step constant
DDS_STEP_CONSTANT = 5.0331648
#DDS_STEP_CONSTANT = 7.5497472
# Source files
SRC = config.c crc8.c lcd.c ui.c dds.c dds.S main.c
# Additional include paths
INCLUDES =
# Libraries to link in
LIBS =
# Optimization
# use s (size opt), 1, 2, 3 or 0 (off)
OPTIMIZE = 1
# AVR Dude programmer
AVRDUDE_PROGRAMMER = usbtiny
#### End project configuration ####
#### Firmware options configuration options ####
# When incrementing (and decrementing) the value under the cursor, if
# the value rolls over increment or decrement the adjacent value also.
ROLL_OVER_ADJACENT = 1
#### End firmware options configuration ####
#### Flags
DEFINES = -DF_CPU=$(CLK_FREQ) -DDDS_STEP_CONSTANT=$(DDS_STEP_CONSTANT) \
-DROLL_OVER_ADJACENT=$(ROLL_OVER_ADJACENT)
# Compiler
override CFLAGS = -I. $(INCLUDES) -g -O$(OPTIMIZE) -mmcu=$(MCU) $(DEFINES) \
-Wall -Werror -Wl,-section-start=.WaveBuffer=0x00800300 \
-pedantic -pedantic-errors -std=gnu99 \
-fpack-struct -fshort-enums -funsigned-char -funsigned-bitfields -ffunction-sections
# Assembler
override ASMFLAGS = -I. $(INCLUDES) -mmcu=$(MCU) $(DEFINES)
# Linker
override LDFLAGS = -Wl,-Map,$(TRG).map $(CFLAGS)
#### Executables
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AVRDUDE = avrdude
REMOVE = rm -f
#### Target Names
TRG = $(PROJECTNAME).out
DUMPTRG = $(PROJECTNAME).s
HEXROMTRG = $(PROJECTNAME).hex
HEXTRG = $(HEXROMTRG) $(PROJECTNAME).ee.hex
GDBINITFILE = gdbinit-$(PROJECTNAME)
# Filter files by type
CFILES = $(filter %.c, $(SRC))
ASMFILES = $(filter %.S, $(SRC))
# Generate list of object files
OBJS = $(CFILES:.c=.c.o) $(ASMFILES:.S=.S.o)
# Define .lst files
LST = $(filter %.lst, $(OBJS:.o=.lst))
# Build all
all: $(TRG)
stats: $(TRG)
$(OBJDUMP) -h $(TRG)
$(SIZE) $(TRG)
hex: $(HEXTRG)
upload: hex
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMER) -p $(MCU) -U flash:w:$(HEXROMTRG)
fuses:
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMER) -p $(MCU) -U lfuse:w:0xf7:m -U hfuse:w:0xd9:m
# to use internal osc. for programing
# otherwise an external xtal is required
default:
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMER) -p $(MCU) -U lfuse:w:0x62:m -U hfuse:w:0xd9:m
program: default upload fuses
# Linking
$(TRG): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $(TRG) $(OBJS)
# Generate object files
%.c.o: src/%.c
$(CC) $(CFLAGS) -c $< -o $@
%.S.o: src/%.S
$(CC) $(ASMFLAGS) -c $< -o $@
# Generate hex
%.hex: %.out
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.ee.hex: %.out
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
# GDB Init file
gdbinit: $(GDBINITFILE)
@echo "file $(TRG)" > $(GDBINITFILE)
@echo "target remote localhost:1212" >> $(GDBINITFILE)
@echo "load" >> $(GDBINITFILE)
@echo "break main" >> $(GDBINITFILE)
@echo "continue" >> $(GDBINITFILE)
@echo
@echo "Use 'avr-gdb -x $(GDBINITFILE)'"
clean:
$(REMOVE) $(TRG) $(TRG).map
$(REMOVE) $(OBJS)
$(REMOVE) $(GDBINITFILE)
$(REMOVE) *.hex