# PlatformIO

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

> **TL;DR**
> 操作系统 ：Windows、Linux、macOS
>
>
>
> PlatformIO for CLion 插件 ：已集成

[PlatformIO](https://platformio.org/) 是一个用于嵌入式开发的开源生态系统。 它支持与多种 MCU，如 ARM Cortex、AVR、MSP430，还支持开发板、框架和环境，包括 Arduino 和 ESP-IDF。

CLion 对 PlatformIO 的集成由 [CLion 的 PlatformIO](https://plugins.jetbrains.com/plugin/13922-platformio-for-clion) 插件提供，该插件是与 PlatformIO 团队合作创建的。 它已与 IDE 集成，无需单独安装。

## 安装 PlatformIO

* 要安装 PlatformIO，请使用 [安装脚本](https://docs.platformio.org/en/latest/core/installation/methods/installer-script.html#super-quick-macos-linux) 或其他 [安装选项](https://docs.platformio.org/en/latest/core/installation.html#core-installation)。

* 请确保 [安装 Shell 命令](https://docs.platformio.org/en/latest/core/installation/shell-commands.html)。

## 创建或打开 PlatformIO 项目

Procedure: 创建新项目

1. 从主菜单调用  `文件 | 新建项目`  并在左侧窗格中选择   PlatformIO  。

2. 设置项目名称，选择一个开发板或框架，然后点击   创建  。

![PlatformIO 项目向导](https://resources.jetbrains.com/help/img/idea/2026.3/cl_platformio_newprj_upd.png)

3. CLion 将生成一个 PlatformIO 项目：

![新 PlatformIO 项目生成](https://resources.jetbrains.com/help/img/idea/2026.3/cl_platformio_init_upd.png)

对于基于 Arduino 的开发板，CLion 会生成  `main.cpp`  而不是  `main.c` ，并用 Arduino 特定的存根代码填充它：

![Arduino 特定的源代码存根](https://resources.jetbrains.com/help/img/idea/2026.3/cl_platformio_arduino_stub_upd.png)

Procedure: 打开项目

1. 请点击   打开   在 [欢迎屏幕](welcome-screen.html)或从主菜单中选择  `文件 | 打开` 。

2. 导航到项目文件夹并选择  `platformio.ini`  文件。

3. 点击   作为项目打开  。

> **Note:**
> 当您打开一个之前生成的基于 CMake 的 PlatformIO 项目时，系统会提示您将其转换为新结构。
>
>
>
> 如果转换失败，请关闭项目，删除项目根目录下的  `.idea`  文件夹，然后重新打开项目。

## PlatformIO 操作

多个 [PlatformIO 命令](https://docs.platformio.org/en/latest/core/userguide/index.html#commands) 可作为 IDE 操作使用。 在主菜单中，转到  `工具 | PlatformIO`  或右键点击项目树中的  `platformio.ini`  并选择   PlatformIO   节点：

![PlatformIO 操作](https://resources.jetbrains.com/help/img/idea/2026.3/cl_platformio_actions_upd.png)

* 重新加载 PlatformIO 项目 - 调用 [pio project init](https://docs.platformio.org/en/latest/core/userguide/project/cmd_init.html)。 使用此操作根据 `platformio.ini` 中的更改更新您的项目。

* 静态代码分析 - 调用 [pio check](https://docs.platformio.org/en/latest/core/userguide/cmd_check.html) 进行静态代码分析。

* PlatformIO 串口监视器 - 调用 [pio device monitor](https://docs.platformio.org/en/latest/core/userguide/device/cmd_monitor.html)。

* 更新平台、工具链等 - 调用 [pio pkg update](https://docs.platformio.org/en/latest/core/userguide/cmd_update.html)。

* PlatformIO 主页 - 调用 `pio home` 并在浏览器中打开 [PlatformIO Home](https://docs.platformio.org/en/latest/home/)。

> **Tip:**
> 您还可以从 CLion 的 [内置终端](terminal-emulator.html) 运行 PlatformIO 命令。

## PlatformIO 工具窗口

PlatformIO 工具窗口提供了快速访问最常用命令和项目操作的功能。

![PlatformIO 工具窗口](https://resources.jetbrains.com/help/img/idea/2026.3/cl_platformio_toolwindow_upd.png)

将鼠标悬停在某个操作上以查看相应的命令：

![PlatformIO 工具窗口中命令的工具提示](https://resources.jetbrains.com/help/img/idea/2026.3/cl_platformio_toolwindow_tooltips_upd.png)

在底部，您可以找到 COM 端口切换器。 如果您不想依赖自动端口检测，可以使用它来配置上传的 COM 端口号。

## 调试功能

调试   操作通过调用  `pio debug`  启动一个使用 [PIO Unified Debugger](https://docs.platformio.org/en/latest/plus/debugging.html#piodebug) 的调试会话。

所有 CLion 的 [调试功能](debugging-code.html) 都可用，包括 [外设寄存器视图](peripheral-view.html)、 [内存视图](memory-view.html) 和 [反汇编](disassembly-view.html)。

如果给定平台有  `.svd`  文件，CLion 将自动加载它。 您也可以手动指定它：

![指定 .svd 文件](https://resources.jetbrains.com/help/img/idea/2026.3/cl_platformio_loadsvd_upd.png)

## 在 platformio.ini 中的代码辅助

与 PlatformIO 插件配套的   Ini   插件为  `.ini`  文件提供语法高亮、代码格式化和 [结构视图](file-structure.html)。

要打开  `platformio.ini`  的结构视图，请在编辑器中打开它，然后从主菜单中选择  `视图 | 工具窗口 | 结构`  或按 `Ctrl+F12` (Windows), `⌘ F12` (macOS), `⌘ F12` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ 7` (macOS System Shortcuts), `Ctrl+F12` (XWin), `Ctrl+F12` (GNOME), `Ctrl+0` (KDE), `Ctrl+F12` (Emacs), `Ctrl+R` (Sublime Text), `⌘ R` (Sublime Text (macOS)), `⌃ 6` (Xcode), `Alt+\` (Visual Studio), `⌥ \` (Visual Studio (macOS)), `Ctrl+F12` (ReSharper), `⌘ F12` (ReSharper (macOS)), `Ctrl+F12` (QtCreator), `⌘ F12` (QtCreator (macOS)), `Ctrl+F12` (NetBeans), `Ctrl+F3` (Eclipse), `⌘ O` (Eclipse (macOS))。

您可以通过   转到符号  （主菜单中的 `Ctrl+Alt+Shift+N` (Windows), `⌘ ⌥ O` (macOS), `⌘ ⌥ ⇧ N` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ O` (macOS System Shortcuts), `Ctrl+Alt+Shift+N` (XWin), `Ctrl+Alt+Shift+N` (GNOME), `Ctrl+Alt+Shift+N` (KDE), `Ctrl+Alt+Shift+N` (Emacs), `Ctrl+Shift+R` (Sublime Text), `⌘ ⇧ R` (Sublime Text (macOS)), `⌘ ⇧ O` (Xcode), `Ctrl+Alt+Shift+T` (Visual Studio), `⌘ ⌥ ⇧ T` (Visual Studio (macOS)), `Ctrl+Alt+Shift+N` (ReSharper), `⌘ ⌥ ⇧ N` (ReSharper (macOS)), `Ctrl+Alt+Shift+N` (QtCreator), `⌘ ⌥ O` (QtCreator (macOS)), `Ctrl+Alt+Shift+O` (NetBeans), `Ctrl+Alt+Shift+N` (Eclipse), `⌘ ⌥ O` (Eclipse (macOS)) 或  `导航 | 符号` ）导航到某个属性。

![针对 ini 文件的代码辅助](https://resources.jetbrains.com/help/img/idea/2026.3/cl_platformio_inifiles_upd.png)

此外，Ini 插件提供了用于检测重复属性和部分的 [检查](code-inspection.html)。 您可以在  `设置 | 编辑器 | 检查 | Ini 文件`  中更改这些检查的严重性并启用/禁用它们。

## See also

### 流程

[STM32CubeMX 项目](embedded-stm32.html) [IAR 工具链](iar-toolchain.html) [外设视图](peripheral-view.html)

