How to configure STM32CubeIDE for the J-Link Debugger

STM32CubeIDE Development Environment Settings

You can download the STM32CubeIDE from the official website.

Getting Ready

Tutorial video

Instructions

For proper functionality of STM32CubeIDE perform the following steps:

  1. Go to: SEGGER - The Embedded Experts - Downloads - J-Link / J-Trace.
  2. Scroll-down to the “J-Link Software and Documentation Pack” item and download the version for your OS.
  3. Run the installation file and complete the installation by following the on-screen instructions.
  4. Go to: Node.js and download the latest version for your OS.
  5. Run the installation file and complete the installation by following the on-screen instructions.
  6. Run PowerShell.exe using administrative rights.
  7. Execute the following command:
    npm install --global xpm
  8. Re-launch PowerShell.exe using administrative rights and execute the following commands:
    xpm install --global @gnu-mcu-eclipse/arm-none-eabi-gcc
    xpm install --global @gnu-mcu-eclipse/windows-build-tools

If script running is disabled on your OS, execute the following command:
Set-ExecutionPolicy RemoteSigned

  1. Run STM32CubeIDE.
  2. Go to “Help → Eclipse marketplace…”.
  3. Enter " GNU MCU " into the search line.
  4. Click “Install” next to GNU MCU Eclipse.
    12_prep
  5. Do not change any installation options, just click “Next” up to the end.
  6. STM32CubeIDE will be re-started.
  7. Before compiling a project, manually specify a path to make-file in the “Build command” field (see the figure below). As a rule, the path is the following: C:\Users\<User Name>\AppData\Roaming\xPacks\@gnu-mcu-eclipse\windows-build-tools\2.12.1-1\.content\bin\make.exe unless manually changed.

Configuring

Tutorial video

Instructions

  1. Select a project, select “Debug As->Debug Configurations” on the menu list or on the toolbar (see Figure 1А and Figure. 1B).

The project has to be compiled successfully at least once.
1A

  1. Right-click “GDB Segger J-Link Debugging” on the configuration tree and select “New Configuration” on the context menu (see Figure 2).
    _2

If necessary, configuration name can be changed right away, but in this example we will leave it as it is.

  1. If the project was not compiled successfully at least once, the "C/C++ Application" field will be left blank (in Figure 3 all fields are filled up correctly). In this case close the configuration window, compile the project, then open the configuration window again and run the file by clicking “Search Project”.
  2. Make sure filepath in the “Actual Executable” field on the “Debugger” tab is correct. If it is incorrect, then GDB-server was installed incorrectly (see Getting Ready). A correct file path is shown in Figure 4.
  3. Specify device name in the corresponding field. Switch the “Connection” radio-button to "IP", specify IP-address and port for the current session as follows: IP:Port (see Figure 5). Make sure the “Interface” radio-button is at "SWD". Device name, IP-address and port are shown on the Connection and Tools page.

While using port forwarding, use localhost as the IP-address and serv_port as Port. serv_port is shown on the Connection and Tools page.

_5

  1. Scroll down the settings list. If the value in the “Actual Executable” field in “GDB Client Setup” group seems incorrect (see Figure 6), specify the file path for arm-none-eagbi-gdb in the “Executable name” field. As a general rule, the path is the following: C:\Users\<User Name>\AppData\Roaming\xPacks\@gnu-mcu-eclipse\arm-none-eabi-gcc\8.2.1-1.7.1\.content\bin\arm-none-eabi-gdb.exe unless manually changed.

  2. Click “Debug”.

If J-Link GDB Server timed out while starting:

  1. Run Cmd.exe and execute the following commands:
    cd «JLink_Path», where «JLink_Path» is a path to JLinkGDBServerCL.exe
    JLinkGDBServerCL.exe -select IP=«IP»:«Port» -device «device_name» -endian little -if SWD -speed 4000 -noir -LocalhostOnly, where «IP», «Port» and «device_name» are from the Connection and Tools page.

While using port forwarding, use localhost as the IP-address and <serv_port> as Port. serv_port is shown on the Connection and Tools page.

  1. Open “Debug Configurations” window for the created configuration.
  2. Uncheck “Start the J-Link GDB server locally” at the “Debugger” tab.
    _10
  3. Click “Debug”.