If your embedded target supports on-chip debug with OpenOCD (Open On-Chip Debugger), use the OpenOCD Download & Run configuration. It works for CMake -based projects, including the case of STM32CubeMX, as well as Makefile projects, and custom build targets.
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.
Your cross-compiler toolchain should 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
If you are working with an STM32CubeMX project, then installing the GNU ARM toolchain is a part of the project set up, and CubeMX generates the linker file automatically. Otherwise, obtain the linker script from your chip vendor or create it manually, and specify in CMake settings.
Create an OpenOCD configuration
Go to OpenOCD Download & Run from the list of templates., click and select
In the settings, you can select the client GDB debugger and board config file, adjust the 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 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.
Also, 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.