Setup Jetbrains Clion IDE with STM32CubeMX project for development on STM32 Microcontrollers – Mac
I’ve managed to setup programming and debugging a STM32 Nucleo-L4R5ZI development board with Jetbrains Clion IDE on my Mac. If you need the same for Windows, I got your back! This tutorial should work for all STM32 based Microcontrollers with a debug interface (JTAG) that is supported by OpenOCD. I used a STM32 Nucleo-L4R5ZI board. I want to share my findings with you. In this tutorial you have to install Java (required for STM32CubeMX), STM32CubeMX, Clion as IDE, the ARM GNU eabi Toolchain, and OpenOCD.
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 openjdk@11 $ brew install --cask clion
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. There is only an .exe file but actually it is 100% Java. Execute:
$ java -jar <path to exe>. The installer will take care of everything. Once the App is installed it might be that you always have to start it with
java -jar /Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources/StM32CubeMX in case that regular application startup doesn’t work. Hold on for now, we will continue here at the end of this tutorial.
Install the ARM GNU compiler toolchain via Homebrew:
brew install --cask gcc-arm-embedded # old way; only do this if the first line doesn't work # $ brew tap ArmMbed/homebrew-formulae # installs a binary called "arm-none-eabi-gcc # $ brew install arm-none-eabi-gcc
Install OpenOCD (Open On-Chip Debugger):
# builds open-ocd from source to have the latest boards available $ brew install --HEAD open-ocd
Find location of OpenOCD for CLion:
$ realpath $(which openocd) # will look like: /usr/local/Cellar/open-ocd/HEAD-ba0f382/bin/openocd
This is the path you have to enter in Clion in the OpenOCD configuration (see Clion settings and search for OpenOCD). Note:
/usr/local/bin/openocd doesn’t work in that case. It has to be the real path because Clion looks into
$ echo $(realpath $(which openocd))/../share/board/ for all board configurations! Be aware of that this path might not work after the next
brew upgrade and you have to adjust it again.
Generate Project in CubeMX
Now lets put everything together. Generate a project in CubeMX, select your board and generate the code. In the Project Manager window of CubeMX you have to set „STM32CubeIDE“ as IDE and checkmark „Generate Under Root“. More details on this can be found on the support link on the bottom of the page.
Afterwards you start Clion and open the *.ioc-file generated by CubeMX. Clion will automatically generate a CMakeLists.txt file and should find „arm-none-eabi-gcc“ (ARM Gnu toolchain) which we installed in a previous step. CubeMX and Clion will use the same directory for this project! Before you run your application, you have to configure the board in the dialog. Click assist and select your board as shown in the screenshot below:
Connect your board via USB and you should be able to run or debug your applications by using the typical Clion IDE run configurations (green RUN button on the top right).