-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
50 lines (41 loc) · 1.37 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
outdir = /tmp
avrdir = ~/Applications/.arduino/arduino-1.8.12/hardware/tools/avr
avrbin = $(avrdir)/bin
mcu = attiny85
# make target="blink" -C ./project/
target = blink
build: build-$(target)
build-%:
@zig build-obj -femit-bin=$(outdir)/$(target).o \
-Dmcu=$(mcu) \
-Drelease-small --strip \
--cache-dir /tmp/zig-cache \
-target avr-freestanding-none \
-mcpu=$(mcu) $(target).zig
@$(avrbin)/avr-gcc -Os $(outdir)/$(target).o \
-mmcu=$(mcu) -o $(outdir)/$(target).elf
@$(avrbin)/avr-objcopy -j .text -j data \
-O ihex $(outdir)/$(target).elf \
$(outdir)/$(target).hex
@$(avrbin)/avr-size -C --mcu=$(mcu) \
$(outdir)/$(target).elf
flash: flash-$(mcu)
flash-attiny85: build-$(target)
@$(avrbin)/avrdude -p $(mcu) -P /dev/ttyACM0 \
-c avrisp -b 19200 \
-U flash:w:$(outdir)/$(target).hex:i \
-C $(avrdir)/etc/avrdude.conf
# this one requires a rst to gnd "button press"
# - will mess with Arduino IDE compatibility
# - will boot within 10 seconds
# - red leds will start powered off after re-connecting
flash-atmega32u4: build-$(target)
@$(avrbin)/avrdude -p$(mcu) \
-cavr109 -P/dev/ttyACM0 -b57600 \
-U flash:w:$(outdir)/$(target).hex:i \
-C $(avrdir)/etc/avrdude.conf
flash-%: build-$(target)
@$(avrbin)/avrdude -p $(mcu) -Pusb \
-U flash:w:$(outdir)/$(target).hex:i \
-c arduino -P/dev/ttyUSB0 \
-C $(avrdir)/etc/avrdude.conf