2026-08-10 23:36:24 +08:00
2026-08-10 23:36:24 +08:00
2026-08-10 23:36:24 +08:00
2026-08-10 23:36:24 +08:00
2026-08-10 23:36:24 +08:00
2026-08-10 23:36:24 +08:00
2026-08-10 23:36:24 +08:00
2026-08-10 23:36:24 +08:00
2026-08-10 23:36:24 +08:00

stm32f103_spl_clion

STM32F103C8T6 标准外设库StdPeriph V3.5.0)工程,基于 CLion + CMake + arm-none-eabi-gcc 工具链。

  • MCUSTM32F103C8T6Cortex-M3Medium density64K Flash / 20K RAM
  • ST 标准外设库 V3.5.0SPL
  • 工具链GNU Tools for STM32arm-none-eabi-gcc 13.3
  • 构建CMake + Ninja
  • 烧录/调试ST-LinkSWDSTM32CubeProgrammer + ST-LINK_gdbserver

目录结构

stm32f103_spl_clion/
├── CMakeLists.txt              # 工程主构建文件
├── CMakePresets.json           # Debug/Release 预设CLion 零配置打开)
├── STM32F103XX_FLASH.ld        # 链接脚本64K Flash / 20K RAM
├── cmake/
│   └── gcc-arm-none-eabi.cmake # 交叉工具链定义(-mcpu=cortex-m3, gc-sections 等)
├── CMSIS/                      # 内核与启动文件
│   ├── startup_stm32f10x_md.s  # GCC 版启动文件Medium density对应 C8T6
│   ├── core_cm3.{c,h}
│   ├── stm32f10x.h
│   └── system_stm32f10x.{c,h}
├── StdPeriph_Driver/           # 标准外设库 V3.5.0
│   ├── inc/                    # 23 个外设头文件
│   └── src/                    # 23 个外设源文件(未引用的会被 --gc-sections 自动裁掉)
├── User/                       # 用户代码
│   ├── main.c                  # 示例PC13 LED 闪烁
│   └── stm32f10x_conf.h        # SPL 配置(包含所有外设头)
└── tools/
    ├── flash.sh                # 一键 configure -> build -> 烧录 -> 复位
    └── debug-server.sh         # 启动 ST-LINK GDB Server端口 61234

一、在 CLion 中打开

  1. File → Open 选择本目录CLion 自动识别 CMakeLists.txt + CMakePresets.json
  2. Settings → Build, Execution, Deployment → Toolchains
    • 添加一个工具链Debugger 选 arm-none-eabi-gdb(通常 CLion 会自动发现 CubeCLT 工具链)。
  3. Settings → Build, Execution, Deployment → CMake
    • Debug profile 的配置类型会读取 CMakePresets.jsonDebug 预设,无需手填 toolchain file。
  4. 加载完成后,右上角可直接 Build,产物为 build/Debug/stm32f103_spl_clion.elf

二、编译

  • CLion:点 Build 按钮。
  • 命令行
    cmake --preset Debug
    cmake --build --preset Debug
    
  • 一键脚本(命令行,自包含 configure+build+flash
    bash tools/flash.sh
    

    注意:flash.sh 使用独立的 build/ 目录;若想烧录 CLion 的产物,用下面的方式。

  • CLion 内烧录:安装 STM32CubeProgrammer / OpenOCD 插件后配置 Run。
  1. 接好 ST-LinkSWD给板子供电。
  2. 终端启动 GDB Server
    bash tools/debug-server.sh   # 监听 localhost:61234under-reset 模式
    
  3. CLion 中新建 Embedded GDB Server 调试配置:
    • Targetstm32f103_spl_clion.elf
    • GDBarm-none-eabi-gdb
    • 连接:target remote localhost:61234
  4. 点 Debug可下断点、单步。

修改工程名

工程名集中在两处:CMakeLists.txtCMAKE_PROJECT_NAMEtools/flash.shELF

Description
No description provided
Readme 376 KiB
Languages
C 99.1%
Assembly 0.6%
CMake 0.2%
Shell 0.1%