Skip to content

Commit e94549b

Browse files
committed
Add scripts to wrap files
This scripts generates wrapping for: * HAL/LL c sources * LL headers * CMSIS startup Signed-off-by: Frederic Pillon <[email protected]>
1 parent 53508b1 commit e94549b

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed

CI/utils/gen_wrapper.sh

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#!/bin/bash -
2+
set -o nounset # Treat unset variables as an error
3+
4+
Core_path=../..
5+
SrcWrapper_path=$Core_path/libraries/SrcWrapper
6+
HALDrivers_path=$Core_path/system/Drivers
7+
CMSIS_path=$Core_path/system/Drivers/CMSIS
8+
9+
# Sources files
10+
HALoutSrc_path=$SrcWrapper_path/src/HAL
11+
LLoutSrc_path=$SrcWrapper_path/src/LL
12+
# Include files
13+
LLoutInc_path=$Core_path/cores/arduino/stm32/LL
14+
15+
CMSIS_Startupfile=$Core_path/cores/arduino/stm32/stm32_def_build.h
16+
17+
series=(`ls -d $HALDrivers_path/STM32*/ | sed -e "s#$HALDrivers_path/STM32##g" | sed -e "s#xx_HAL_Driver/##g"`)
18+
all_LL_file=stm32yyxx_ll.h
19+
20+
21+
# Create the file
22+
print_C_header() {
23+
if [[ $1 = *"template"* ]]; then
24+
echo "#if 0" > $1
25+
else
26+
touch $1
27+
fi
28+
}
29+
30+
# Add some pragma to ll header files to avoid several warnings
31+
# which will be corrected along Cube update
32+
print_LL_header() {
33+
upper=`echo $1 | awk '{print toupper($1)}' | sed -e "s/\./_/g"`
34+
echo "#ifndef _${upper}_
35+
#define _${upper}_
36+
/* LL raised several warnings, ignore them */
37+
#pragma GCC diagnostic push
38+
#pragma GCC diagnostic ignored \"-Wunused-parameter\"
39+
#pragma GCC diagnostic ignored \"-Wstrict-aliasing\"
40+
" > $LLoutInc_path/$1
41+
}
42+
43+
print_CMSIS_Startup_header() {
44+
echo "#ifndef _STM32_DEF_BUILD_
45+
#define _STM32_DEF_BUILD_
46+
47+
#if !defined(CMSIS_STARTUP_FILE) && !defined(CUSTOM_STARTUP_FILE)" > $CMSIS_Startupfile
48+
}
49+
50+
print_CMSIS_Startup_footer() {
51+
echo "#else
52+
#error UNKNOWN CHIP
53+
#endif
54+
#else
55+
#warning \"No CMSIS startup file defined, custom one should be used\"
56+
#endif /* !CMSIS_STARTUP_FILE && !CUSTOM_STARTUP_FILE */
57+
#endif /* _STM32_DEF_BUILD_ */" >> $CMSIS_Startupfile
58+
}
59+
60+
print_CMSIS_Startup_list() {
61+
# Handle first elements
62+
# File name
63+
local f=`echo ${list[0]} | awk -F/ '{print $NF}'`
64+
local upper=`echo $f | awk -F'[_.]' '{print toupper($2)}' | tr X x`
65+
echo "#if defined($upper)
66+
#define CMSIS_STARTUP_FILE \"$f\"" >> $CMSIS_Startupfile
67+
68+
if [ ${#list[@]} -gt 1 ]; then
69+
for fp in ${list[@]:1}
70+
do
71+
# File name
72+
f=`echo $fp | awk -F/ '{print $NF}'`
73+
upper=`echo $f | awk -F'[_.]' '{print toupper($2)}' | tr X x`
74+
echo "#elif defined($upper)
75+
#define CMSIS_STARTUP_FILE \"$f\"" >> $CMSIS_Startupfile
76+
done
77+
fi
78+
}
79+
80+
# main
81+
# Check if this is the right place
82+
if [ ! -d $HALDrivers_path ]; then
83+
echo "Could not find $HAL_outSrcpath!"
84+
echo "Launch $0 from scripts folder!"
85+
exit 1
86+
fi
87+
88+
# Remove old file
89+
rm -f $HALoutSrc_path/* $LLoutSrc_path/* $LLoutInc_path/* $CMSIS_Startupfile
90+
91+
# Search all files for each series
92+
for serie in ${series[@]}
93+
do
94+
if [ -d $HALDrivers_path/STM32${serie}xx_HAL_Driver/Src ]; then
95+
lower=`echo $serie | awk '{print tolower($0)}'`
96+
echo -n "Generating for $serie..."
97+
98+
# Generate stm32yyxx_[hal|ll]*.c file
99+
filelist=(`find $HALDrivers_path/STM32${serie}xx_HAL_Driver/Src -maxdepth 1 -name "stm32${lower}xx_*.c"`)
100+
for fp in ${filelist[@]}
101+
do
102+
outp=$HALoutSrc_path
103+
# File name
104+
f=`echo $fp | awk -F/ '{print $NF}'`
105+
# Compute generic file name
106+
g=`echo $f | sed -e "s/$lower/yy/g"`
107+
if [[ $f = *"_ll_"* ]]; then
108+
outp=$LLoutSrc_path
109+
fi
110+
if [ ! -f $outp/$g ]; then
111+
print_C_header $outp/$g
112+
fi
113+
# Amend file name under serie switch
114+
echo "#ifdef STM32${serie}xx" >> $outp/$g
115+
echo "#include \"$f\"" >> $outp/$g
116+
echo "#endif" >> $outp/$g
117+
done
118+
119+
# Generate stm32yyxx_ll_*.h file
120+
filelist=(`find $HALDrivers_path/STM32${serie}xx_HAL_Driver/Inc -maxdepth 2 -name "stm32${lower}xx_ll_*.h"`)
121+
for fp in ${filelist[@]}
122+
do
123+
# File name
124+
f=`echo $fp | awk -F/ '{print $NF}'`
125+
# Compute generic file name
126+
g=`echo $f | sed -e "s/$lower/yy/g"`
127+
128+
if [ ! -f $LLoutInc_path/$g ]; then
129+
print_LL_header $g
130+
fi
131+
# Amend full LL header file
132+
echo "#include \"$g\"" >> $LLoutInc_path/${all_LL_file}.tmp
133+
# Amend file name under serie switch
134+
echo "#ifdef STM32${serie}xx" >> $LLoutInc_path/$g
135+
echo "#include \"$f\"" >> $LLoutInc_path/$g
136+
echo "#endif" >> $LLoutInc_path/$g
137+
done
138+
echo "done"
139+
fi
140+
done
141+
142+
# Filter full LL header file
143+
if [ ! -f $LLoutInc_path/$all_LL_file ]; then
144+
print_LL_header $all_LL_file
145+
fi
146+
echo "/* Include Low Layers drivers */" >> $LLoutInc_path/${all_LL_file}
147+
sort -u $LLoutInc_path/${all_LL_file}.tmp >> $LLoutInc_path/${all_LL_file}
148+
rm -f $LLoutInc_path/${all_LL_file}.tmp
149+
150+
# Search all template file to end "#if 0"
151+
filelist=(`find $HALoutSrc_path -maxdepth 1 -name "stm32*_template.c"`)
152+
for fp in ${filelist[@]}
153+
do
154+
echo "#endif /* 0 */" >> $fp
155+
done
156+
157+
# Search all LL header files to end guard
158+
filelist=(`find $LLoutInc_path -maxdepth 1 -name "stm32yyxx_ll*.h"`)
159+
for fp in ${filelist[@]}
160+
do
161+
upper=`basename $fp | awk '{print toupper($1)}' | sed -e "s/\./_/g"`
162+
echo "#pragma GCC diagnostic pop" >> $fp
163+
echo "#endif /* _${upper}_ */" >> $fp
164+
done
165+
166+
# CMSIS startup files
167+
list=(`find $CMSIS_path -name "startup_*.s" | grep gcc | sort -u`)
168+
if [ ${#list[@]} -ne 0 ]; then
169+
echo "Number of startup files: ${#list[@]}"
170+
print_CMSIS_Startup_header
171+
print_CMSIS_Startup_list
172+
print_CMSIS_Startup_footer
173+
else
174+
echo "No startup files found!"
175+
fi

0 commit comments

Comments
 (0)