# [Foundation] Setup CLion with STM32CubeMX project for STM32 Development on macOS

> IDE Setup

- Author: Finn Sheng
- Published: 2023-01-21
- Category: Foundation · ece, software
- URL: https://www.robcholz.com/2023/01/21/clion-dev-macos/

---

Keil is very easy to handle for embedded development but might not have some functionalities such as code completion and inlay hint. This would trouble you especially when you want to conduct a big project.

IDEs by Jetbrains like Intellij and Pycharm are very popular in the market. They have many advantages including charming UIs, good usability, safe refactoring. Doubtlessly, their IDEs could greatly assist your coding works. CLion is a cross-platform IDE for C/C++ development by Jetbrains, and I will guide you to setup a basic development environment for STM32 with CLion in this tutorial.

## Tools

### Software

- A computer with macOS(for sure)
- CLion
- STM32CubeMX
- Homebrew

### Hardware

- STM32 MCU
- ST-Link/J-Link

## Installations

### Prerequisites

#### [CLion](https://www.jetbrains.com/clion/download/#section=mac)

> The version should be higher than 2019.2.

#### [STM32CubeMX](https://www.st.com/en/development-tools/stm32cubemx.html#get-software)

>Downloading requires email verification.

![open](https://www.robcholz.com/2023/01/21/clion-dev-macos/open_package.png)

- After you unzip the downloaded file, right-click the STM32CubeMX package and click `Show Package Contents` and right click to open the executable file inside the package.

![open](https://www.robcholz.com/2023/01/21/clion-dev-macos/malware_issue.png)

- There will be an error window popped up. Click `Cancel`.

![privacy setting](https://www.robcholz.com/2023/01/21/clion-dev-macos/privacy_setting.png)

- Open `Security & Privacy` in `System Preferences` and click `Allow Anyway`.

![open cubemx](https://www.robcholz.com/2023/01/21/clion-dev-macos/open_cubemx.png)

- Open STM32CubeMX executable file again in the package and click `Open`.

![installation wizard](https://www.robcholz.com/2023/01/21/clion-dev-macos/installation_wizard.png)

- Install STM32CubeMX.

#### [Homebrew](https://brew.sh/)

>Validate the installation `brew -v`.

You should have installed these tools above before you continue the next step.

#### ARM Toolchain

- Run `brew tap ArmMbed/homebrew-formulae` and `brew install arm-none-eabi-gcc` in the terminal.

>Validate the installation: `arm-none-eabi-gcc -v`.

#### OpenOCD

`brew install open-ocd`

>Validate the installation: `openocd -v`.

## CLion Configurations

### OpenOCD & STM32CubeMX Paths

![embedded dev tools set](https://www.robcholz.com/2023/01/21/clion-dev-macos/embedded_dev_tools_set.png)

- Generally, both of your OpenOCD and CubeMX locations should be as same as me. Remember to test your paths by clicking `Test`.

### Toolchains

![toolchains](https://www.robcholz.com/2023/01/21/clion-dev-macos/toolchains.png)

- Set build tools, C/C++ compilers and debuggers. You should use `Bundled GDB` or like me, manually set another GDB path for `Debugger` option.

![new project](https://www.robcholz.com/2023/01/21/clion-dev-macos/new_project.png)

- Create a new `STM32CubeMX` project.

![select board type](https://www.robcholz.com/2023/01/21/clion-dev-macos/select_board_type.png)

- Here, you can either click `Use` to choose a board type or click `Skip` to choose one later.

![open with cubemx](https://www.robcholz.com/2023/01/21/clion-dev-macos/open_with_cubemx.png)

- Click `Open with STM32CubeMX` to open the application.

![mcu before](https://www.robcholz.com/2023/01/21/clion-dev-macos/mcu_before.png)

- The default MCU is `STM32F030F4Px`.

![mcu after](https://www.robcholz.com/2023/01/21/clion-dev-macos/mcu_after.png)

- You can use STM32CubeMX like what you do everyday.

![ide selection](https://www.robcholz.com/2023/01/21/clion-dev-macos/ide_selection.png)

>- You have to select `STM32CubeIDe` in `Toolchain / IDE` setting, and the `Project Name` should be kept as same as the project name in CLion.

![edit config](https://www.robcholz.com/2023/01/21/clion-dev-macos/edit_config.png)

- After you generate code and overwrite the old project files, click `Assist` and choose a board type in `Run/Debug Configurations`.

>- You also need to edit the board config file in accordance to the version of your ST-Link.

Congrats! You can now build, upload, and debug in CLion.
