-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstb.sh
More file actions
executable file
·112 lines (93 loc) · 2.83 KB
/
stb.sh
File metadata and controls
executable file
·112 lines (93 loc) · 2.83 KB
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
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_FILE="$SCRIPT_DIR/$CONFIG_NAME"
#--Functions-------------------------------------------------------------------
create_pase_folders_structure() {
if [ -z "$PROJECT_NAME" ]; then PROJECT_NAME="project"; fi
echo "Creating project: $PROJECT_NAME"
mkdir -p "$PROJECT_NAME"/{app,build,config,submodules}
mkdir -p "$PROJECT_NAME/platform"/{linker,startup,cmsis,hal}
mkdir -p "$PROJECT_NAME/platform/hal"/{Src,Inc}
mkdir -p "$PROJECT_NAME/app"/{src,inc}
touch "$PROJECT_NAME/app"/src/main.c
touch "$PROJECT_NAME/app"/inc/main.h
}
get_config_name() {
if [ -z "$1" ]; then
echo "The name of the custom .toml config file is not specified"
exit 1
fi
if [ "$CONFIG_NAME" != "$1" ]; then
CONFIG_NAME=$1
fi
}
sync_hal() {
local path="$1"
local modules="$2"
if [ -z "$path" ]; then
echo "Skip HAL: path not set"
return 1
return
fi
for mod in ${modules//,/ }; do
cp "$path/Src/${FAMILY}_hal_$mod.c" "$PROJECT_NAME/platform/hal/Src/"
cp "$path/Inc/${FAMILY}_hal_$mod.h" "$PROJECT_NAME/platform/hal/Inc/"
done
#cp "$path/Src/system_${FAMILY}.c" "$PROJECT_NAME/platform/hal/Src/"
}
sync_cmsis() {
local path="$1"
if [ -z "$path" ]; then
echo "Skip CMSIS: path not set"
return 1
return
fi
cp -r "$path/Core/Include/"* "$PROJECT_NAME/platform/cmsis/"
}
add_deps() {
grep "http" "$CONFIG_FILE" | cut -d'=' -f2 | tr -d '" ' | while read -r url; do
git submodule add "$url" libs/"$(basename "$url")"
done
}
parse_config() {
local current_section=""
while IFS= read -r line || [ -n "$line" ]; do
line=$(echo "$line" | sed 's/#.*//; s/^[[:space:]]*//; s/[[:space:]]*$//')
[ -z "$line" ] && continue
if [[ "$line" =~ ^\[(.*)\]$ ]]; then
current_section="${BASH_REMATCH[1]//./_}"
continue
fi
if [[ "$line" =~ ^(.*)=(.*)$ ]]; then
local key val
key=$(echo "${BASH_REMATCH[1]}" | tr -d '[:space:]')
val=$(echo "${BASH_REMATCH[2]}" | tr -d '[:space:][]"' )
if [ -n "$current_section" ]; then
export "${current_section}_${key}"="$val"
else
export "${key}"="$val"
fi
fi
done < "$CONFIG_FILE"
}
#------------------------------------------------------------------------------
CONFIG_NAME="${1:-stb.toml}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_FILE="$SCRIPT_DIR/$CONFIG_NAME"
if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: $CONFIG_FILE not found"
exit 1
fi
parse_config
PROJECT_NAME="${project:-stb_project}"
MCU="${device_mcu:-}"
case "$MCU" in
stm32f4*) FAMILY="stm32f4xx" ;;
stm32l4*) FAMILY="stm32l4xx" ;;
stm32f1*) FAMILY="stm32f1xx" ;;
*) echo "Unknown MCU: $MCU"; exit 1 ;;
esac
create_pase_folders_structure
sync_hal "$layers_hal_path" "$layers_hal_modules"
sync_cmsis "$layers_cmsis_path"
add_deps