summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 6d420d1a3181e6160f8fb0630084ce5806d39f8a (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
# How to compile the examples.
APP = bleusb
RELEASE = debug
TARGET = thumbv6m-none-eabi

# VID and PID of device to flash firmware to.
USBVID = 239a
USBPID = '001e|801e'

BOSSAC = bossac
OFFSET = 0x2000

OBJCOPY = arm-none-eabi-objcopy

TARGETDIR = target/$(TARGET)
OUTDIR = $(TARGETDIR)/$(RELEASE)

CARGOFLAGS = --target thumbv6m-none-eabi

.PHONY: all clean cargo-build $(OUTDIR)/$(APP)

all: $(OUTDIR)/$(APP)

clean:
	rm -f $(APP).uf2
	rm -f $(APP).bin
	cargo clean

test:
	cargo test

cargo-build:
	cargo rustc $(CARGOFLAGS) -- -C link-arg=-Tlink.x

$(OUTDIR)/$(APP): cargo-build

flash: $(APP).bin
	feather-cmd r
	sleep 2
	feather-cmd dfu
	sleep 2
	$(BOSSAC) -R -e -w -v -o$(OFFSET) -p`./find-serial-port $(USBVID) $(USBPID)` $<

qemu: $(OUTDIR)/$(APP)
	qemu-system-arm -d in_asm,int,exec,cpu,guest_errors,unimp -pidfile qemu.pid -cpu cortex-m0 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -s -S -kernel $<

gdb: $(OUTDIR)/$(APP)
	gdb-multiarch -ex "target remote localhost:1234" -ex "break main" -ex "continue" $<

%.bin: $(OUTDIR)/%
	$(OBJCOPY) -O binary $< $@

# Requires https://github.com/sajattack/uf2conv-rs.git
%.uf2: %.bin
	uf2conv-rs $< --base $(OFFSET) --output $@