Stm32 Clion

For embedded projects that target STM32 boards, CLion integrates with STM32CubeMX.

Install Java and Clion. If you don’t have them yet, you can install Java and Clion with Homebrew. You need Homebrew later anyway. $ brew install [email protected] $ brew install -cask clion Install STM32CubeMX. Download the ZIP file from their website. If you don’t want to create an account for that, use one from bugmenot. After you downloaded STM32CubeMX, extract the ZIP. For embedded projects that target STM32 boards, CLion integrates with STM32CubeMX. You can open an.ioc file generated by CubeMX as project, and CLion will automatically create a CMake project structure. Or you can start a new project from scratch - the wizard will help you configure it in CubeMX.

You can open an .ioc file generated by CubeMX as project, and CLion will automatically create a CMake project structure. Or you can start a new project from scratch - the wizard will help you configure it in CubeMX.

Clionembedded Embedded Development on STM32 with CLion and the Segger Tools The CLion IDE from Jetbrains is a very powerful IDE for C/C developments with lots of features to increase developer productivity. This small demo project shows how to use CLion for embedded development. STM32 Tutorial NUCLEO F103RB GPIO Pins. V1.0.1 – created on. Simon burkhardt page 2 /5. The concept is simple, on line 190 an init struct is defined, this struct is filled with information. A STM32F407 Discovery development board is used, but most STM32 targets should also work fine. Project Creation and Setup We'll basically follow the normal project creation process with CLion's embedded support. This JetBrains article shows the process.

STM32CubeMX support in CLion is a part of the bundled OpenOCD + STM32CubeMX plugin. For this reason, project settings and certain steps of the project creation procedure are coupled with OpenOCD. However, STM32CubeMX projects are not limited to be used with OpenOCD only: you can also set up a more generic Embedded GDB Server run/debug configuration. In the latter case, ignore the OpenOCD-related settings and steps of your project set up.

The following board configurations are not supported at the moment: STM32MP1, dual-core lines of STM32H7, and STM32L5 with TrustZone(R) enabled.

Required tools

  1. CubeMX is a graphical tool that helps configure STM32 microcontrollers and generate the corresponding C code. In CubeMX, you can set up both CPU and peripherals, and adjust frequencies and pin modes. It generates a stub project which CLion then converts into a CMake project.

  2. GNU ARM toolchain is a cross-platform set of tools which launches on desktop, while the build result can only run under the target ARM MCU environment.

    For CLion to detect the toolchain, it should be presented in system PATH. You can check it by running arm-none-eabi-gcc from the command line - your system should recognize this command.

    On Linux and macOS, make sure to have the toolchain path in ~/.profile (not in a shell-specific config like ~/.bash_profile or ~/.zprofile ).

In Settings/Preferences Build, Execution, Deployment Embedded Development, you can check whether the location of CubeMX was detected correctly, and set the path manually if needed. If you don't plan to use OpenOCD, leave the OpenOCD Location field empty.

  • For GNU ARM Toolchain, use version 2019-q3 (and later) or 2018-q2 (and earlier). See the issue with 2018-q4.

  • Only the MinGW and MinGW-w64 environments are supported (CPP-15034 ).

Open a project from the .ioc file

Stm32
  • If you already have a project that contains an .ioc file, call File Open, select the .ioc file, and choose Open as Project. CLion will automatically generate a CMake project structure.

Create a new project

For new projects, you have two options: a) configure your MCU and generate the code in CubeMX, then open the .ioc file in CLion, or b ) create a project from scratch as described below.

  1. Go to File New Project and select STM32CubeMX as your project type. CLion will create the .ioc file for the default STM32F030F4 MCU:

    .ioc files are CubeMX original project files that contain static initialization settings. In CLion, this file is read-only, and on the current step, it is a place-holder for the configuration that will be set up in CubeMX on the next step.

  2. Now you need to switch to CubeMX to generate the project sources and fill the .ioc file. Click the Open with STM32CubeMX link to open CubeMX from CLion.

  3. In CubeMX, the configuration is already set for the newly created project. Click STM32F030F4Px to invoke the MCU/Board Selector and change the default MCU:

    CubeMX resets the project name when you change the MCU. Provide the name manually in Project Manager, and then accept the suggestion to overwrite the project.

    After the hardware configuration is ready, check that the Toolchain / IDE field is set to STM32CubeIDE and select Generate Under Root, then click Generate Code:

  4. Skip this step (click Cancel) if you don't plan to use OpenOCD.

    Back in CLion, when the CMake project loading completes, you will be prompted to select a board config file. The list of suggestions consists of board config files shipped with OpenOCD in Openocd-Installation/share/openocd/scripts/board:

    You will also be able to select the board config file, including a custom one, later in the OpenOCD Run/Debug configuration settings.

    Click Copy to Project & Use, and the selected board config file will be added to your project tree. You will be able to open and adjust it in the editor.

Edit source code

  • When you change the MCU configuration in CubeMX and click Generate Code, your CLion project gets updated automatically:

    You can also update the project manually: right-click the .ioc file in Project View and select Update CMake project with STM32CubeMX.

  • While editing the files generated by CubeMX, always enclose your code in the /* USER CODE BEGIN ... */ and /* USER CODE END ... */ pseudo comments. This will protect your code from being overwritten by CubeMX during code regeneration. Also, consider extracting pieces of code into separate .c or .h files (see the next point).

  • If you add source or header files, place them in the Src and Inc directories.

  • CLion regenerates CMakeLists.txt from the template every time the project is updated. If you need to make changes in the CMake script (for example, to add external libraries or FPU support), do so in CMakeLists_template.txt and then call Update CMake project with STM32CubeMX.

Build a project

To build you project, use one of the following options:

  • Run or debug an OpenOCD or Embedded GDB Server configuration. Both of these configurations include Build as a Before launch step:

  • Use Build actions to build the project manually.

3 years ago.

Hi there,

You can open your Mbed OS LPC1768 project in CLion by exporting your project to the CMake-GCC-ARM toolchain within the online compiler or Mbed CLI. For example, import the mbed-os-example-blinky project into your online compiler. Make sure you have selected the LPC1768 as your target in the top right hand corner. If you do not see the LPC1768, add it to your online compiler from it's board page here.

Then, right click on your project's name in the online compiler and select 'Export program...'. Then make sure your export target is the LPC1768 and your export toolchain is 'CMake-GCC-ARM'. Then click 'Export' and download the .zip file to your computer.

You will need to have the GCC ARM toolchain installed to your computer: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm

Extract the .zip file somewhere on your computer. Then open up CLion and create a new project by 'Import Project from Sources' and select the extracted Mbed OS project folder on your computer. Make sure you do not let CLion override your existing CMakeLists.txt file.

You may need to add full directory paths to your cmake compilers in the CMakeLists.txt file, for example these paths look like the following on my Macbook on line 15 of the CMakeLists.txt file:

Please let me know if you have any questions!

- Jenny, team Mbed

If this solved your question, please make sure to click the 'Thanks' link below!

I using Windows10, so wrote belows...

but I catches parse error.How to fix this?

posted by 26 Apr 2018

Hi, try changing your cmake compiler paths to use different slashes.

posted by 27 Apr 2018

Dear JennySpecifically, how do I fix this error?

posted by 30 Apr 2018

Try paths such as: D:/Apps/GCC/7 2017-q4-major/bin/arm-none-eabi-gcc

- Jenny, team Mbed

posted by 30 Apr 2018

Clion Stm32 Debug

I changed it like that, but the same error is thrown.

posted by 01 May 2018

Please try reverting to the paths to what they were originally then, I apologize for the confusion.

posted by 01 May 2018

hmm... can't fix it... Also, I tried removing blanks, but it did not improve.

Clion Stm32 Debug

posted by 01 May 2018

Is there any similar way when using ARMC6 compiler instead of GCC?

Cubemx

posted by 11 Aug 2018