summaryrefslogtreecommitdiffstats
path: root/motmock/firmware/Makefile
blob: 7fad605058ea2c211c8f52945123eda746f336a9 (plain)
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
OBJCOPY:=avr-objcopy
OBJDUMP:=avr-objdump
SIZE:=avr-size

AVRDUDE:=avrdude
AVRDUDE_MCU:=m8
AVRDUDE_PORT:=usb
AVRDUDE_PROG:=avrisp2
AVRDUDE_SPEED:=1
AVRDUDE_SPEED_SLOW:=10

# Fuses: int-osc-8MHz-64ms; BOD-4V
LFUSE:=0x24
HFUSE:=0xD9

AVR_CPU_FREQUENCY_HZ:=8000000

NAME:=motmock
TARGET:=avr-atmega8
RELEASEDIR:=target/$(TARGET)/release
HEX:=$(RELEASEDIR)/$(NAME).hex
ELF:=$(RELEASEDIR)/$(NAME).elf
DASM:=$(RELEASEDIR)/$(NAME).dasm

all: $(HEX) $(DASM)
	$(SIZE) --format=SysV $(ELF)

$(HEX): $(ELF)
	$(OBJCOPY) -R.eeprom -O ihex $(ELF) $(HEX)

$(ELF):
	AVR_CPU_FREQUENCY_HZ=$(AVR_CPU_FREQUENCY_HZ) \
	cargo build --target $(TARGET).json -Z build-std=core --release

.PHONY: $(ELF) # Always run cargo

$(DASM): $(HEX)
	$(OBJDUMP) --disassemble $(ELF) > $(DASM)

dasm: $(DASM)
	less $(DASM)

clean:
	cargo clean

reset:
	$(AVRDUDE) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROG) \
		-B $(AVRDUDE_SPEED_SLOW) -p $(AVRDUDE_MCU) \
		-U signature:r:/dev/null:i -qq

avrdude:
	$(AVRDUDE) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROG) \
		-B $(AVRDUDE_SPEED_SLOW) -p $(AVRDUDE_MCU) \
		-t

fuses:
	$(AVRDUDE) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROG) \
		-B $(AVRDUDE_SPEED_SLOW) -p $(AVRDUDE_MCU) \
		-U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m

flash: $(HEX)
	$(AVRDUDE) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROG) \
		-B $(AVRDUDE_SPEED) -p $(AVRDUDE_MCU) \
		-U flash:w:$(HEX)
bues.ch cgit interface