Preface
We use STM32CubeMX because it’s very easy to use and provides HAL and startup code.
If you do not use an STM32 or want to use STM32CubeMX just skip the Create a Project stage and write your own startup code.
Prerequisites
- CLion 2022.2.3
- Stm32CubeMX 6.6.1
- CMake 3.24.2
- IAR Embedded Workbench for ARM 9.30.1 (with license)
- STM32F3-Discovery
- OpenOCD
Create a Project
Start Stm32CubeMX, open board selector, STM32F3-Discovery, and create the project. Important changes:
Then generate the project.
Clion Toolchains Settings
-
In CLion, navigate to Settings | Build, Execution, Deployment | Toolchains
On Windows, create a new MinGW toolchain or select an existing one. Use bundled MinGW and CMake or configure the path to your installation. -
Select the debugger: you can use the bundled GDB or a custom GDB version, for example, the debugger from GNU ARM Embedded Toolchain.
CLion CMake Settings
- Open the project in CLion (ignore CMake errors).
- Configure CMakeLists.txt for your project.
- Configure toolchain-iar-9-arm.cmake to match your IAR installation path.
set(IAR_TOOLCHAIN_ROOT "C:/Program Files/IAR Systems/Embedded Workbench 9.0/arm")
- Configure CMakePresets.json to use the toolchain created earlier.
"toolchain": "CMake 3.24"
- Right-click CMakeLists.txt in the project tree and click Load CMake Project
- In CLion, navigate to Settings | Build, Execution, Deployment | CMake and enable the
Default preset
profile - Add your code to
main()
andcppMain
functions
Alternative to steps 4 - 6:
In CLion, navigate to Settings | Build, Execution, Deployment | CMake
Create a new profile or select an existing one and Under CMake options:
add:
-DCMAKE_TOOLCHAIN_FILE=$CMakeProjectDir$/toolchain-iar-9-arm.cmake
Debug
- Open Run Configurations
- (Optional) Enable semi-hosting via .gdbinit
- Set breakpoint to the very beginning of main()
- Click debug button
- Wait
- Debugger works
- Enjoy!