~toykeeper/flashlight-firmware/trunk

« back to all changes in this revision

Viewing changes to SammysHP/rampinglight/Makefile

  • Committer: Selene Scriven
  • Date: 2021-08-09 00:14:36 UTC
  • Revision ID: bzr@toykeeper.net-20210809001436-n3d1rw80mlmbonf4
imported "rampinglight" firmware from SammysHP

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#==== Main Options =============================================================
 
2
 
 
3
MCU = attiny13
 
4
F_CPU = 4800000
 
5
#LFUSE = 0x75
 
6
#HFUSE = 0xFF
 
7
 
 
8
TARGET = rampinglight
 
9
SRC = $(TARGET).c
 
10
 
 
11
OBJDIR = obj
 
12
BACKUPDIR = backup
 
13
 
 
14
 
 
15
 
 
16
#==== Compile Options ==========================================================
 
17
 
 
18
CFLAGS = -mmcu=$(MCU)
 
19
CFLAGS += -I.
 
20
CFLAGS += -DF_CPU=$(F_CPU)UL
 
21
CFLAGS += -Os
 
22
#CFLAGS += -mint8
 
23
#CFLAGS += -mshort-calls
 
24
CFLAGS += -funsigned-char
 
25
CFLAGS += -funsigned-bitfields
 
26
CFLAGS += -fpack-struct
 
27
CFLAGS += -fshort-enums
 
28
#CFLAGS += -fno-unit-at-a-time
 
29
CFLAGS += -Wall
 
30
CFLAGS += -Wstrict-prototypes
 
31
CFLAGS += -Wundef
 
32
#CFLAGS += -Wunreachable-code
 
33
#CFLAGS += -Wsign-compare
 
34
CFLAGS += -std=gnu99
 
35
#CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
 
36
#CFLAGS += -flto
 
37
CFLAGS += -Wno-int-to-pointer-cast
 
38
#CFLAGS += -save-temps
 
39
 
 
40
#LDFLAGS =
 
41
 
 
42
 
 
43
 
 
44
#==== Programming Options (avrdude) ============================================
 
45
 
 
46
AVRDUDE_PROGRAMMER = stk500v1
 
47
AVRDUDE_PORT = /dev/ttyUSB0
 
48
AVRDUDE_BAUD = 19200
 
49
 
 
50
#AVRDUDE_NO_VERIFY = -V
 
51
 
 
52
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -b $(AVRDUDE_BAUD) -c $(AVRDUDE_PROGRAMMER) $(AVRDUDE_NO_VERIFY)
 
53
 
 
54
 
 
55
 
 
56
#==== Targets ==================================================================
 
57
 
 
58
CC = avr-gcc
 
59
OBJCOPY = avr-objcopy
 
60
OBJDUMP = avr-objdump
 
61
AVRDUDE = avrdude
 
62
AVRSIZE = avr-size
 
63
REMOVE = rm -f
 
64
REMOVEDIR = rm -rf
 
65
TAIL = tail
 
66
AWK = awk
 
67
 
 
68
OBJ = $(SRC:%.c=$(OBJDIR)/%.o)
 
69
 
 
70
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
 
71
AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
 
72
 
 
73
MEMORYTYPES = flash eeprom fuse lfuse hfuse efuse boot calibration lock signature application apptable prodsig usersig
 
74
 
 
75
 
 
76
all: build
 
77
 
 
78
 
 
79
help:
 
80
        @echo 'Basic targets:'
 
81
        @echo '  build       Create all files.'
 
82
        @echo '  clean       Remove files created by make.'
 
83
        @echo '  size        Show the size of each section in the .elf file.'
 
84
        @echo
 
85
        @echo 'Create files:'
 
86
        @echo '  elf         Create binary .elf file.'
 
87
        @echo '  hex         Create .hex file containing .text and .data sections.'
 
88
        @echo '  eep         Create .eep file with the EEPROM content.'
 
89
        @echo '  lss         Create .lss file with a listing of the program.'
 
90
        @echo
 
91
        @echo 'Flashing:'
 
92
        @echo '  program     Write flash and EEPROM.'
 
93
        @echo '  flash       Write only flash.'
 
94
        @echo '  eeprom      Write only EEPROM.'
 
95
        @echo '  backup      Backup MCU content to "$(BACKUPDIR)". Available memory types:'
 
96
        @echo '              $(MEMORYTYPES)'
 
97
        @echo
 
98
        @echo 'Fuses:'
 
99
        @echo '  readfuses   Read fuses from MCU.'
 
100
        @echo '  writefuses  Write fuses to MCU using .fuse section.'
 
101
        @echo '  printfuses  Print fuses from .fuse section.'
 
102
 
 
103
 
 
104
build: elf hex eep lss size
 
105
 
 
106
 
 
107
elf: $(TARGET).elf
 
108
hex: $(TARGET).hex
 
109
eep: $(TARGET).eep
 
110
lss: $(TARGET).lss
 
111
 
 
112
 
 
113
program: flash eeprom
 
114
 
 
115
 
 
116
flash: $(TARGET).hex
 
117
        $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
 
118
 
 
119
 
 
120
eeprom: $(TARGET).eep
 
121
        $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_EEPROM)
 
122
 
 
123
 
 
124
readfuses:
 
125
        $(AVRDUDE) $(AVRDUDE_FLAGS) -U lfuse:r:-:h -U hfuse:r:-:h
 
126
 
 
127
 
 
128
#writefuses:
 
129
#       $(AVRDUDE) $(AVRDUDE_FLAGS) -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m
 
130
 
 
131
 
 
132
writefuses: FUSES = $(shell $(OBJDUMP) -s --section=.fuse $(TARGET).elf | tail -1 | awk '{print substr($$2,1,2),substr($$2,3,2),substr($$2,5,2)}')
 
133
writefuses: $(TARGET).elf
 
134
        $(AVRDUDE) $(AVRDUDE_FLAGS) \
 
135
        $(if $(word 1,$(FUSES)),-U lfuse:w:0x$(word 1,$(FUSES)):m) \
 
136
        $(if $(word 2,$(FUSES)),-U hfuse:w:0x$(word 2,$(FUSES)):m) \
 
137
        $(if $(word 3,$(FUSES)),-U efuse:w:0x$(word 3,$(FUSES)):m)
 
138
 
 
139
 
 
140
printfuses: FUSES = $(shell $(OBJDUMP) -s --section=.fuse $(TARGET).elf | tail -1 | awk '{printf "l:0x%s h:0x%s e:0x%s",substr($$2,1,2),substr($$2,3,2),substr($$2,5,2)}')
 
141
printfuses: $(TARGET).elf
 
142
        @echo '$(FUSES)'
 
143
 
 
144
 
 
145
%.hex: %.elf
 
146
        $(OBJCOPY) -O ihex -j .text -j .data $< $@
 
147
 
 
148
 
 
149
%.eep: %.elf
 
150
        -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $< $@
 
151
 
 
152
 
 
153
%.lss: %.elf
 
154
        $(OBJDUMP) -h -S $< > $@
 
155
 
 
156
 
 
157
.SECONDARY: $(TARGET).elf
 
158
.PRECIOUS: $(OBJ)
 
159
%.elf: $(OBJ)
 
160
        $(CC) $(CFLAGS) $^ --output $@ $(LDFLAGS)
 
161
 
 
162
 
 
163
$(OBJDIR)/%.o: %.c
 
164
        $(shell mkdir -p $(OBJDIR) 2>/dev/null)
 
165
        $(CC) -c $(CFLAGS) $< -o $@
 
166
 
 
167
 
 
168
size: $(TARGET).elf
 
169
        $(AVRSIZE) -A $(TARGET).elf
 
170
        $(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf
 
171
 
 
172
 
 
173
clean:
 
174
        $(REMOVE) "$(TARGET).hex"
 
175
        $(REMOVE) "$(TARGET).eep"
 
176
        $(REMOVE) "$(TARGET).elf"
 
177
        $(REMOVE) "$(TARGET).lss"
 
178
        $(REMOVE) "$(TARGET).i"
 
179
        $(REMOVE) "$(TARGET).s"
 
180
        $(REMOVEDIR) "$(OBJDIR)"
 
181
 
 
182
 
 
183
backup:
 
184
        $(shell mkdir -p $(BACKUPDIR) 2>/dev/null)
 
185
        @for memory in $(MEMORYTYPES); do \
 
186
            $(AVRDUDE) $(AVRDUDE_FLAGS) -U $$memory:r:$(BACKUPDIR)/$(MCU).$$memory.hex:i; \
 
187
        done
 
188
 
 
189
 
 
190
.PHONY: all size build elf hex eep lss clean program flash eeprom readfuses writefuses printfuses backup help