Using J-Link Debugging in VSCode

Using J-Link Debugging in VSCodeUsing J-Link Debugging in VSCode

Using J-Link Debugging

Visual Studio Code is a free source code editor launched by Microsoft. With plugins, it can achieve GDB + J-Link + GDBServer debugging for embedded systems in VSCode.

In this article, we will introduce how to add debugging capabilities to Cortex core microcontrollers using J-Link. The example uses SEGGER’s emPower v2.0 evaluation board, which has an MCU of NXP’s MK66FN2M8xxx18. Please note that the following configuration will refresh the target application, reset, and connect to debugging. If you wish to add this option to the running target board, simply change “request”: “launch” in launch.json to “request”: “attach”.

System Requirements

1. Visual Studio Code (https://code.visualstudio.com/)

2. GNU ARM Embedded Toolchain(https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads)

3. Visual Studio Code Plugins

· C/C++ for Visual Studio Code

· Cortex-Debug

· C/C++ Intellisense (optional)

4. SVD for NXP MK66F Device(https://keilpack.azureedge.net/pack/Keil.Kinetis_K60_DFP.1.5.0.pack)

Using J-Link Debugging in VSCode

Windows System Setup

After installing VSCode and the corresponding plugins, first open Visual Studio Code.

Open Project Folder

In the File menu, select Open Folder and choose the downloaded emPower project folder(https://www.segger.com/downloads/eval/SeggerEval_K66_SEGGER_emPower_CortexM_EmbeddedStudio).

Using J-Link Debugging in VSCode

Through the Run and Debug button, select “Cortex Debug” to create a launch.json file in the .vscode directory of the project folder.

Using J-Link Debugging in VSCode

Edit the .json file as follows:

{    // Use IntelliSense to learn about possible attributes.    // Hover to view descriptions of existing attributes.    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387    "version": "0.2.0",    "configurations": [      {      "type": "cortex-debug",      "request": "launch",      "name": "Debug J-Link",      "cwd": "${workspaceRoot}",   "executable": "${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Output/Debug/Start_emPower.elf",       "serverpath": "D:/Program Files /SEGGER/JLink_V788e/JLinkGDBServerCL.exe",        "servertype": "jlink",       "device": "MK66FN2M0xxx18",       "interface": "jtag",       "serialNumber": "", //If you have more than one J-Link probe, add the serial number here.    "jlinkscript":"${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Setup/Kinetis_K66_Target.js",     "runToMain": true,     "svdFile": "${workspaceRoot}/SVD/MK66F18.svd"     }]}

“serverpath” should be the specific installation directory of your J-Link GDB server. If your computer is connected to multiple J-Links, you need to add the J-Link serial number. If you are debugging a single target, you can comment out this entry.

In the project BSP/SEGGER/K66FN2M0_emPower directory, open the Start_SEGGER_emPower.emProject project using SES and build to generate Start_emPower.elf.

Using J-Link Debugging in VSCode

Note:

After extracting the downloaded SVD for the NXP MK66F device, the MK66F18.svd file is located under Keil. kinetis_k60_dfp .1.5.0/ SVD. Copy this folder to the emPower folder.

Using J-Link Debugging in VSCode

The last step is to set up the ARM GDB toolchain. Press F1, type “config”. From the dropdown menu, select C/C++: Edit Configurations (JSON)

Using J-Link Debugging in VSCode

In the JSON configuration file, you need to add the compiler path as follows:

{     "configurations": [    {      "name": "Win32",      "includePath": [      "${workspaceFolder}/**",     "${workspaceFolder}/GUI/Inc"  ],  "defines": [      "_DEBUG",      "UNICODE",      "_UNICODE"  ],  "intelliSenseMode": "gcc-x64",  "compilerPath": " D:\Program Files (x86)\GNU Arm Embedded Toolchain\10 2020-q4-major\bin\arm-none-eabi-gcc.exe"  }  ],"version": 4}

Final Result:

Using J-Link Debugging in VSCode

In the settings file, we must specify armToolchainPath. Press F1 and type “settings”, select “Open settings (JSON)”:

Using J-Link Debugging in VSCode

“cortex-debug.armToolchainPath”: “C:\Tool\C\Arm\7_2018-q2-update\bin” line

should point to the folder where arm-none-eabi-gdb.exe is located:

Using J-Link Debugging in VSCode

Now all settings are complete. You can start debugging by pressing F5 or from the RUN menu → Start Debugging.

Once in debugging, the output is as follows:

Using J-Link Debugging in VSCode

In the left panel, you can view debugging variables (local, global, and static), call stacks, breakpoints, MCU peripherals, and kernel register information needed for debugging.

You can now debug the target application in Visual Studio Code.

When you add and set up extensions for debugging and compilation, Visual Studio Code is a great choice. In the configuration above, we added the “request”:”launch” option, but if you want to connect to a running target, you can simply set it to “request”:”attach”. Alternatively, you can add an extra.json file to connect to the target. With the above configuration, you can debug using J-Link in Visual Studio Code.

This article is sourced from the internet, freely conveying knowledge, and the copyright belongs to the original author. If there are copyright issues, please contact me for deletion.

Previous Recommendations

“Comprehensive Guide to Embedded Linux Drivers”

Reply 1024 in the WeChat public account chat interface to obtain embedded resources

Leave a Comment