38 lines
1.2 KiB
Bash
38 lines
1.2 KiB
Bash
#!/usr/bin/env bash
|
|
# ============================================================
|
|
# 一键: configure (首次) -> build -> flash -> reset & run
|
|
# 调试器: ST-Link / J-Link / DAP-Link 均可 (走 SWD)
|
|
# 产物: build/stm32f103_spl_clion.elf
|
|
# ============================================================
|
|
set -e
|
|
|
|
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
CLT="/c/ST/STM32CubeCLT_1.18.0"
|
|
CMAKE="$CLT/CMake/bin/cmake.exe"
|
|
NINJA="$CLT/Ninja/bin/ninja.exe"
|
|
PROG="$CLT/STM32CubeProgrammer/bin/STM32_Programmer_CLI.exe"
|
|
BUILD="$ROOT/build"
|
|
ELF="$BUILD/stm32f103_spl_clion.elf"
|
|
TOOLCHAIN_FILE="$ROOT/cmake/gcc-arm-none-eabi.cmake"
|
|
|
|
# ---- 1. 首次 configure (生成 build.ninja) ----
|
|
if [ ! -f "$BUILD/build.ninja" ]; then
|
|
echo "==[ 1/3 configure ]=="
|
|
"$CMAKE" -S "$ROOT" -B "$BUILD" -G Ninja \
|
|
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN_FILE" \
|
|
-DCMAKE_MAKE_PROGRAM="$NINJA" \
|
|
-DCMAKE_BUILD_TYPE=Debug
|
|
else
|
|
echo "==[ 1/3 configure ]== (skipped, build/ 已存在)"
|
|
fi
|
|
|
|
# ---- 2. 编译 ----
|
|
echo "==[ 2/3 build ]=="
|
|
"$CMAKE" --build "$BUILD" --config Debug
|
|
|
|
# ---- 3. 烧录 + 校验 + 复位运行 ----
|
|
echo "==[ 3/3 flash ]=="
|
|
"$PROG" -c port=swd -w "$ELF" -v -rst
|
|
|
|
echo "==[ done: 已烧录并复位运行 ]=="
|