For the plugin to work, the mbed cli needs to present in the PATH or be explicitly specified in the settings under
Tools -> Mbed
. For importing existing repositories from version control, git or mercurial are required.
Installers for Windows and Mac OS can be found at https://os.mbed.com/docs/mbed-os/v5.15/tools/installation-and-setup.html
Recommended method of installation is using python's package manager pip, and the command pip install mbed-cli
New Mbed projects can be created using CLions new project dialog. Simply select Mbed and enter a valid location in the right.
After pressing the create button a new window will open and the plugin starts downloading the newest Mbed OS version from the Github repo. As soon as the download has finished a new dialog will appear asking which Mbed Target should be used. This option can be changed later at any time.
After pressing okay a cmake project will be generated from the Mbed project and CLion should start indexing and updating symbols. To further configure your project the file mbed_app.json has been created. To start programing the file main.cpp has been created that already contains the main function of the program.
To fetch existing Mbed projects from Git or Mercurial the mbed import
functionality has been integrated into CLion.
In the Get from Version Control
dialog simply select mbed import
as Version Control and enter the URL to the
repository.
For importing examples provided by Mbed OS the repository name can be specified instead of the URL.
For additional options such as branch, tag or commit hash see: https://os.mbed.com/docs/mbed-os/v5.15/tools/working-with-mbed-cli.html
After pressing Clone
the git or Mercurial repository will be downloaded. Once the download has finished the target
dialog as seen in Project Creation will appear.
To configure targets and features of Mbed OS the file mbed_app.json
exists. The CMakeLists.txt that is generated when
creating a new project or importing existing ones is created by the mbed-cli after reading the mbed_app.json file. As the
CMakeLists.txt file is overwritten each time the mbed_app.json
file is changed, no changes should be done to it except
adding new Sources. For the documentation on features and possible configurations see:
https://os.mbed.com/docs/mbed-os/v5.15/reference/configuration.html
The plugin ships with a schema that provides Code Completion, documentation and checks for validity
of the mbed_app.json
file.
After changes have been done the file a prompt will appear at the top, similar to the reload-prompt inside of
CMakeLists.txt for normal C++ projects, and prompt to reload the Mbed project. A new CMakeLists.txt file is then created
using the configs in the mbed_app.json
file.
The Mbed target can be changed at any time in the project. Either right click the project root and select
Change Target Board
or go to Build -> Change Target Board
.
By default, code is compiled in debug mode with optimizations turned off. To switch to release mode and optimize
for size go to Build -> Switch to Release
. A dialog regenerating the cmake project should appear. Use the menu
Build -> Switch to Debug
to switch back to unoptimized code.
Using profiles it is possible to change flags used for compilation of C, C++ and Assembly code as well as linker flags. Mbed defines extra JSON files where one can set flags per supported toolchain. For further information see: https://os.mbed.com/docs/mbed-os/v5.15/tools/build-profiles.html
The plugin provides a GUI for adding profiles that should be used during the build process. Simply open the settings
and go to Build, Execution, Deployement -> Mbed Profiles
:
When pressing the +
button a file dialog will appear allowing you to select a new profile to add. Using -
removes
the selected profile. With the Edit button one can change the path of a profile.
It is possible to add multiple profiles. Profiles added last also add their builds flags last and can therefore overwrite options of previous profiles. Using the arrow buttons it is possible to change the order of the profiles.
When you are done simply click Apply
and the IDE will regenerate the project with the new build flags.
As soon as a JSON file is added as a profile, code completion and type checking and similar will be available in it.
When a profile in use changes, a suggestion to reload the project to apply the new flags appears.
For managing Mbed OS packages a tool window labeled "Mbed" exists at the bottom of the screen. It provides a tree view of all dependencies of the project and allows changing the version of dependencies and sub dependencies.
- Use Ninja instead of make: https://github.com/ninja-build/ninja Simply download the binary for your platform,
add its location in the PATH and specify
-GNinja
in the CMake options in the Settings underBuild, Execution, Deployment -> CMake
. Using Ninja instead of make leads to faster compile times for both incremental and full builds. - Enable Repository caching: Simply enter
mbed cache on
in a terminal to enable Repository caching. The mbed-cli will then cache downloads of repositories and reuse them when possible. This allows for faster project creation as well as creating new projects without an internet connection.
- When working on Windows, and the base path of the project has too many characters the project may not compile. This is due to the CMakeLists.txt file generated by the mbed-cli adding every folder in the project to the include-path, leading to a compiler command exceeding Windows maximum number of 32768 characters.
- Ability to remove and add packages will be added in the future
- A prompt for the user to turn on Repository caching after project creation if it is turned off will be added in the future
- Ability to check features of a specific target (such as if it has a lower power clock, etc.) will be added in the future.