CLion 2019.2 Help

OpenOCD Support

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.

Required tools

  1. OpenOCD

    OpenOCD will be used as a flash probe and remote gdbserver.

    In Settings/Preferences | Build, Execution, Deployment | Embedded Development, you can check whether the OpenOCD location was detected correctly and set the path manually if needed.

  2. Toolchain

    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-gcc from 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 Settings/Preferences | Build, Execution, Deployment | Toolchain or in your CMake script (take a look at the template CMakeLists.txt).

    Also, you need to provide the linker file: obtain it from your chip vendor or create it manually, and specify through CMake settings.

    If you are working with an STM32CubeMX project, installing the GNU ARM toolchain is a part of the project set up, and CubeMX generates the linker file automatically.

  • In addition to the tools required for all platforms, install the ST-LINK/V2 driver.

  • For GNU ARM Toolchain, use version 2019-q3 or 2018-q2 (and earlier). See the issue with 2018-q4.

  • Only the MinGW and MinGW-w64 environments are supported (CPP-15034).

Create an OpenOCD Download & Run configuration

  1. Go to Run | Edit Configurations, click icons general add svg and select OpenOCD Download & Run.

    For STM32CubeMX projects, a configuration of this type is added automatically during the project creation.

  2. In the settings, you can choose the board config file, adjust GDB and Telnet ports, and set up Download/Reset options.

    openocd run-debug configuration

Run/debug an OpenOCD Download & Run configuration

  • When you Runartwork studio icons avd run this configuration, the compiled firmware is downloaded to the target board, and then the chip is reset.

  • When you Debugicons actions startDebugger svg, 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:

    debug the embedded project

    Notice the MCU reset 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.

Last modified: 22 August 2019