web123456

Embedded linux clion, cross-platform IDE integrated development environment Clion Tutorial: Embedded Development

CLionIntelliJ is a cross-platform IDE designed for C and C++ development that is based on IntelliJ and includes many smart features to increase developer productivity. This powerful IDE helps developers toLinuxIt develops C/C++ on OS X, Windows, and Windows, and uses a smart editor to improve code quality, automate code refactoring, and deeply integrate with the CMake compilation system to increase developer productivity.

STM32CubeMX Project

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

STM32CubeMX support in CLion is part of the bundled OpenOCD + STM32CubeMX plugin. Therefore, some steps of the project setup and project creation process are combined with OpenOCD. However, STM32CubeMX projects are not limited to use with OpenOCD: you can also set up a more generalized embedded GDB server run/debug configuration. In the latter case, ignore the setup and project setup steps related to OpenOCD.

Tools required

All platforms

STM32CubeMX

CubeMX is a graphical tool for configuring STM32 microcontrollers and generating the corresponding C code. In CubeMX, you can set up the CPU and peripherals, and adjust the frequency and pin patterns. It generates a stub project, which CLion then converts to aCMakeProject.

GNU ARM Toolchain

The GNU ARM toolchain is a set of cross-platform tools that can be launched on the desktop, while the build results can only be run in the target ARM MCU environment. After installation, make sure that the toolchain appears in the system path: run arm-none-eabi-gcc from the command line- Your system should recognize this command.

WindowsExclusively for the GNU ARM toolchain, use version 2019-q3 or 2018-q2 (and earlier).

Only MinGW andMinGW-w64Environment.

Opening a project from an .ioc file

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

Create a new project

For a new project, you can start by configuring your MCU and CubeMX to generate code and then open that .ioc file, or as described below, you can create a project from scratch. In the New Project wizard (File | New Project), select STM32CubeMX as the project type. clion will create the .ioc file for the default STM32F030F4 MCU:

This .ioc file is the original CubeMX project file containing the static initialization settings. In CLion, this file is read-only, and in the current step it is a placeholder for the configuration that will be set in CubeMX in the next step.

Now we need to switch to CubeMX to generate the project source and populate the .ioc file. Click on the " Open with STM32CubeMX" link to open CubeMX from CLion.

In CubeMX, the configuration has been 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 the MCU changes. Therefore, we need to manually provide the name in the Project Manager and then accept the suggestion to overwrite the project.

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

4. If you do not plan to use OpenOCD, skip this step (click Cancel).

Back at CLion, when the CMake project is loaded, we are prompted to select a board configuration file. The suggested list is taken from the set of board configuration files that OpenOCD ships with OpenOd: Openocd-Installation / share / openocd / scripts / board folder:

You can also select the correct board configuration, including custom board configurations, in the settings of the OpenOCD run/debug configuration.

Editing Source CodeWhen you change the MCU configuration in CubeMX and click Generate Code, your CLion project is automatically updated!

You can also update the project manually: to do this, select Update CMake Project with STM32CubeMX from Tools | CMake on the main menu or from the context menu of the project view.When editing files generated by CubeMX, always enclose the code in /* 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 the code segments into separate .c or .h files (see next point).

If adding source or include files, place them in the Src and Inc directories.

CLion is regenerated from the template each time the project is updated. If you need to make changes in the CMake script (e.g., to add external libraries or FPU support), perform this action in CMakeLists_template.txt, and then call Update CMake project using STM32CubeMX.

Create a project

Select one of the following options: Run or debug an OpenOCD or embedded GDB server configuration. Both configurations include a Build as a Before startup step:

Build the project manually using the build operation.

Recommended Reading:

=====================================================

Those who want to buy Clion's genuine license can consult Wisdom's official customer service.

For more exciting content, please pay attention to the WeChat public number below and get the latest product information in time▼▼▼▼

Tags:

This site, in addition to the reproduction of the article, are the site's original or translation. Welcome any form of reproduction, but please be sure to indicate the source, not modify the original relevant links, if there are objections to the content, please e-mail feedback to hey@!

Article reprinted from: Clion