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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# The architecture configuration
ARCH := atmega8
AVRDUDE_ARCH := m8
AVRDUDE_SPEED := 1
AVRDUDE_SLOW_SPEED := 100
PROGRAMMER := avr910
#PROGRAMMER := avrisp2
PROGPORT := /dev/ttyUSB0
#PROGPORT := usb
# The fuse bits
LFUSE := 0xFF
HFUSE := 0xD9
# Hardware parameters
F_CPU := 16000000
BINEXT :=
NODEPS :=
# The toolchain definitions
CC := avr-gcc$(BINEXT)
OBJCOPY := avr-objcopy$(BINEXT)
SIZE := avr-size$(BINEXT)
MKDIR := mkdir$(BINEXT)
MV := mv$(BINEXT)
RM := rm$(BINEXT)
CP := cp$(BINEXT)
ECHO := echo$(BINEXT)
AVRDUDE := avrdude$(BINEXT)
MYSMARTUSB := mysmartusb.py
DOXYGEN := doxygen$(BINEXT)
V := @ # Verbose build: make V=1
O := s # Optimize flag
Q := $(V:1=)
QUIET_CC = $(Q:@=@$(ECHO) ' CC '$@;)$(CC)
QUIET_DEPEND = $(Q:@=@$(ECHO) ' DEPEND '$@;)$(CC)
QUIET_OBJCOPY = $(Q:@=@$(ECHO) ' OBJCOPY '$@;)$(OBJCOPY)
QUIET_SIZE = $(Q:@=@$(ECHO) ' SIZE '$@;)$(SIZE)
CFLAGS := -mmcu=$(ARCH) -std=c99 -g -O$(O) -Wall \
"-Dinline=inline __attribute__((__always_inline__))" \
-fshort-enums \
-DF_CPU=$(F_CPU)
LDFLAGS :=
# Application code
SRCS := main.c comm.c
NAME := pcremote
BIN := $(NAME).bin
HEX := $(NAME).hex
EEP := $(NAME).eep.hex
.SUFFIXES:
.PHONY: all avrdude install_flash install_eeprom install reset writefuse doxygen clean distclean
.DEFAULT_GOAL := all
ifeq ($(BINEXT),.exe)
HAVE_MYSMARTUSB :=
else
HAVE_MYSMARTUSB := $(shell $(MYSMARTUSB) -h >/dev/null 2>&1 && $(ECHO) 1)
endif
MYSMARTUSB_PWRCYCLE := \
$(if $(HAVE_MYSMARTUSB), \
$(MYSMARTUSB) -p0 $(PROGPORT) && \
sleep 1 && \
$(MYSMARTUSB) -p1 $(PROGPORT) \
)
MYSMARTUSB_PROGMODE := \
$(if $(HAVE_MYSMARTUSB), \
$(MYSMARTUSB) -mp $(PROGPORT) \
)
MYSMARTUSB_DATAMODE := \
$(if $(HAVE_MYSMARTUSB), \
$(MYSMARTUSB) -md $(PROGPORT) \
)
DEPS = $(sort $(patsubst %.c,dep/%.d,$(1)))
OBJS = $(sort $(patsubst %.c,obj/%.o,$(1)))
# Generate dependencies
$(call DEPS,$(SRCS)): dep/%.d: %.c
@$(MKDIR) -p $(dir $@)
@$(MKDIR) -p obj
$(QUIET_DEPEND) -o $@.tmp -MM -MT "$@ $(patsubst dep/%.d,obj/%.o,$@)" $(CFLAGS) $<
@$(MV) -f $@.tmp $@
ifeq ($(NODEPS),)
-include $(call DEPS,$(SRCS))
endif
# Generate object files
$(call OBJS,$(SRCS)): obj/%.o: %.c
@$(MKDIR) -p $(dir $@)
$(QUIET_CC) -o $@ -c $(CFLAGS) $<
all: $(HEX)
%.s: %.c
$(QUIET_CC) $(CFLAGS) -S $*.c
$(BIN): $(call OBJS,$(SRCS))
$(QUIET_CC) $(CFLAGS) -o $(BIN) $(call OBJS,$(SRCS)) $(LDFLAGS) $(LDFLAGS)
$(HEX): $(BIN)
$(QUIET_OBJCOPY) -R.eeprom -O ihex $(BIN) $(HEX)
# $(QUIET_OBJCOPY) -j.eeprom --set-section-flags=.eeprom="alloc,load" \
# --change-section-lma .eeprom=0 -O ihex $(BIN) $(EEP)
$(QUIET_SIZE) $(BIN)
avrdude:
$(call MYSMARTUSB_PROGMODE)
$(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
-c $(PROGRAMMER) -P $(PROGPORT) -t
$(call MYSMARTUSB_PWRCYCLE)
$(call MYSMARTUSB_DATAMODE)
install_flash: all
$(call MYSMARTUSB_PROGMODE)
$(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
-c $(PROGRAMMER) -P $(PROGPORT) \
-U flash:w:$(HEX)
$(call MYSMARTUSB_DATAMODE)
install_eeprom: all
$(call MYSMARTUSB_PROGMODE)
$(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
-c $(PROGRAMMER) -P $(PROGPORT) -U eeprom:w:$(EEP)
$(call MYSMARTUSB_DATAMODE)
install: install_flash
$(call MYSMARTUSB_PWRCYCLE)
# Reset the microcontroller through avrdude
reset:
$(call MYSMARTUSB_PROGMODE)
$(AVRDUDE) -B $(AVRDUDE_SPEED) -p $(AVRDUDE_ARCH) \
-c $(PROGRAMMER) -P $(PROGPORT) \
-U signature:r:/dev/null:i -q -q
$(call MYSMARTUSB_PWRCYCLE)
writefuse:
$(call MYSMARTUSB_PROGMODE)
$(AVRDUDE) -B $(AVRDUDE_SLOW_SPEED) -p $(AVRDUDE_ARCH) \
-c $(PROGRAMMER) -P $(PROGPORT) -q -q \
-U lfuse:w:$(LFUSE):m \
-U hfuse:w:$(HFUSE):m
$(call MYSMARTUSB_DATAMODE)
$(call MYSMARTUSB_PWRCYCLE)
clean:
-$(RM) -rf obj dep $(BIN) __pycache__
distclean: clean
-$(RM) -rf $(patsubst %.c,%.s,$(SRCS)) $(HEX) $(EEP)
|