CLion 2022.1 Help

PlatformIO

PlatformIO is an open-source ecosystem for embedded development. It allows working with various MCUs (such as ARM Cortex, AVR, MSP430), development boards, frameworks, and environments (Arduino, ESP-IDF, and many others).

CLion's integration with PlatformIO is provided by the PlatformIO for CLion plugin, created in collaboration with the PlatformIO team.

Installation

Install PlatformIO

  1. Refer to the official guide for details of the installation procedure.

  2. As you will be using PlatformIO in CLion, make sure to install Shell commands.

Install the PlatformIO plugin

  1. Go to Settings / Preferences | Plugins and switch to Marketplace.

  2. Search for PlatformIO for CLion and click Install.

  3. You will be prompted to install the Ini plugin, which provides code insight for platformio.ini files. Click Install.

  4. After the installation is finished, click Restart IDE.

Creating a project

  1. Call File | New Project from the main menu and select PlatformIO in the left-hand pane.

  2. Set the project name, choose a board or framework, and click Create.

    New project wizard for Platformio

CLion will generate a PlatformIO CMake-base project, calling the proper PlatformIO command in the background:

New PlatformIO project generation

For Arduino-based boards, CLion generates main.cpp instead of main.c and fills it with Arduino-specific stub code:

Arduino-specific source stub

CMake profiles

CLion automatically creates CMake profiles for the corresponding CMAKE_CONFIGURATION_TYPES entries. To configure the profiles, go to Settings / Preferences | Build, Execution, Deployment | CMake:

CMake profile for a PlatformIO project

Notice that Build type corresponds to the PlatformIO environment in use.

The directory specified in Build directory is used for storing CMake build artifacts (in our example, it is called cmake-build-eval_l073z). This directory is excluded from project indexing and is highlighted accordingly in the project tree:

Build folder excluded

Run/debug configurations

When you create or open a PlatformIO project, configurations for upload and debug are created automatically:

Automatically created configurations

Add PlatformIO configurations

  1. Select Edit Configurations in the switcher or call Run | Edit Configurations from the main menu.

  2. In the left-hand pane, click App general add and select the PlatformIO node. Choose among the configuration types:

    PlatformIO configurations

    Configuration

    Description

    Debug

    Starts a debug session with PIO Unified Debugger by calling platformio debug.

    All the CLion debug features are available, including peripheral registers view, memory view, and disassembly.

    Program

    Uploads the firmware using a programmer.

    Test

    Runs the project's unit tests by calling platformio test.

    Upload

    Uploads the firmware by calling platformio run -t upload.

    Upload fs

    Uploads the firmware to file system SPIFFS by calling platformio run -t uploadfs.

  3. Set the configuration name and click Apply.

Note that all PlatformIO configurations include Build as a pre-launch step. If you need to build the project separately, select a configuration in the Edit Configurations dialog and remove (Remove) the Build step in the Before launch area.

PlatformIO actions

Besides the run/debug configurations, a few PlatformIO commands are also available as IDE actions. Use Tools | PlatformIO on the main menu or right-click platformio.ini in the Project tree and select the PlatformIO node:

PlatformIO actions

  • Build Production - calls platformio run to build the project in release configuration.

  • Build - calls platformio run --target debug to build the project with debug information and all optimizations turned off.

  • Clean - calls platformio run --target clean.

  • Check - calls platformio check for static code analysis.

  • Re-Init - calls platformio init. Use this action to update your project following the changes in platformio.ini.

  • Update All - calls platformio update.

  • Monitor - calls platformio device moitor.

  • Home - calls platformio home and opens PlatformIO Home in your browser.

Code assistance in platformio.ini

The Ini plugin, which comes in pair with the PlatformIO plugin, provides syntax highlighting, code formatting, and structure view for .ini files.

To open the structure view for platformio.ini, open it in the editor and then select View | Tool Windows | Structure from the main menu or press Ctrl+F12.

You can navigate to a property via Go to Symbol (Ctrl+Alt+Shift+N or Navigate | Symbol on the main menu).

Code assistance for ini files

Also, the Ini plugin provides inspections for detecting duplicate properties and sections. You can change the severity of these inspections and turn them on/off in Settings / Preferences | Editor | Inspections | Ini files.

Last modified: 25 July 2022