forked from MartGB/BMSBattery_S_controllers_firmware
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile_linux
173 lines (145 loc) · 4.05 KB
/
Makefile_linux
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#Makefile for STM8 Examples with SDCC compiler
#Author: Saeid Yazdani
#Website: WWW.EMBEDONIX.COM
#Copyright 2016
#LICENSE: GNU-LGPL
.PHONY: all clean
#Compiler
CC = sdcc
OBJCOPY = objcopy
SIZE = size
#Platform
PLATFORM = stm8
#Product name
PNAME = main
#Directory for helpers
IDIR = lib/inc
SDIR = lib/src
SRC = src
INC = include
# In case you ever want a different name for the main source file
MAINSRC = $(SRC)/$(PNAME).c
ELF_SECTIONS_TO_REMOVE = -R DATA -R INITIALIZED -R SSEG -R .debug_line -R .debug_loc -R .debug_abbrev -R .debug_info -R .debug_pubnames -R .debug_frame
# These are the sources that must be compiled to .rel files:
EXTRASRCS = \
$(SDIR)/stm8s_itc.c \
$(SDIR)/stm8s_clk.c \
$(SDIR)/stm8s_iwdg.c \
$(SDIR)/stm8s_gpio.c \
$(SDIR)/stm8s_exti.c \
$(SDIR)/stm8s_uart2.c \
$(SDIR)/stm8s_tim1.c \
$(SDIR)/stm8s_tim2.c \
$(SDIR)/stm8s_adc1.c \
$(SDIR)/stm8s_flash.c \
$(SRC)/BOdisplay.c \
$(SRC)/ACAcontrollerState.c \
$(SRC)/ACAeeprom.c \
$(SRC)/ACAsetPoint.c \
$(SRC)/ACAcommons.c \
$(SRC)/gpio.c \
$(SRC)/cruise_control.c \
$(SRC)/uart.c \
$(SRC)/adc.c \
$(SRC)/brake.c \
$(SRC)/timers.c \
$(SRC)/pwm.c \
$(SRC)/motor.c \
$(SRC)/PAS.c \
$(SRC)/SPEED.c \
$(SRC)/display.c \
$(SRC)/display_lcd8.c \
$(SRC)/display_kingmeter.c
HEADERS = \
$(INC)/BOdisplay.h \
$(INC)/ACAcommons.h \
$(INC)/ACAsetPoint.h \
$(INC)/ACAcontrollerState.h \
$(INC)/ACAeeprom.h \
$(INC)/adc.h \
$(INC)/brake.h \
$(INC)/cruise_control.h \
$(INC)/gpio.h \
$(INC)/interrupts.h \
$(INC)/main.h \
$(INC)/motor.h \
$(INC)/pwm.h \
$(INC)/timers.h \
$(INC)/uart.h \
$(INC)/PAS.h \
$(INC)/SPEED.h \
# The list of .rel files can be derived from the list of their source files
RELS = $(EXTRASRCS:.c=.rel)
INCLUDES = -I$(IDIR) -I$(INC)
CFLAGS = -m$(PLATFORM) --std-c99
#--nolospre
#ELF_FLAGS = --out-fmt-elf --debug
#ELF_FLAGS = --out-fmt-elf
ELF_FLAGS = --out-fmt-ihx
LIBS =
# This just provides the conventional target name "all"; it is optional
# Note: I assume you set PNAME via some means not exhibited in your original file
all: $(PNAME)
# How to build the overall program
$(PNAME): $(MAINSRC) $(RELS)
$(CC) $(INCLUDES) $(CFLAGS) $(ELF_FLAGS) $(LIBS) $(MAINSRC) $(RELS)
# $(SIZE) $(PNAME).elf -A
# $(OBJCOPY) -O binary $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).bin
# $(OBJCOPY) -O ihex $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).hex
# How to build any .rel file from its corresponding .c file
# GNU would have you use a pattern rule for this, but that's GNU-specific
%.rel: %.c $(HEADERS)
$(CC) -c $(INCLUDES) $(CFLAGS) $(ELF_FLAGS) $(LIBS) -o$< $<
# Suffixes appearing in suffix rules we care about.
# Necessary because .rel is not one of the standard suffixes.
.SUFFIXES: .c .rel
hex:
$(OBJCOPY) -O ihex $(ELF_SECTIONS_TO_REMOVE) $(PNAME).elf $(PNAME).ihx
flash:
stm8flash -d/dev/ttyACM0 -cstlinkv2 -pstm8s105?6 -w$(PNAME).ihx -s flash
# stm8flash -cstlinkv2 -pstm8s105?6 -w$(PNAME).bin
erase:
stm8flash -d/dev/ttyACM0 -cstlinkv2 -pstm8s105?6 -w images/zeroes.bin -s flash
erase-eeprom:
stm8flash -d/dev/ttyACM0 -cstlinkv2 -pstm8s105?6 -w images/zeroes.bin -s eeprom
read-eeprom:
stm8flash -d/dev/ttyACM0 -cstlinkv2 -pstm8s105?6 -r eeprom.dump -s eeprom
unlock:
stm8flash -d/dev/ttyACM0 -cstlinkv2 -pstm8s105?6 -u
option:
stm8flash -d/dev/ttyACM0 -cstlinkv2 -pstm8s105?6 -w images/option_bytes_pwm_n_channels_enabled.bin -s opt
clean:
@echo "Cleaning files..."
@rm -rf $(SDIR)/*.asm
@rm -rf $(SDIR)/*.rel
@rm -rf $(SDIR)/*.lk
@rm -rf $(SDIR)/*.lst
@rm -rf $(SDIR)/*.rst
@rm -rf $(SDIR)/*.sym
@rm -rf $(SDIR)/*.cdb
@rm -rf $(SDIR)/*.map
@rm -rf $(SDIR)/*.elf
@rm -rf $(SDIR)/*.bin
@rm -rf $(SDIR)/*.adb
@rm -rf $(SRC)/*.asm
@rm -rf $(SRC)/*.rel
@rm -rf $(SRC)/*.lk
@rm -rf $(SRC)/*.lst
@rm -rf $(SRC)/*.rst
@rm -rf $(SRC)/*.sym
@rm -rf $(SRC)/*.cdb
@rm -rf $(SRC)/*.map
@rm -rf $(SRC)/*.adb
@rm -rf $(SRC)/*.elf
@rm -rf main.ihx
@rm -rf $(SRC)/*.ihx
@rm -rf $(SRC)/*.hex
@rm -rf main.asm
@rm -rf main.ihx
@rm -rf main.lk
@rm -rf main.lst
@rm -rf main.map
@rm -rf main.rel
@rm -rf main.rst
@rm -rf main.sym
@echo "Done."