Skip to content

Setting up debugging in different IDEs

Dmitry Rezvanov edited this page Nov 25, 2024 · 21 revisions

Basic command set

Since MioLink (like the BlackMagic Probe on which it is based) works directly with GDB commands, the configuration for debugging will be similar across all IDEs.

The basic set of commands for the SWD interface:

set mem inaccessible-by-default off
monitor tpwr enable
monitor frequency 1M
monitor swdp_scan
att 1

The basic set of commands for the JTAG interface:

set mem inaccessible-by-default off
monitor tpwr enable
monitor frequency 1M
monitor jtag_scan
att 1

The purpose of the commands is as follows:

  1. set mem inaccessible-by-default off – allows viewing, for example, MCU peripheral registers;
  2. monitor tpwr enable – enables 3.3V power supply from the debugger to the Vtref pin.
    If this feature is not needed and the Vtref pin is powered externally, use monitor tpwr disable instead;
  3. monitor frequency 1M – sets the interface frequency to 1MHz.
    This command supports values in Hz, kHz, and MHz.
    Examples of valid values: 100000 (100kHz), 250k (250kHz), 4M (4MHz);
  4. monitor swdp_scan / monitor jtag_scan – initiates a target scan on the SWD/JTAG interface.
  5. att 1 – connects to the target with the specified index.
    Here, the argument 1 is the index of the target in the output of the swdp_scan/jtag_scan command:
(gdb) monitor swdp_scan
Target voltage: 3.3V
Available Targets:
No. Att Driver
 1      STM32F1 L/M density M3

If you have multiple targets (e.g., in a JTAG chain), specify the index of the desired target.
NOTE: If you want to work with the target via the JTAG interface, but JTAG is disabled in the target's current firmware, you will need to connect the target's NRST pin to the probe and add monitor connect_rst enable to the list of commands before monitor jtag_scan.

No IDE (GDB command line interface)

  1. Open the command line;
  2. Run GDB and specify the .elf file: arm-none-eabi-gdb MioLink_testing_f103.elf
  3. Connect to the MioLink: target extended-remote COM9
    NOTE: On Windows, use COMx format for ports 0-9 and \\.\COMx for ports starting from the 10 (where x - is the port number).
    Example: (gdb) target extended-remote \\.\COM10
  4. Use the commands from the list above, for example:
(gdb) target extended-remote COM9
`C:\Development\MCU\MioLink\test_board\MioLink_testing_f103\Debug\MioLink_testing_f103.elf' has changed; re-reading symbols.
Remote debugging using COM9
(gdb) set mem inaccessible-by-default off
(gdb) monitor tpwr enable
Enabling target power
(gdb) monitor frequency 1M
Debug iface frequency set to 1000000Hz
(gdb) monitor swdp_scan
Target voltage: 3.3V
Available Targets:
No. Att Driver
 1      STM32F1 L/M density M3
(gdb) att 1
Attaching to program: C:\Development\MCU\MioLink\test_board\MioLink_testing_f103\Debug\MioLink_testing_f103.elf, Remote target
HAL_GetTick () at ../Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c:305
305     {
(gdb)
  1. Work as you would with a regular GDB server.

CLion

Unfortunately, as of now (October 2024), CLion does not support extended-remote, making it impossible to set up debugging in CLion without resorting to dirty hacks with .gdbinit.
If that doesn’t scare you and you know what you're doing, you can find more information here.

VSCode

  1. Install cortex-debug extension;
  2. Create (or modify) launch.json file in .vscode folder;
  3. Add the debug configuration:
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "BMP Debug",
      "type": "cortex-debug",
      "servertype": "bmp",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "executable": "<path to .elf executable>",
      "interface": "swd",
      "device": "<target device>",
      "BMPGDBSerialPort": "<probe serial port>",
      "powerOverBMP": "<enable or disable>",
      "runToEntryPoint": "main",
      "svdFile": "<path to .svd file>"
    }
  ]
}

Options description:

Option Description
executable Path to your .elf executable,
e.g. ${workspaceRoot}/build/MioLink_testing_f103.elf.
For CMake applications, you can use ${command:cmake.launchTargetPath}
device Target device, e.g. STM32F103
BMPGDBSerialPort Black Magic Probe serial port, COMx for Windows (\\.\COMx for ports starting from the 10),
/dev/ttyACMx for Linux and /dev/cu.usbmodemX for Mac OS
powerOverBMP Set to enable to power the target from the probe or
disable if the target is self-powered
svdFile optional, specify the path to .svd file (registers description), e.g. STM32F103.svd

Full configuration example for a CMake-based project for STM32F103 which is powered from the BMP:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "BMP Debug",
      "type": "cortex-debug",
      "servertype": "bmp",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "executable": "${command:cmake.launchTargetPath}",
      "interface": "swd",
      "device": "STM32F103",
      "BMPGDBSerialPort": "/dev/cu.usbmodem1201",
      "powerOverBMP": "enable",
      "runToEntryPoint": "main",
      "svdFile": "STM32F103.svd"
    }
  ]
}

STM32CubeIDE

  1. Go to Run -> Debug Configurations;
  2. In GDB Hardware Debugging, add new configuration:
    image
  3. In the Debugger tab, specify the GDB command you are using, in my case: arm-none-eabi-gdb,
    the debugger type: Black Magic Probe (or Generic Serial, it doesn't matter),
    and the COM port number for MioLink’s GDB interface:
    image
  4. In the Startup tab, in the Initialization Commands input field, copy the basic set of commands from the list above (edited to fit your project, of course):
    image
  5. If you want the execution to stop at the main function, enable "Set breakpoint at:" in the Run Commands section below, enter main in the input field, and enable "Resume" below:
    image
  6. That’s it! To save the configuration, click Apply, and click Debug to start the debugging process.

Conclusion

This page contains only basic information on how to get started with MioLink.
For more details, please refer to the Black Magic Probe documentation.