Skip to content

Commit d91ff72

Browse files
committed
compile the SPL for all supported CPUs
1 parent d77441c commit d91ff72

20 files changed

Lines changed: 284 additions & 2 deletions

STM8S_StdPeriph_Driver/README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Compiling the ST Standard Peripheral Library SPL
2+
3+
4+
all of this might be moved to this location at a later stage of the project:
5+
hardware/tools/stm8/STM8S_StdPeriph_Driver
6+
7+
8+
## STM8S903 and STM8AF622x
9+
10+
The definitions for these two (uncommon) CPUs are flawed in the original
11+
versions of the SPL. `inc/stm8s.h` needs
12+
[this patch](correct_stm8s908.patch) if you start from
13+
scratch with the stock SPL files from the ST website.
14+
15+
16+
## Supported CPUs
17+
18+
The script in `tools/showdeps.sh` lists the known CPU names defined in
19+
inc/stm8s.h. Some CPUs use identical libraries:
20+
21+
Product line | supported CPU types per library
22+
---------------------------------- | ---------------------------
23+
| Low density devices | STM8S003, STM8S103
24+
| Medium density devices | STM8S005, STM8S105, STM8AF626x
25+
| High density devices without CAN | STM8S007, STM8S207, STM8AF62Ax
26+
| High density devices with CAN | STM8S208, STM8AF52Ax
27+
| App. specific low density devices | STM8S903
28+
| | STM8AF622x
29+
30+
31+
Supported peripherie for the different CPUs:
32+
33+
CPU |STM8S003|STM8S005 |STM8S007 |STM8S208 |STM8S903 |
34+
|STM8S103|STM8S105 |STM8S207 | | |
35+
Module | |STM8AF626x|STM8AF62Ax |STM8AF52Ax| |STM8AF622x
36+
------ |:-----:|:------: |:------: |:------: |:------: |
37+
stm8s_adc1.c|+ |+ | | |+ |+
38+
stm8s_adc2.c| | |+ |+ | |
39+
stm8s_awu.c|+ |+ |+ |+ |+ |+
40+
stm8s_beep.c|+ |+ |+ |+ |+ |+
41+
stm8s_can.c| | | |+ | |
42+
stm8s_clk.c|+ |+ |+ |+ |+ |+
43+
stm8s_exti.c|+ |+ |+ |+ |+ |+
44+
stm8s_flash.c|+ |+ |+ |+ |+ |+
45+
stm8s_gpio.c|+ |+ |+ |+ |+ |+
46+
stm8s_i2c.c|+ |+ |+ |+ |+ |+
47+
stm8s_itc.c|+ |+ |+ |+ |+ |+
48+
stm8s_iwdg.c|+ |+ |+ |+ |+ |+
49+
stm8s_rst.c|+ |+ |+ |+ |+ |+
50+
stm8s_spi.c|+ |+ |+ |+ |+ |+
51+
stm8s_tim1.c|+ |+ |+ |+ |+ |+
52+
stm8s_tim2.c|+ |+ |+ |+ | |
53+
stm8s_tim3.c| |+ |+ |+ | |
54+
stm8s_tim4.c|+ |+ |+ |+ | |
55+
stm8s_tim5.c| | | | |+ |+
56+
stm8s_tim6.c| | | | |+ |+
57+
stm8s_uart1.c|+ | |+ |+ |+ |
58+
stm8s_uart2.c| |+ | | | |
59+
stm8s_uart3.c| | |+ |+ | |
60+
stm8s_uart4.c| | | | | |+
61+
stm8s_wwdg.c|+ |+ |+ |+ |+ |+
62+
63+
![Table of supported peripherie per CPU](peripherie.png)
64+
65+
66+
## Recycle bin
67+
68+
Some (maybe) useful leftovers. These code snipplets might be useful again
69+
later.
70+
71+
72+
73+
### Compare the contents of two libraries
74+
75+
Unpack two libraries and compare the individual files: `cmplib.sh`
76+
77+
```bash
78+
#!/bin/sh
79+
80+
rm -rf a b
81+
mkdir a b
82+
(cd a; ar x ../$1)
83+
(cd b; ar x ../$2)
84+
diff -r a b
85+
```
86+
87+
### Determine the CPU dependencies within a Makefile
88+
89+
```make
90+
DEPS=$(shell sdcc -mstm8 -Iinc -Isrc -D$(CPU) "-Wp-MM" -E inc/stm8s.h)
91+
HFILES = $(subst inc/,,$(filter inc/stm8s_%.h,$(DEPS)))
92+
93+
$(info DEPS=$(DEPS))
94+
$(info HFILES=$(HFILES))
95+
```
96+
(now use HFILES to generate list of C-files into LIBSOURCES)
97+
98+
If all source files are already split into single-function source files
99+
this could be used to compile only the modules needed for the current CPU:
100+
101+
```make
102+
# include all parts for every needed module in the LIBSOURCES list
103+
find_files = $(wildcard $(module)-*)
104+
SOURCES := $(foreach module,$(LIBSOURCES),$(find_files))
105+
# if only the needed modules got split: This simple version is good enough
106+
#SOURCES := $(wildcard stm8s*.c)
107+
108+
OBJECTS=$(SOURCES:.c=.o)
109+
OBJECTS_LINK=$(SOURCES:.c=.rel)
110+
EXECUTABLE=$(shell echo $(CPU)|tr '[:upper:]' '[:lower:]').lib
111+
112+
# test output
113+
$(info LIBSCOMMON: $(LIBSCOMMON))
114+
$(info LIBSOURCES: $(LIBSOURCES))
115+
#$(info SOURCES: $(SOURCES))
116+
$(info EXECUTABLE: $(EXECUTABLE))
117+
118+
119+
# targets
120+
nothing:
121+
122+
all: $(SOURCES) $(EXECUTABLE)
123+
echo $^
124+
125+
$(EXECUTABLE): $(OBJECTS)
126+
$(AR) $(LDFLAGS) $(EXECUTABLE) $(OBJECTS_LINK)
127+
128+
.c.o:
129+
$(CC) $(CFLAGS) $< -o $@
130+
131+
clean:
132+
rm -f *.lib *.rst *.rel *.lst *.ihx *.sym *.asm *.lk *.map
133+
rm -f $(EXECUTABLE)
134+
```
135+
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
3+
## parameter check
4+
5+
if [ $# -ne 1 ]; then
6+
cat << EOF
7+
split the library into individual source files for every single function,
8+
compile them seperately and pack them all together into one big library.
9+
10+
usage: $0 cputype
11+
12+
supported cpu types:
13+
Low density devices: STM8S003, STM8S103
14+
Medium density devices: STM8S005, STM8S105, STM8AF626x
15+
High density devices without CAN: STM8S007, STM8S207, STM8AF62Ax
16+
High density devices with CAN: STM8S208, STM8AF52Ax
17+
App. specific low density devices:STM8S903, STM8AF622x
18+
EOF
19+
exit 1
20+
fi
21+
22+
CPU=$1
23+
24+
25+
### main part starts here
26+
27+
28+
# define the compile parameter
29+
CC="sdcc"
30+
AR="sdar"
31+
CFLAGS="-mstm8 -D${CPU} -I ../inc -I ../src --opt-code-size -I."
32+
LDFLAGS="-rc"
33+
34+
BUILDDIR="build-${CPU}"
35+
36+
37+
38+
# name of the library: $CPU.lib in lower case
39+
LIBRARY=$(echo ${CPU}|tr '[:upper:]' '[:lower:]').lib
40+
41+
# check the dependencies, generate the list of needed c source files
42+
HFILES=$($CC -mstm8 -Iinc -Isrc -D$CPU "-Wp-MM" -E inc/stm8s.h|fmt -1|sed -n 's, *inc/stm8s_,stm8s_,p')
43+
CFILES=${HFILES//.h/.c}
44+
45+
# debug output
46+
echo "Needed source code modules for CPU $CPU:"
47+
echo $CFILES
48+
echo "Library name: $LIBRARY"
49+
echo "cflags: $CFLAGS"
50+
51+
52+
# the most important function: split on c source file in to a collection
53+
# of single-function source files.
54+
splitit() {
55+
awk "/\/\*\*\r/{n++; file=\"$1-\" n \".c\";print \"#include \\\"$1.h\\\"\">file}{print >file }" ../src/$1
56+
sed "1 d" $1-1.c > $1.h
57+
rm $1-1.c
58+
}
59+
60+
61+
# prepare a fresh build directory
62+
#BUILDDIR=$(mktemp -dp.)
63+
rm -rf $BUILDDIR
64+
mkdir $BUILDDIR
65+
cd $BUILDDIR
66+
echo "using $BUILDDIR"
67+
68+
# split all needed source files into single-function source files
69+
for i in $CFILES; do
70+
splitit $i;
71+
done
72+
73+
# compile all split files
74+
#cp ../compilelib.mk Makefile
75+
#make CPU=$CPU
76+
for i in stm8s*.c; do
77+
echo "compiling $i"
78+
${CC} ${CFLAGS} -c $i || break
79+
done
80+
81+
# build the library
82+
${AR} ${LDFLAGS} ../lib/${LIBRARY} *.rel
83+
84+
# get the generated library
85+
#mv *.lib ..
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff --git a/STM8S_StdPeriph_Driver/src/stm8s_conf.h b/STM8S_StdPeriph_Driver/src/stm8s_conf.h
2+
index 111047b..152fdfb 100644
3+
--- a/STM8S_StdPeriph_Driver/src/stm8s_conf.h
4+
+++ b/STM8S_StdPeriph_Driver/src/stm8s_conf.h
5+
@@ -56,14 +56,14 @@
6+
#include "stm8s_rst.h"
7+
#include "stm8s_spi.h"
8+
#include "stm8s_tim1.h"
9+
-#if !defined(STM8S903) || !defined(STM8AF622x)
10+
+#if !defined(STM8S903) && !defined(STM8AF622x)
11+
#include "stm8s_tim2.h"
12+
#endif /* (STM8S903) || (STM8AF622x) */
13+
#if defined(STM8S208) || defined(STM8S207) || defined(STM8S007) ||defined(STM8S105) ||\
14+
defined(STM8S005) || defined (STM8AF52Ax) || defined (STM8AF62Ax) || defined (STM8AF626x)
15+
#include "stm8s_tim3.h"
16+
#endif /* (STM8S208) ||defined(STM8S207) || defined(STM8S007) ||defined(STM8S105) */
17+
-#if !defined(STM8S903) || !defined(STM8AF622x)
18+
+#if !defined(STM8S903) && !defined(STM8AF622x)
19+
#include "stm8s_tim4.h"
20+
#endif /* (STM8S903) || (STM8AF622x) */
21+
#if defined(STM8S903) || defined(STM8AF622x)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
STM8S208.lib
282 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
STM8S005.lib
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
STM8S007.lib
273 KB
Binary file not shown.
304 KB
Binary file not shown.
312 KB
Binary file not shown.

0 commit comments

Comments
 (0)