This repository was archived by the owner on Apr 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
91 lines (69 loc) · 2.83 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#######
# makefile for STM8*_StdPeriph_Lib and SDCC compiler
# modified for SDCC
# modified use SPL functions inlined from https://github.com/MightyPork/stm8s_inline_spl
# inlined functions save much flash space, but may not be totally complete.
#
# usage:
# 1. if SDCC not in PATH set path -> CC_ROOT
# 2. set correct STM8 device -> DEVICE
# 3. set project paths -> PRJ_ROOT, PRJ_SRC_DIR, PRJ_INC_DIR
# 4. set SPL paths -> SPL_ROOT
# 5. add required SPL modules -> SPL_SOURCE
# 6. add required STM8S_EVAL modules -> EVAL_SOURCE, EVAL_128K_SOURCE, EVAL_COMM_SOURCE
#
#######
# STM8 device (for supported devices see stm8s.h)
DEVICE = STM8S103
PARTNO = stm8s103f3
PROGRAMMER = stlinkv2
# set compiler path & parameters
CC_ROOT =
CC = sdcc
#CFLAGS = -mstm8 -lstm8 --opt-code-size --out-fmt-elf --debug --all-callee-saves --verbose --stack-auto --fverbose-asm --float-reent --no-peep
# oddball SDCC linker errors - has bugs with debug and out-fmt-elf. --fverbose-asm seems to help in this case; don't know why
CFLAGS = -mstm8 -lstm8 --opt-code-size --out-fmt-elf --debug --verbose --fverbose-asm --disable-warning 126
#CFLAGS = -mstm8 -lstm8 --opt-code-size --disable-warning 126 --disable-warning 110
# use pre-compiled and split SPL libs from sduino project:
#CFLAGS += -L ../spl-splitter/lib
# set output folder and target name
OUTPUT_DIR = ./dist
TARGET := $(addprefix $(OUTPUT_DIR)/, $(notdir $(CURDIR))).elf
# set project folder and files (all *.c)
PRJ_ROOT = .
PRJ_SRC_DIR = $(PRJ_ROOT)
PRJ_INC_DIR = $(PRJ_ROOT)
PRJ_SOURCE = $(notdir $(wildcard $(PRJ_SRC_DIR)/*.c))
PRJ_OBJECTS := $(addprefix $(OUTPUT_DIR)/, $(PRJ_SOURCE:.c=.rel))
# set SPL paths
SPL_ROOT =
#uncomment the next line if you're not usig the 'inlined' SPL headers
#SPL_SRC_DIR = $(SPL_ROOT)/Libraries/STM8S_StdPeriph_Driver/src
SPL_INC_DIR = inc
#SPL_INC_DIR = ../spl/Libraries/STM8S_StdPeriph_Driver/inc/
#SPL_SOURCE: not needed with the 'inline' library, *except* the stm8s_flash.c, if used
#SPL_SOURCE = stm8s_gpio.c stm8s_clk.c stm8s_uart1.c stm8s_tim1.c stm8s_adc1.c
SPL_SOURCE =
SPL_OBJECTS := $(addprefix $(OUTPUT_DIR)/, $(SPL_SOURCE:.c=.rel))
COMMON_INC = ./common
# collect all include folders
INCLUDE = -I$(PRJ_SRC_DIR) -I$(SPL_INC_DIR) -I$(COMMON_INC)
# collect all source directories
VPATH=$(PRJ_SRC_DIR):$(SPL_SRC_DIR)
all: $(OUTPUT_DIR) $(TARGET)
$(OUTPUT_DIR):
mkdir -p $(OUTPUT_DIR)
# $(OUTPUT_DIR)/%.rel: %.c
# $(CC) $(CFLAGS) $(INCLUDE) -D$(DEVICE) -c $?
$(OUTPUT_DIR)/%.rel: %.c
$(CC) $(CFLAGS) $(INCLUDE) -D$(DEVICE) -c $? -o $@
$(TARGET): $(PRJ_OBJECTS) $(SPL_OBJECTS)
$(CC) $(CFLAGS) -o $(TARGET) $^
stm8-objcopy -O ihex -R DATA -R INITIALIZED -R SSEG $(TARGET) $(TARGET).ihx
stm8-size -A $(TARGET)
clean:
rm -rf $(OUTPUT_DIR)
rm $(PRJ_ROOT)/*.gch
flash: all
stm8flash -c $(PROGRAMMER) -p $(PARTNO) -w $(TARGET).ihx
.PHONY: clean flash