-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen-pac.sh
executable file
·59 lines (45 loc) · 1.23 KB
/
gen-pac.sh
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
#!/bin/sh -e
EX_USAGE=64
print_usage() {
echo 'Usage: gen-pac.sh MCU_NAME' >&2
}
if [ $# -ne 1 ]; then
print_usage
exit $EX_USAGE
fi
mcu_name=$1
BUILD_DIR=${BUILD_DIR:-build}
pac_path=$BUILD_DIR/pacs/${mcu_name}-lpa
# Create a clean directory for the PAC.
rm -rf "$pac_path"
mkdir -p "$pac_path"
# Generate the crate metadata from the templates.
find pac-template -exec sh -ec "
path=\$1
path_no_pac_template=\${path#pac-template/}
if [ \"\$path_no_pac_template\" = \"\$path\" ]; then
exit
fi
path=\$path_no_pac_template
if [ -d \"\$1\" ]; then
mkdir -p \"$pac_path/\$path\"
else
path_no_jinja=\${path%.jinja}
if [ \"\$path_no_jinja\" != \"\$path\" ]; then
path=\$path_no_jinja
jinja2 --strict -o \"$pac_path/\$path\" \"\$1\" \\
\"pac-metadata/$mcu_name.toml\"
else
cp \"\$1\" \"$pac_path/\$path\"
fi
fi
" sh {} \;
# Generate the crate source code from the SVD file.
svd2rust -i "build/svds/${mcu_name}.svd" --target none --atomics \
--atomics-feature atomic --impl_debug --impl-defmt defmt -o "$pac_path"
# Format the source code.
cd "$pac_path"
mkdir src
form -i lib.rs -o src/
rm lib.rs
cargo fmt