otr_logo_grey OntarioTechRacing.github.io

STM32 CLion & STM32CubeMX Developer Environment Setup

The following documentation details how to set up JetBrains CLion for embedded STM32 development utilizing STM32CubeMX, GNU ARM Toolchain and OpenOCD.

Currently, the debugger on macOS when using this setup does not work. Build and Run have had no documented issues.


Table of Contents

1 Initial Software Installs / Setup

1.1 STM32CubeMX*

STM32CubeMX.

Prerequisites for macOS:

  1. Xcode.

    • Homebrew Xcode packages work as well.
  2. Rosetta.

Installation for macOS:

  1. Run SetupSTM32CubeMX-6.9.1.app for the application wizard.

  2. If stopped by macOS, open the Privacy & Security in System Settings to allow running SetupSTM32CubeMX-6.9.1.app.

    • If wizard never opens or errors, try (replace 6.9.1 with your version):
    sudo xattr -cr ~/SetupSTM32CubeMX-6.9.1.app
    

1.2 CLion*

CLion.

1.3 GNU Compiler Collection (GCC) ARM Toolchain*

GNU Compiler Collection (GCC) ARM Toolchain.

1.4 OpenOCD*

OpenOCD.


2 Complete IDE Setup

For reference, official JetBrains documentation: STM32CubeMX projects.

2.1 Enable Embedded Development Support CLion Plugin

Add the Embedded Development Support plugin for CLion: Settings → Plugins CLion Embedded Development Support plugin.png

2.2 Setup OpenOCD and STM32CubeMX Paths

Add the path for OpenOCD and STM32CubeMX: Settings → Build, Execution, Deployment → Embedded Development CLion Embedded Development OpenOCD and STM32CubeMX path setting.png

2.3 Setup Arm GNU Toolchain GCC and G++

Add the path for Arm GNU Toolchain (arm-none-eabi-gcc).

Settings → Build, Execution, Deployment → Toolchains CLion Build Execution Deployment Toolchains.png

2.4 Create new CLion STM32CubeMX project

File → New → Project → STM32CubeMX CLion new STM32CubeMX project.png

2.4.1 Configure Version Control

Wait for STM32CubeMX to finish generating a default project.

If you are using version control, verify that any required files such as .git are still in the project directory, sometimes STM32CubeMX may delete / overwrite these files.

2.4.2 Remove Default Generated File Structure

Delete all files in your project except those that you specifically know are needed.

If you are new to the STM32 workflow follow the recommendations below:

  1. Keep CMakeLists.txt, CMakeLists_template.txt, **PROJECT_NAME_HERE**.ioc.
  2. Keep files required for version control such as .git.
  3. Keep .idea (JetBrain's project structure file).

2.5 Configure STM32 with STM32CubeMX

If STM32CubeMX fails to open automatically you can find the newly created **PROJECT_NAME_HERE**.ioc on the left-hand Project file structure viewer.

2.5.1 Configure STM32CubeMX Project Manager

Configure the Project Manager.

  1. Project Name = will be the name of your .ioc.
    • The recommended name is to follow the name of the (project) directory your .ioc is in.
  2. Project Location = will be the root directory of your project.
  3. Toolchain / IDE = STM32CubeIDE.
  4. Generate Under Root = True.

STM32CubeMX code generation settings.png

2.5.2 Generate Code

Generate code with the... GENERATE CODE button.

2.6 Configure OpenOCD

2.6.1 Pick Target Board Configuration File

Set the OpenOCD board file via Select Board Configuration File popup.

CLion Select Board Config File.png

2.6.2 Configure Run and Debug

Run / Debug Configurations → Edit Configurations... CLion ioc configured.png

2.6.3 Verify Run and Debug Config

Run / Debug Configurations → Edit Configurations...

CLion Edit Configurations.png

2.7 Hello World

Use the project file structure view on the left-hand to see the source code.

Build, Run (flash ST) and Debug are shown in the top mid-to-right.

CLion successful flash.png