Official PlatformIO plugin for JetBrains CLion IDE

Hi all,

There is a piece of good news here. We are so happy to present the first MVP of the PlatformIO plugin for CLion. Big thanks to JetBrains CLion Team, especially to @elmot for his amazing work.

This is not the final release. We just want to get some feedback and would be thankful if you help us to build a list with the most important features.

Demo

ESP-32

RISC-V

How to try it?

  1. Install the latest CLion EAP
  2. Download PlatformIO for Clion Plugin
  3. Install the plugin: CLion > Preferences > Plugins > :gear: > Install Plugin from Disk … > Select ZIP archive

  1. Upgrade PlatformIO Core to the latet 4.1.0 or above via pio upgrade.
  2. Generate PlatformIO project for CLion using docs Redirecting...
  3. Open a project with CLion and add PlatformIO to configuration using CLion > Run > Edit Configurations… > [+] > PlatformIO > Give a name PlatformIO Debug

  1. Select “PlatformIO Debug” configuration and press “Debug” icon
    Screen Shot 2019-11-06 at 23 09 31

  2. Happy debugging with PlatformIO and CLion.

Known issue

  1. [R] icon (hot-restart) currently only resets + halts target, and does not move execution to initial breakpoint. This is will be fixed in the next version. A temporary solution is to put breakpoints in the code and press “Continue”.
2 Likes

Hi all,
is there “a button” for the update all libraries in CLION? I don’t find it.

Is there even “a button” for upload all?
I am trying to edit my configuration but I’m not able to upload to all my targets in one button.

Is this possible in CLION?

Hi,

For “update all” button, right click on platformio.ini file in your project, scroll down to “PlatformIO”, and you will see “update all”. (button is also present under “Tools” > “PlatformIO”)

image

For “upload all”, I’m not sure this is possible, because Upload/Debug profile buttons are link to one Cmake Profile, and so one board … Or maybe try create a Cmake special profile for multiple boards ? Not sure if it is possible :confused:

thanks for the answer, I appreciate it.

that “update all” is not the equivalent of the command:
platformio lib update
I am searching for

I am pretty sure that this is configurable in CLION but can’t understand how.

If you really want to, you can “trick” Clion to create a dummy target that will launch this command. To do so, you have to edit the CMakeLists.txt as below, then reload it, and a configuration will be added for your command that you can launch as a button:

But be aware, every time you “re-init” the PIO project, these custom lines will disappear. Not sure if it is a good solution.

1 Like

not that good if this disappear but it’s an idea, thanks :frowning:
is there a better solution?

Good news @sblantipodi, I didn’t read the documentation:

  • Create a new file in the root of your project called “CMakeListsUser.txt”
  • Add the few custom lines of my response above:

add_custom_target(
LibsUpdate
COMMAND platformio lib update
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

  • Re-init PlatformIO

Now the customisation is permanent, you will have the button with your custom command even if the project has to be reload :ok_hand: click on the build button to the left (and not the play button) to execute the command.

1 Like

@copperbot-d thanks for the answer but it does not work, when I try to run that target it says: “Error: Executable is not specified”

That is weird, it works on my side, maybe try to clean Cmake cache ? (Up in Clion: “Tools” > “CMake” > “Reset cache and reload project”)

If not, re-init a second time PIO ? (“Tools” > “PlatformIO” > “re-init”)

If not, try to remove the unnecessary “build” line in the “LibsUpdate” configuration:

  • Go to “Edit Configurations…” in the menu next to build button
  • Select “LibsUpdate” on the left
  • (Be sure no executable is selected next to “Executable:” by the way)
  • Select the “build” line under “Before Launch : Activate Tool windows”
  • Remove it, apply, and try running again LibsUpdate

thanks again for the help.
done it.

the command works ok but than give me an error.

do you have a Z_DUMMY_TARGET in your executable under “Edit Configurations…”?

No, and that could be the problem, because PIO is doing fine, but Clion is trying to compile something that he doesn’t understand.
Try to remove all the CMake Application from the list, because there are not useful for a project with PIO (except LibsUpdate of course), and keep only PIO configurations:
image
Be sure to remove “Z_DUMMY_TARGET” in the Executable for LibsUpdate (select nothing instead).

And be sure to launch the command from left button, not the right one, because Clion will try to compile something on its own if you use the right one:
image

That should remove the “false” compilation error from Clion :+1:

1 Like

ok it worked, THANKS!
I was pressing the PLAY button instead of the BUILD one.
Sorry, this is the first time I have errors on the play button :slight_smile:

Copperbot may I ask you if you are someone related to JetBrains?

Glad it worked !
No haha, just a regular user ^^

1 Like

hope to see all the PlatformIO basic functions implemented soon in the clion plugin.
is there something like “Upload and Monitor”?

why they added some commands only and not all the commands that Visual Studio Code have?

thanks

and what about if I add an environment to my platformio.ini
how can I reload all the available environements? it seems that clion is not updating the available environment.

should I manually delete the CMakeLists.txt?

I have another problem,
I have two environments.

If I do this:
#ifdef TARGET_MYENV

#endif

it works ok for one environment and not for others :frowning:

any idea @copperbot-d?

is there something like “Upload and Monitor”?

This seems to be a current request feature for future versions of the plugin. For my part I always open a separate terminal to do a “pio device monitor”.

why they added some commands only and not all the commands that Visual Studio Code have?

The plugin is still new, there will be updates in the future, you can check the progress here.

and what about if I add an environment to my platformio.ini
how can I reload all the available environements? it seems that clion is not updating the available environment.

Right now, if you add an environment in your platformio.ini, you have to “re-init” PIO (Tools > PlatformIO > re-init), and then add the new environment in Cmake Build Execution Deployment Profiles list of Clion, exactly like this (press + button until all your new environments appear in the list).

should I manually delete the CMakeLists.txt?

Nop, PIO will edit it automatically while “re-init”.

it works ok for one environment and not for others

If you want to do this, you have to add a different build flag for each of your environment in your platformio.ini, like this : build_flags = -D TARGET_MYENV_ONE
And then, after re-init PIO, and adding your different environments in Clion as say above (if not already), Clion will recognize the environment you have selected (in the list next to build button), and update code features accordingly, so it will understand when you write #ifdef TARGET_MYENV_ONE or #ifdef TARGET_MYENV_TWO :+1:

I have done it, done the reinit, restarted the ide, but it does not works.

As you can see the two targets are loaded correcly in the configuration drop down menu

but the code is not “highlited” correclty.
If you see in my screenshot the “glowwormluciferinlight” env is selected, but in the code, the TARGET_GLOWWORMLUCIFERIN is highlited, I expect to see the TARGET_GLOWWORMLUCIFERINLIGHT highlited instead.

any idea?

thanks!

That should work, is your platformio.ini have the right build flag for each environment ?

demo_multi_env2