Difference between revisions of "J-Link Visual Studio Code"
(→Microsoft Windows Setup) |
(→Microsoft Windows Setup) |
||
(44 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
__TOC__ |
__TOC__ |
||
− | = |
+ | = Debugging with J-Link = |
+ | There are 3rd party plugins available that enable Visual Studio Code debugging on embedded targets via GDB + J-Link + GDBServer. |
||
− | Visual Studio Code is a free of charge source code editor from Microsoft that is available for Windows, Linux and macOS. Besides allowing to do code refactoring and version control by installing extensions it is possible to extend this “simple” code editor to a multi-platform development environment. |
||
+ | is a free of charge source code editor from Microsoft that is available for Windows, Linux and OS-X. Besides allowing to do code refactoring and version control by installing extensions it is possible to extend this “simple” code editor to a multi-platform development environment. |
||
In this tutorial, we will cover only how to add Debug capability to Cortex cores Microcontrollers over debug probe J-Link. |
In this tutorial, we will cover only how to add Debug capability to Cortex cores Microcontrollers over debug probe J-Link. |
||
For this example purpose, we will be using the SEGGER‘s emPower v2.0 evaluation board. Our target MCU will be the NXP MK66FX1M0xxx18, you can acquire it in our online store([https://www.segger.com/evaluate-our-software/segger/empower/ link]). |
For this example purpose, we will be using the SEGGER‘s emPower v2.0 evaluation board. Our target MCU will be the NXP MK66FX1M0xxx18, you can acquire it in our online store([https://www.segger.com/evaluate-our-software/segger/empower/ link]). |
||
− | Please notice that the |
+ | Please notice that the below configurations will re-flash your target, reset and attach to debug. If you wish to add the option to attach to a running target, just change the launch.json '''"request": "launch"''' to '''"request": "attach"'''. |
− | |||
− | |||
== Requirements == |
== Requirements == |
||
# Visual Studio Code ([https://code.visualstudio.com/ link]) |
# Visual Studio Code ([https://code.visualstudio.com/ link]) |
||
+ | # GNU ARM Embedded tool-chain ([https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads link]) |
||
− | # GNU ARM Embedded tool-chain |
||
+ | # J-Link Software and Documentation Pack ([https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack link]) |
||
− | ## Note: under windows use version 7-2018 ([https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads link]) |
||
− | # J-Link ([https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack link]) |
||
# Visual Studio Code Plugins |
# Visual Studio Code Plugins |
||
## C/C++ for Visual Studio Code ([https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools link]) |
## C/C++ for Visual Studio Code ([https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools link]) |
||
Line 26: | Line 24: | ||
= Microsoft Windows Setup = |
= Microsoft Windows Setup = |
||
− | + | Let's get started. Once you installed Visual Studio Code and the above plugins, start by opening Visual Studio Code. |
|
'''Open the project folder''' |
'''Open the project folder''' |
||
Line 32: | Line 30: | ||
Under File menu select Open Folder and select the EMPower project folder that you previously downloaded and extracted. |
Under File menu select Open Folder and select the EMPower project folder that you previously downloaded and extracted. |
||
− | [[Image:vs_code_debug_1.png| |
+ | [[Image:vs_code_debug_1.png|800px]] |
+ | Then switch to the debug sidebar, click "create a launch.json file" and select "Cortex Debug" from the drop-down list. |
||
+ | [[Image:vs_code_debug_3.png||800px]] |
||
− | Then press F1(to show all commands), type “launch” and select “Debug:Open launch.json” from the drop-down list. |
||
− | |||
− | |||
− | [[Image:vs_code_debug_2.png||600px]] |
||
− | |||
− | Afterwards you will be prompted to select the environment. Chose “Cortex Debug” |
||
− | |||
− | |||
− | [[Image:vs_code_debug_3.png||600px]] |
||
The launch.json file will be created under .vscode folder within your project folder. |
The launch.json file will be created under .vscode folder within your project folder. |
||
+ | [[Image:vs_code_debug_4.png||800px]] |
||
+ | Now we have to adapt the .json file with the below settings. |
||
− | [[Image:vs_code_debug_4.png||600px]] |
||
− | |||
− | Now we have to adapt the .json file with the bellow settings. |
||
<source lang="JavaScript"> |
<source lang="JavaScript"> |
||
{ |
{ |
||
− | // Use IntelliSense to learn about possible attributes. |
+ | // Use IntelliSense to learn about possible attributes. |
− | // Hover to view descriptions of existing attributes. |
+ | // Hover to view descriptions of existing attributes. |
− | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
+ | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
− | "version": "0.2.0", |
+ | "version": "0.2.0", |
− | "configurations": [ |
+ | "configurations": [ |
+ | { |
||
− | { |
||
+ | "name": "Cortex Debug", |
||
− | "type": "cortex-debug", |
||
+ | "cwd": "${workspaceFolder}", |
||
− | "request": "launch", |
||
+ | "executable": "${workspaceFolder}/BSP/SEGGER/K66FN2M0_emPower/Output/Debug/Start_emPower.elf", |
||
− | "name": "Debug J-Link", |
||
+ | "request": "launch", |
||
− | "cwd": "${workspaceRoot}", |
||
+ | "type": "cortex-debug", |
||
− | "executable": "${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Output/Release/Start_emPower.elf", |
||
+ | "runToEntryPoint": "main", |
||
− | "serverpath": "C:/Program Files (x86)/SEGGER/JLink_V647d/JLinkGDBServerCL.exe", |
||
− | + | "servertype": "jlink", |
|
+ | "serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL.exe", |
||
− | "device": "MK66FX1M0xxx18", |
||
+ | "serverArgs": [], |
||
− | "interface": "jtag", |
||
+ | "device": "MK66FX1M0xxx18", |
||
− | "serialNumber": "", //if you have more than one J-Link probe add the serial number here |
||
+ | "interface": "jtag", |
||
− | "jlinkscript":"${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Setup/Kinetis_K66_Target.js", |
||
+ | "serialNumber": "", //If you have more than one J-Link probe, add the serial number here. |
||
− | "runToMain": true, |
||
+ | "jlinkscript":"${workspaceFolder}/BSP/SEGGER/K66FN2M0_emPower/Setup/Kinetis_K66_Target.js", |
||
− | "svdFile": "${workspaceRoot}/SVD/MK66F18.svd" |
||
+ | "svdFile": "${workspaceFolder}/SVD/MK66F18.svd", |
||
− | } |
||
+ | "armToolchainPath": "C:/Program Files (x86)/Arm GNU Toolchain arm-none-eabi/12.3 rel1/bin" |
||
− | ] |
||
+ | } |
||
+ | ] |
||
} |
} |
||
</source> |
</source> |
||
The “serverpath” should be your J-Link GDB server installation directory. |
The “serverpath” should be your J-Link GDB server installation directory. |
||
+ | For “serverArgs” any of the [[J-Link_GDB_Server#Command_line_options | supported command line options]] can be used. E.g.:<source lang="JavaScript">"serverArgs": ["-speed", "8000"]</source> |
||
− | If you have more than one J-Link probe connected add your probe serial number. If you are only |
+ | If you have more than one J-Link probe connected, add your probe serial number. If you are only debugging one target, you can just comment this entry out. |
+ | To setup ARMs GDB toolchain, just add the "armToolchainPath" to the launch.json. This is the path where your arm-none-eabi-gdb.exe is located. |
||
+ | To get the Start_emPower.elf go to BSP/SEGGER/K66FN2M0_emPower and build the Start_SEGGER_emPower.emProject using SEGGER Embedded Studio. |
||
− | '''Note:''' |
||
+ | [[Image:vs_code_debug_4_1.png||800px]] |
||
− | The <span style="background-color:#1e1e1e;color:#ce9178;">MK66F18.svd</span> file can be found under Keil.Kinetis_K60_DFP.1.5.0/SVD from the above provided link from Keil. Copy this folder to your EMPower folder. |
||
+ | '''Note:''' |
||
− | [[Image:vs_code_debug_5.png||600px]] |
||
+ | The <span style="background-color:#1e1e1e;color:#ce9178;">MK66F18.svd</span> file can be found under Keil.Kinetis_K60_DFP.1.5.0/SVD from the above provided link from Keil. Copy this folder to your EMPower folder. |
||
+ | [[Image:vs_code_debug_5.png||800px]] |
||
− | The last step is to setup the ARMs GDB toolchain. Press F1 and write config. From the drop-down menu chose C/C++:Edit Configurations (JSON) |
||
− | |||
− | |||
− | [[Image:vs_code_debug_6.png||600px]] |
||
− | |||
− | In this Json configuration file you just add the compilerpath and the intelliSenseMode. Like bellow. |
||
− | |||
− | <source lang="JavaScript"> |
||
− | { |
||
− | "configurations": [ |
||
− | { |
||
− | "name": "Win32", |
||
− | "includePath": [ |
||
− | "${workspaceFolder}/**", |
||
− | "${workspaceFolder}/GUI/Inc" |
||
− | ], |
||
− | "defines": [ |
||
− | "_DEBUG", |
||
− | "UNICODE", |
||
− | "_UNICODE" |
||
− | ], |
||
− | "intelliSenseMode": "gcc-x64", |
||
− | "compilerPath": "C:\\Tool\\C\\Arm\\7_2018-q2-update\\bin\\arm-none-eabi-gcc.exe" |
||
− | } |
||
− | ], |
||
− | "version": 4 |
||
− | } |
||
− | </source> |
||
− | |||
− | Final result: |
||
− | [[Image:vs_code_debug_7.png||600px]] |
||
− | |||
− | You can achieve the same result through the UI. Press F1 write “config” and select „C/C++:Edit Configurations (UI)“ |
||
− | |||
− | [[Image:vs_code_debug_8.png||600px]] |
||
The setup is now all done. You can start debugging by simply pressing F5 or from the Debug Menu → Start Debugging. |
The setup is now all done. You can start debugging by simply pressing F5 or from the Debug Menu → Start Debugging. |
||
− | If you did the above steps you should expect the |
+ | If you did the above steps you should expect the below output. |
− | [[Image:vs_code_debug_9.png|| |
+ | [[Image:vs_code_debug_9.png||800px]] |
− | On the Left panel is possible to view the debug Variables(Locals, Global and Static) |
+ | On the Left panel is possible to view the debug Variables(Locals, Global and Static) Watch, Call Stack, Breakpoints, MCU Peripherals and the Core registers. All the basic and relevant information for debugging your project. |
− | + | That's it. Now you can debug your target application within Visual Studio Code. |
|
− | = Linux setup = |
+ | = Linux Ubuntu setup = |
− | The |
+ | The below setup was tested with Linux Ubuntu 16.04.01 LTS. |
ARM GCC installation |
ARM GCC installation |
||
<source lang="Bash shell scripts"> |
<source lang="Bash shell scripts"> |
||
− | $ sudo apt-get -y install |
+ | $ sudo apt-get -y install gcc-arm-none-eabi binutils-arm-none-eabi gdb-arm-none-eabi openocd |
− | $ sudo apt-get -y install lib32ncurses5 |
||
− | $ sudo apt-get -y install ia32-libs |
||
− | $ wget -O ${HOME}/Downloads/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2?revision=d830f9dd-cd4f-406d-8672-cca9210dd220?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,8-2018-q4-major |
||
− | $ mkdir -p "${HOME}/opt" |
||
− | $ cd "${HOME}/opt" |
||
− | $ tar xjf ~/Downloads/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2 |
||
− | $ chmod -R -w "${HOME}/opt/gcc-arm-none-eabi-8-2018-q4-major" |
||
</source> |
</source> |
||
Line 167: | Line 121: | ||
J-Link installation |
J-Link installation |
||
− | In the directory where you downloaded the j-link installer you use the installer to perform the installation. |
+ | In the directory where you downloaded the j-link installer, you use the installer to perform the installation. |
The J-Link installation directory can be found under /opt/SEGGER/. |
The J-Link installation directory can be found under /opt/SEGGER/. |
||
Line 174: | Line 128: | ||
In the terminal just type code to launch Visual Studio Code and install the following extensions under Visual Studio Code Extension Manager(Left panel Extensions symbol) Cortex Debug and C/C++ IntelliSense. |
In the terminal just type code to launch Visual Studio Code and install the following extensions under Visual Studio Code Extension Manager(Left panel Extensions symbol) Cortex Debug and C/C++ IntelliSense. |
||
− | [[Image:vs_code_debug_10.png|| |
+ | [[Image:vs_code_debug_10.png||800px]] |
− | Open the project folder that you Select Open folder from the File menu the emPower BSP. |
+ | Open the project folder that you Select Open folder from the File menu the emPower BSP. |
− | [[Image:vs_code_debug_11.png|| |
+ | [[Image:vs_code_debug_11.png||800px]] |
Press F1 and write config and select C/C++:Edit Configurations(UI) |
Press F1 and write config and select C/C++:Edit Configurations(UI) |
||
− | [[Image:vs_code_debug_12.png|| |
+ | [[Image:vs_code_debug_12.png||800px]] |
Add the compiler path to |
Add the compiler path to |
||
Line 198: | Line 152: | ||
− | You can perform the same through |
+ | You can perform the same through JSON config file |
F1 → type config→ and Select „C/C++:Edit Configurations(JSON) |
F1 → type config→ and Select „C/C++:Edit Configurations(JSON) |
||
− | [[Image:vs_code_debug_13.png|| |
+ | [[Image:vs_code_debug_13.png||800px]] |
− | Adapt your configuration like |
+ | Adapt your configuration like below. |
<source lang="JavaScript"> |
<source lang="JavaScript"> |
||
{ |
{ |
||
Line 220: | Line 174: | ||
"\"_UNICODE\"" |
"\"_UNICODE\"" |
||
], |
], |
||
− | "compilerPath": "/ |
+ | "compilerPath": "/usr/bin/arm-none-eabi-gcc", |
"cStandard": "c11", |
"cStandard": "c11", |
||
"cppStandard": "c++17", |
"cppStandard": "c++17", |
||
Line 229: | Line 183: | ||
} |
} |
||
</source> |
</source> |
||
− | |||
− | The end result should look like this. |
||
− | |||
− | [[Image:vs_code_debug_16.png||600px]] |
||
Now we need to generate and configure the launch Debug file for the Cortex-Debug extension. |
Now we need to generate and configure the launch Debug file for the Cortex-Debug extension. |
||
− | Press F1 and type launch. From the drop |
+ | Press F1 and type launch. From the drop-down list select "Debug:Open launch.json" |
− | [[Image:vs_code_debug_14.png|| |
+ | [[Image:vs_code_debug_14.png||800px]] |
Then select Cortex-Debug... |
Then select Cortex-Debug... |
||
− | [[Image:vs_code_debug_15.png|| |
+ | [[Image:vs_code_debug_15.png||800px]] |
+ | The end result should look like this. |
||
− | Under the generated .json file add the bellow setup. |
||
+ | |||
+ | [[Image:vs_code_debug_16.png||800px]] |
||
+ | |||
+ | Under the generated .json file add the below setup. |
||
<source lang="JavaScript"> |
<source lang="JavaScript"> |
||
{ |
{ |
||
− | // Use IntelliSense to learn about possible attributes. |
+ | // Use IntelliSense to learn about possible attributes. |
− | // Hover to view descriptions of existing attributes. |
+ | // Hover to view descriptions of existing attributes. |
− | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
+ | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
"version": "0.2.0", |
"version": "0.2.0", |
||
"configurations": [ |
"configurations": [ |
||
{ |
{ |
||
− | + | "type": "cortex-debug", |
|
− | + | "request": "launch", |
|
− | + | "name": "Debug J-Link", |
|
− | + | "cwd": "${workspaceRoot}", |
|
− | + | "executable": "${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Output/Debug/Start_emPower.elf", |
|
− | + | "serverpath": "/opt/SEGGER/JLink/JLinkGDBServerCLExe", |
|
− | + | "serverArgs": [], |
|
− | + | "servertype": "jlink", |
|
− | + | "device": "MK66FX1M0xxx18", |
|
+ | "interface": "jtag", |
||
− | "serialNumber": "679000005", //if you have more than one J-Link probe add the serial number here |
||
+ | "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", |
||
+ | "jlinkscript":"${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Setup/Kinetis_K66_Target.js", |
||
− | "runToMain": true, |
||
+ | "runToMain": true, |
||
− | "armToolchainPath": "/home/anybody/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/", |
||
+ | "armToolchainPath": "/usr/bin/", |
||
− | "svdFile": "${workspaceRoot}/SVD/MK66F18.svd" |
||
+ | "svdFile": "${workspaceRoot}/SVD/MK66F18.svd" |
||
} |
} |
||
] |
] |
||
− | + | } |
|
</source> |
</source> |
||
− | [[Image:vs_code_debug_17.png|| |
+ | [[Image:vs_code_debug_17.png||800px]] |
The Cortex-Debug launch.json should look like this in the end. |
The Cortex-Debug launch.json should look like this in the end. |
||
+ | |||
+ | To get the .svd files, extract the Keil.Kinetis_K60_DFP.1.5.0.pack and copy the SVD folder into the main project folder. |
||
+ | |||
+ | To get the Start_emPower.elf go to BSP/SEGGER/K66FN2M0_emPower and build the Start_SEGGER_emPower.emProject using SEGGER Embedded Studio. |
||
+ | |||
+ | [[Image:vs_code_debug_17_1.png||800px]] |
||
Now you are ready to start debugging. Just press F5 or from the Menu Debug select "Start Debugging".# |
Now you are ready to start debugging. Just press F5 or from the Menu Debug select "Start Debugging".# |
||
− | [[Image:vs_code_debug_18.png|| |
+ | [[Image:vs_code_debug_18.png||800px]] |
On the left Debug panel, you may find the debug variables, watch, call stack, breakpoints, peripherals registers and the core registers. All you need to start debugging your target. |
On the left Debug panel, you may find the debug variables, watch, call stack, breakpoints, peripherals registers and the core registers. All you need to start debugging your target. |
||
Line 283: | Line 244: | ||
= Apple Mac OS X Setup = |
= Apple Mac OS X Setup = |
||
− | The setup for |
+ | The setup for Apple OS-X is quite straightforward with one exception in the launch.json config file. |
'''Visual Studio Code''' |
'''Visual Studio Code''' |
||
Line 291: | Line 252: | ||
'''ARM GCC installation''' |
'''ARM GCC installation''' |
||
− | Open a terminal window and go to the directory where you download the ARM GCC toolchain(most likely in Downloads folder). Just unzip the folder to a directory of your choice. I recommend under /''opt.'' |
+ | Open a terminal window and go to the directory where you download the ARM GCC toolchain(most likely in the Downloads folder). Just unzip the folder to a directory of your choice. I recommend under /''opt.'' |
+ | <source> |
||
− | [[Image:vs_code_debug_19.png||600px]] |
||
+ | $ sudo tar -xjvf gcc-arm-none-eabi-8-2018-q4-major-mac.tar.bz2 -C /opt/ |
||
+ | </source> |
||
+ | |||
+ | [[Image:vs_code_debug_19.png||800px]] |
||
Open Visual Studio Code, and install the Extensions Cortex-Debug and C/C++ Intelisense. |
Open Visual Studio Code, and install the Extensions Cortex-Debug and C/C++ Intelisense. |
||
+ | Click on "Open Folder" and then select the EMPower project folder that you previously downloaded and extracted. |
||
− | [[Image:vs_code_debug_20.png||600px]] |
||
+ | [[Image:vs_code_debug_20.png||800px]] |
||
− | Then Press F1 and write “config”. From the drop down list select “C/C++ Edit configurations...” |
||
+ | Then Press F1 and write “config”. From the drop-down list select “C/C++ Edit configurations...” |
||
− | [[Image:vs_code_debug_21.png||600px]] |
||
− | [[Image: |
+ | [[Image:vs_code_debug_21.png||800px]] |
− | In the default generated json file change to the |
+ | In the default generated json file change to the below settings. |
+ | <source lang="JavaScript"> |
||
− | [[Image:vs_code_debug_23.png||600px]] |
||
+ | { |
||
+ | "configurations": [ |
||
+ | { |
||
+ | "name": "Mac", |
||
+ | "includePath": [ |
||
+ | "${workspaceFolder}/**" |
||
+ | ], |
||
+ | "defines": [], |
||
+ | "macFrameworkPath": [ |
||
+ | "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks" |
||
+ | ], |
||
+ | "compilerPath": "/opt/gcc-arm-none-eabi-8-2018-q4-major", |
||
+ | "cStandard": "c11", |
||
+ | "cppStandard": "c++17", |
||
+ | "intelliSenseMode": "gcc-x64" |
||
+ | } |
||
+ | ], |
||
+ | "version": 4 |
||
+ | } |
||
+ | </source> |
||
+ | |||
+ | [[Image:vs_code_debug_23.png||800px]] |
||
− | Lastly press again F1 and write launch and select “Debug: Open launch.json” followed by Cortex Debug option. |
+ | Lastly, press again F1 and write launch and select “Debug: Open launch.json” followed by Cortex Debug option. |
− | [[Image:vs_code_debug_24.png|| |
+ | [[Image:vs_code_debug_24.png||800px]] |
− | Change the default .json file to the |
+ | Change the default .json file to the below settings with the extra line for the compiler. In the current version from Cortex-Debug plugin/extension (v0.3.0) is not possible to run a Debug session without previously specifying the “armToolchainPath”. |
<source lang="JavaScript"> |
<source lang="JavaScript"> |
||
Line 328: | Line 315: | ||
"cwd": "${workspaceRoot}", |
"cwd": "${workspaceRoot}", |
||
"executable": "${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Output/Release/Start_emPower.elf", |
"executable": "${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Output/Release/Start_emPower.elf", |
||
− | "serverpath": "/Applications/SEGGER/ |
+ | "serverpath": "/Applications/SEGGER/JLink_V684a/JLinkGDBServerCLExe", |
+ | "serverArgs": [], |
||
"servertype": "jlink", |
"servertype": "jlink", |
||
"armToolchainPath": "/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/", |
"armToolchainPath": "/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/", |
||
"device": "MK66FX1M0xxx18", |
"device": "MK66FX1M0xxx18", |
||
"interface": "jtag", |
"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", |
"jlinkscript":"${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Setup/Kinetis_K66_Target.js", |
||
"runToMain": true, |
"runToMain": true, |
||
Line 343: | Line 332: | ||
Your launch .json file should look like this. |
Your launch .json file should look like this. |
||
− | [[Image:vs_code_debug_25.png|| |
+ | [[Image:vs_code_debug_25.png||800px]] |
− | You can now run a debug session by Pressing F5 or from the Debug Menu → Start debugging. |
||
+ | To get the .svd files, extract the Keil.Kinetis_K60_DFP.1.5.0.pack and copy the SVD folder into the main project folder. |
||
− | [[Image:vs_code_debug_26.png||600px]] |
||
+ | To get the Start_emPower.elf go to BSP/SEGGER/K66FN2M0_emPower and build the Start_SEGGER_emPower.emProject using SEGGER Embedded Studio. |
||
− | On the left panel(Debug Panel) you will find all the relevant information for debugging your project(Variables, Watch,.call stack, brerakpoints, peripherals registers and cortex registers). |
||
+ | You can now run a debug session by Pressing F5 or from the Debug Menu → Start debugging. |
||
+ | |||
+ | [[Image:vs_code_debug_26.png||800px]] |
||
+ | |||
+ | On the left panel(Debug Panel) you will find all the relevant information for debugging your project(Variables, Watch,.call stack, breakpoints, peripherals registers and cortex registers). |
||
= Final Remarks = |
= Final Remarks = |
||
Line 362: | Line 355: | ||
That's it. Happy debugging with J-Link under Visual Studio Code. |
That's it. Happy debugging with J-Link under Visual Studio Code. |
||
+ | |||
+ | = Support = |
||
+ | |||
+ | Please note that J-Link integration for Visual Studio Code is not provided by SEGGER. Therefore, SEGGER does not give any support regarding setting up a specific device. |
||
+ | This article is just an example and should be understood as such, not as a general guide for every setup. |
Latest revision as of 12:02, 2 May 2024
Contents
Debugging with J-Link
There are 3rd party plugins available that enable Visual Studio Code debugging on embedded targets via GDB + J-Link + GDBServer. is a free of charge source code editor from Microsoft that is available for Windows, Linux and OS-X. Besides allowing to do code refactoring and version control by installing extensions it is possible to extend this “simple” code editor to a multi-platform development environment. In this tutorial, we will cover only how to add Debug capability to Cortex cores Microcontrollers over debug probe J-Link. For this example purpose, we will be using the SEGGER‘s emPower v2.0 evaluation board. Our target MCU will be the NXP MK66FX1M0xxx18, you can acquire it in our online store(link). Please notice that the below configurations will re-flash your target, reset and attach to debug. If you wish to add the option to attach to a running target, just change the launch.json "request": "launch" to "request": "attach".
Requirements
- Visual Studio Code (link)
- GNU ARM Embedded tool-chain (link)
- J-Link Software and Documentation Pack (link)
- Visual Studio Code Plugins
- SVD for the NXP MK66F device (link)
- SEGGER Evaluation Software for emPower (link)
Note: from the above list download the packages according to your OS.
Microsoft Windows Setup
Let's get started. Once you installed Visual Studio Code and the above plugins, start by opening Visual Studio Code.
Open the project folder
Under File menu select Open Folder and select the EMPower project folder that you previously downloaded and extracted.
Then switch to the debug sidebar, click "create a launch.json file" and select "Cortex Debug" from the drop-down list.
The launch.json file will be created under .vscode folder within your project folder.
Now we have to adapt the .json file with the below settings.
{
// 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": [
{
"name": "Cortex Debug",
"cwd": "${workspaceFolder}",
"executable": "${workspaceFolder}/BSP/SEGGER/K66FN2M0_emPower/Output/Debug/Start_emPower.elf",
"request": "launch",
"type": "cortex-debug",
"runToEntryPoint": "main",
"servertype": "jlink",
"serverpath": "C:/Program Files/SEGGER/JLink/JLinkGDBServerCL.exe",
"serverArgs": [],
"device": "MK66FX1M0xxx18",
"interface": "jtag",
"serialNumber": "", //If you have more than one J-Link probe, add the serial number here.
"jlinkscript":"${workspaceFolder}/BSP/SEGGER/K66FN2M0_emPower/Setup/Kinetis_K66_Target.js",
"svdFile": "${workspaceFolder}/SVD/MK66F18.svd",
"armToolchainPath": "C:/Program Files (x86)/Arm GNU Toolchain arm-none-eabi/12.3 rel1/bin"
}
]
}
The “serverpath” should be your J-Link GDB server installation directory.
For “serverArgs” any of the supported command line options can be used. E.g.:
"serverArgs": ["-speed", "8000"]
If you have more than one J-Link probe connected, add your probe serial number. If you are only debugging one target, you can just comment this entry out.
To setup ARMs GDB toolchain, just add the "armToolchainPath" to the launch.json. This is the path where your arm-none-eabi-gdb.exe is located.
To get the Start_emPower.elf go to BSP/SEGGER/K66FN2M0_emPower and build the Start_SEGGER_emPower.emProject using SEGGER Embedded Studio.
Note:
The MK66F18.svd file can be found under Keil.Kinetis_K60_DFP.1.5.0/SVD from the above provided link from Keil. Copy this folder to your EMPower folder.
The setup is now all done. You can start debugging by simply pressing F5 or from the Debug Menu → Start Debugging.
If you did the above steps you should expect the below output.
On the Left panel is possible to view the debug Variables(Locals, Global and Static) Watch, Call Stack, Breakpoints, MCU Peripherals and the Core registers. All the basic and relevant information for debugging your project.
That's it. Now you can debug your target application within Visual Studio Code.
Linux Ubuntu setup
The below setup was tested with Linux Ubuntu 16.04.01 LTS.
ARM GCC installation
$ sudo apt-get -y install gcc-arm-none-eabi binutils-arm-none-eabi gdb-arm-none-eabi openocd
Microsoft Visual Studio Code installation
$ curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
$ sudo install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
$ sudo apt-get install apt-transport-https
$ sudo apt-get update
$ sudo apt-get install code
J-Link installation
In the directory where you downloaded the j-link installer, you use the installer to perform the installation.
The J-Link installation directory can be found under /opt/SEGGER/.
In the terminal just type code to launch Visual Studio Code and install the following extensions under Visual Studio Code Extension Manager(Left panel Extensions symbol) Cortex Debug and C/C++ IntelliSense.
Open the project folder that you Select Open folder from the File menu the emPower BSP.
Press F1 and write config and select C/C++:Edit Configurations(UI)
Add the compiler path to
/home/user/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/arm-none-eabi-gcc
the Defines
"_DEBUG",
"UNICODE",
"_UNICODE"
You can perform the same through JSON config file
F1 → type config→ and Select „C/C++:Edit Configurations(JSON)
Adapt your configuration like below.
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"\"_DEBUG\",",
"\"UNICODE\",",
"\"_UNICODE\""
],
"compilerPath": "/usr/bin/arm-none-eabi-gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Now we need to generate and configure the launch Debug file for the Cortex-Debug extension. Press F1 and type launch. From the drop-down list select "Debug:Open launch.json"
Then select Cortex-Debug...
The end result should look like this.
Under the generated .json file add the below setup.
{
// 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": "/opt/SEGGER/JLink/JLinkGDBServerCLExe",
"serverArgs": [],
"servertype": "jlink",
"device": "MK66FX1M0xxx18",
"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,
"armToolchainPath": "/usr/bin/",
"svdFile": "${workspaceRoot}/SVD/MK66F18.svd"
}
]
}
The Cortex-Debug launch.json should look like this in the end.
To get the .svd files, extract the Keil.Kinetis_K60_DFP.1.5.0.pack and copy the SVD folder into the main project folder.
To get the Start_emPower.elf go to BSP/SEGGER/K66FN2M0_emPower and build the Start_SEGGER_emPower.emProject using SEGGER Embedded Studio.
Now you are ready to start debugging. Just press F5 or from the Menu Debug select "Start Debugging".#
On the left Debug panel, you may find the debug variables, watch, call stack, breakpoints, peripherals registers and the core registers. All you need to start debugging your target.
Apple Mac OS X Setup
The setup for Apple OS-X is quite straightforward with one exception in the launch.json config file.
Visual Studio Code
Download the Visual Studio for Mac. Unzip the App to your Applications folder or any other folder of your choice.
ARM GCC installation
Open a terminal window and go to the directory where you download the ARM GCC toolchain(most likely in the Downloads folder). Just unzip the folder to a directory of your choice. I recommend under /opt.
$ sudo tar -xjvf gcc-arm-none-eabi-8-2018-q4-major-mac.tar.bz2 -C /opt/
Open Visual Studio Code, and install the Extensions Cortex-Debug and C/C++ Intelisense.
Click on "Open Folder" and then select the EMPower project folder that you previously downloaded and extracted.
Then Press F1 and write “config”. From the drop-down list select “C/C++ Edit configurations...”
In the default generated json file change to the below settings.
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks"
],
"compilerPath": "/opt/gcc-arm-none-eabi-8-2018-q4-major",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
Lastly, press again F1 and write launch and select “Debug: Open launch.json” followed by Cortex Debug option.
Change the default .json file to the below settings with the extra line for the compiler. In the current version from Cortex-Debug plugin/extension (v0.3.0) is not possible to run a Debug session without previously specifying the “armToolchainPath”.
{
// 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": [
{
"request": "launch",
"type": "cortex-debug",
"name": "Debug J-Link",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}/BSP/SEGGER/K66FN2M0_emPower/Output/Release/Start_emPower.elf",
"serverpath": "/Applications/SEGGER/JLink_V684a/JLinkGDBServerCLExe",
"serverArgs": [],
"servertype": "jlink",
"armToolchainPath": "/opt/gcc-arm-none-eabi-8-2018-q4-major/bin/",
"device": "MK66FX1M0xxx18",
"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"
}
]
}
Your launch .json file should look like this.
To get the .svd files, extract the Keil.Kinetis_K60_DFP.1.5.0.pack and copy the SVD folder into the main project folder.
To get the Start_emPower.elf go to BSP/SEGGER/K66FN2M0_emPower and build the Start_SEGGER_emPower.emProject using SEGGER Embedded Studio.
You can now run a debug session by Pressing F5 or from the Debug Menu → Start debugging.
On the left panel(Debug Panel) you will find all the relevant information for debugging your project(Variables, Watch,.call stack, breakpoints, peripherals registers and cortex registers).
Final Remarks
Visual Studio Code is a good freeware alternative to Eclipse based development environments when you add and set the extensions for debugging and compiling.
In the above configurations we only add the option "request": "launch", but if you wish to attach to a running target you can simply change this by set it to "request": "attach". Alternatively you can add an extra .json file for attach to target and assign another short-cut key to it. Leaving you this way with the two options.
If you wish to compile within Visual Studio Code there are plenty of tutorials online that can help you, setting up your environment by use of ARM GCC toolchain.
That's it. Happy debugging with J-Link under Visual Studio Code.
Support
Please note that J-Link integration for Visual Studio Code is not provided by SEGGER. Therefore, SEGGER does not give any support regarding setting up a specific device. This article is just an example and should be understood as such, not as a general guide for every setup.