Skip to content

Commit e378839

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

File tree

1 file changed

+204
-0
lines changed

1 file changed

+204
-0
lines changed

CI/utils/gen_wrapper.sh

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

0 commit comments

Comments
 (0)