-
Notifications
You must be signed in to change notification settings - Fork 27
/
Makefile
72 lines (53 loc) · 1.7 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
## STM8S
MCU ?= stm8s003f3
FAMILY ?= STM8S
## STM8L
# MCU ?= stm8l051f3
# FAMILY ?= STM8L
ARCH = stm8
TARGET ?= main.ihx
SRCS := $(wildcard *.c)
ASRCS := $(wildcard *.s)
OBJS = $(SRCS:.c=.rel)
OBJS += $(ASRCS:.s=.rel)
CC = sdcc
LD = sdld
AS = sdasstm8
OBJCOPY = sdobjcopy
ASFLAGS = -plosgff
CFLAGS = -m$(ARCH) -p$(MCU) -D$(FAMILY) -I.
CFLAGS += --stack-auto --noinduction --use-non-free --noinvariant --opt-code-size
LDFLAGS = -m$(ARCH) -l$(ARCH) --out-fmt-ihx
LDFLAGS += -Wl-bIVT=0x8000 -Wl-bGSINIT=0x8080
all: $(TARGET) size
$(TARGET): $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -o $@
%.rel: %.s
$(AS) $(ASFLAGS) $<
%.rel: %.c
$(CC) $(CFLAGS) -c $< -o $@
flash: $(TARGET)
stm8flash -c stlinkv2 -p $(MCU) -w $(TARGET)
clean:
rm -f *.map *.rel *.ihx *.o *.sym *.lk *.lst *.rst *.cdb *.bin *.asm
size:
@$(OBJCOPY) -I ihex --output-target=binary $(TARGET) $(TARGET).bin
@echo "-----\nImage size:"
@stat -L -c %s $(TARGET).bin
## @TODO: separate option-bytes for stm8s and stm8l!
# enable write-protection on first 10 pages
opt-set:
@echo '0x00 0x09 0xf6 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff' | xxd -r > opt.bin
stm8flash -c stlinkv2 -p stm8s003f3 -s opt -w opt.bin
# reset option-bytes to factory defaults
opt-reset:
@echo '0x00 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff 0x00 0xff' | xxd -r > opt.bin
stm8flash -c stlinkv2 -p stm8s003f3 -s opt -w opt.bin
dump-opt:
stm8flash -c stlinkv2 -p $(MCU) -s opt -r dump_opt.bin
dump-flash:
stm8flash -c stlinkv2 -p $(MCU) -s flash -r dump_flash.bin
erase:
tr '\000' '\377' < /dev/zero | dd of=empty.bin bs=8192 count=1
stm8flash -c stlinkv2 -p $(MCU) -s flash -w empty.bin
.PHONY: clean all flash size dump-opt dump-flash erase