For embedded targets that allow on-chip debug with OpenOCD (Open On-Chip Debugger), use the dedicated OpenOCD Download & Run configuration. This configuration works with CMake-based projects, including the case of STM32CubeMX format.
OpenOCD will be used as a flash probe and remote gdbserver.
In, you can check whether the OpenOCD location was detected correctly and set the path manually if needed.
The OpenOCD Download & Run configuration requires the cross-compiler toolchain to be configured in advance.
For ARM Cortex-M and Cortex-R MCUs, install GNU ARM toolchain. After the installation, make sure the toolchain is presented in the system PATH: run
arm-none-eabi-gccfrom the command line, and your system should recognize this command.
For all other platforms, install the platform-specific toolchain and set up the tools in CMakeLists.txt).or in your CMake script (take a look at the template
Also, you need to provide the linker file: obtain it from your chip vendor or create it manually, and specify through CMake settings.
Create an OpenOCD Download & Run configuration
Go to OpenOCD Download & Run., click and select
For STM32CubeMX projects, a configuration of this type is added automatically during the project creation.
In the settings, you can choose the board config file, adjust GDB and Telnet ports, and set up Download/Reset options.
When setting up the board config file, you can provide the path manually or click Assist and choose from the standard options:
To adjust the board config file to your needs (for example, when you are working with a non-standard device or need to keep several config files), click Copy to Project & Use: the selected file will be copied into your project tree, and you'll be able to open it in the editor and modify as required.
Run/debug an OpenOCD Download & Run configuration
When you Run this configuration, the compiled firmware is downloaded to the target board, and then the chip is reset.
When you Debug, the firmware is downloaded, the chip is reset, and then the remote debugger is attached to the MCU.
You can now use all the CLion debugging features for your firmware running on-chip. For example, the following screenshot shows how to randomly light a LED on an STM32L073 Nucleo-64 board:
Notice the button on the left-hand bar of the Debugger tool window. When pressed, it sends the chip reset command selected in the Reset option of the configuration settings.