# OpenOCD 支持

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/clion/llms.txt).

> **TL;DR**
> 操作系统  ：Windows (MinGW 或 MinGW-w64) / Linux / macOS
>
>
>
> 必需工具  ：OpenOCD，交叉编译工具链
>
>
>
> 构建目标  ：CMake / Makefile / 自定义构建目标

如果您的嵌入式目标支持使用 [OpenOCD](http://openocd.org/)（片上调试器）的片上调试，请使用   OpenOCD 下载与运行   配置。 它适用于基于   CMake   的项目，包括 [STM32CubeMX](embedded-stm32.html) 的情况，以及 [Makefile 项目](makefiles-support.html) 和 [自定义构建目标](custom-build-targets.html)。

> **Note:**
> 您还可以使用本文中描述的替代方法设置 OpenOCD 服务器。 [Debug Servers](debug-servers.html) 配置选项提供了一种更方便的方式来配置各种 gdbserver 并将其与构建目标结合。

Procedure: 必需工具

所有平台:

1.

[OpenOCD](https://openocd.org/pages/getting-openocd.html)

OpenOCD 将用作闪存探针和远程 [gdbserver](https://sourceware.org/gdb/onlinedocs/gdb/Server.html)。

在  `设置 | 构建、执行、部署 | 嵌入式开发`  中，您可以检查 OpenOCD 的位置是否被正确检测到，并在需要时手动设置路径。

2.

工具链

您的交叉编译工具链应提前配置好。

* 对于 ARM [Cortex-M](https://developer.arm.com/ip-products/processors/cortex-m) 和 [Cortex-R](https://developer.arm.com/ip-products/processors/cortex-r) MCU，请安装 [GNU ARM toolchain](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm)。 安装后，请确保工具链已添加到系统 PATH 中：从命令行运行 `arm-none-eabi-gcc` ，您的系统应能识别此命令。

* 对于所有其他平台，请安装特定于平台的工具链，并在 `设置 | 构建、执行、部署 | 工具链` 或您的 CMake 脚本中设置工具（请参阅模板 [CMakeLists.txt](https://github.com/elmot/clion-embedded-arm/blob/master/resources/xyz/elmot/clion/cubemx/tmpl_CMakeLists.txt)）。

* 如果您正在处理 [STM32CubeMX 项目](embedded-stm32.html)，那么安装 [STM32CubeCLT](https://www.st.com/en/development-tools/stm32cubeclt.html) 和 [STM32CubeMX](https://www.st.com/en/development-tools/stm32cubemx.html) 是项目设置的一部分，并且 STM32CubeMX 会自动生成链接器文件。

特定于 Windows:

* 除了所有平台所需的工具外，还需安装 [ST-LINK/V2 驱动](https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-utilities/stsw-link009.html#getsoftware-scroll)。

* 对于 GNU ARM 工具链 ，请使用 2019-q3（及更高版本）或 2018-q2（及更早版本）。 请参阅 2018-q4 的 [问题](https://bugs.launchpad.net/gcc-arm-embedded/+bug/1810274)。

* 仅支持 MinGW 和 MinGW-w64 环境（ [CPP-15034](https://youtrack.jetbrains.com/issue/CPP-15034)）。

Procedure: 创建 OpenOCD 配置

1. 转到  `运行 | 编辑配置` ，点击 ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.add.svg) 并从模板列表中选择   OpenOCD 下载与运行  。

> **Tip:**
> 对于 STM32CubeMX 项目，CLion 在项目创建期间会自动添加此类型的配置。

2. 在设置中，您可以选择客户端 GDB 调试器和板配置文件，调整 GDB 和 Telnet 端口，并设置下载/复位选项。

![OpenOCD 运行/调试配置](https://resources.jetbrains.com/help/img/idea/2026.3/cl_embed_openocdconfig.png)

3. 设置板配置文件时，您可以手动提供路径或点击   辅助   并从标准选项中选择：

![板配置选择对话框](https://resources.jetbrains.com/help/img/idea/2026.3/cl_embed_bardconfigs.png)

要根据需要调整板配置文件（例如，当您使用非标准设备或需要保留多个配置文件时），请点击   复制到项目并使用  ：所选文件将被复制到您的项目树中，您可以在编辑器中打开并根据需要修改。

Procedure: 运行/调试 OpenOCD 配置

* 当您   运行   ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.actions.execute.svg) 此配置时，编译后的固件将下载到目标板，然后芯片将复位。

* 当您   调试   ![](https://resources.jetbrains.com/help/img/idea/2026.3/app.actions.startDebugger.svg) 时，固件将被下载，芯片将复位，然后远程调试器将附加到 MCU。

现在，运行在芯片上的固件可以使用 CLion 的完整调试功能进行调试，包括 [内存视图](memory-view.html) 和显示外设寄存器和位的 [外设](peripheral-view.html) 选项卡。

另请注意调试器工具窗口左侧栏上的 ![MCU 复位](https://resources.jetbrains.com/help/img/idea/2026.3/clion-embedded.icons.ResetMcu.png) 按钮。 按下此按钮时，它会发送配置设置的   重置   选项中选择的 [芯片复位命令](http://openocd.org/doc/html/General-Commands.html)。

![调试嵌入式项目](https://resources.jetbrains.com/help/img/idea/2026.3/cl_embed_debug_example.animated.gif)

## See also

### 外部链接

[Embedded Development in CLion FAQs](https://intellij-support.jetbrains.com/hc/en-us/articles/4405160320274-Embedded-Development-in-CLion) [CLion for embedded development, part III](https://blog.jetbrains.com/clion/2019/02/clion-2019-1-eap-clion-for-embedded-development-part-iii/) [CLion for embedded development, part II](https://blog.jetbrains.com/clion/2017/12/clion-for-embedded-development-part-ii/) [CLion for embedded development](https://blog.jetbrains.com/clion/2016/06/clion-for-embedded-development/)

