使用J-Link調(diào)試?
Visual Studio Code是微軟推出的免費(fèi)的源代碼編輯器,通過(guò)插件,可以實(shí)現(xiàn)GDB +J-Link+GDBServer方式在VSCode中調(diào)試嵌入式系統(tǒng)。
在本文中,我們將介紹如何通過(guò)J-Link向Cortex內(nèi)核微控制器添加調(diào)試功能。示例使用SEGGER的emPower v2.0評(píng)估板,其MCU為NXP的MK66FN2M8xxx18。請(qǐng)注意,以下配置將重新刷新目標(biāo)應(yīng)用,復(fù)位并連接到調(diào)試。如果希望添加該選項(xiàng)到正在運(yùn)行的目標(biāo)板,只需更改launch.json 中的"request": "launch"為"request": "attach"。
系統(tǒng)需求
1、Visual Studio Code
3、Visual Studio代碼插件
· C/ C++ for Visual Studio Code
· Cortex-Debug
· C/ C++?Intellisense可選
4、NXP MK66F器件的SVD
?
Windows系統(tǒng)設(shè)置
安裝完VSCode及相應(yīng)插件后,首先打開Visual Studio Code。
打開項(xiàng)目文件夾
在File菜單下選擇Open Folder并選擇下載的emPower項(xiàng)目文件夾(https://www.segger.com/downloads/eval/SeggerEval_K66_SEGGER_emPower_CortexM_EmbeddedStudio)。

通過(guò)Run and Debug按鈕?,選擇“Cortex Debug”, 在項(xiàng)目文件夾的.vscode目錄中創(chuàng)建launch.json文件。

改編.json文件,如下:
?
{
? ?// 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”應(yīng)該是你的J-Link GDB服務(wù)器的具體安裝目錄。如果電腦連接了多個(gè)J-Link,需添加J-Link序列號(hào)。如果只調(diào)試一個(gè)目標(biāo),可以把這個(gè)條目注釋掉。
在項(xiàng)目BSP/SEGGER/K66FN2M0_emPower目錄下,使用SES打開Start_SEGGER_emPower.emProject工程,構(gòu)建生成Start_emPower.elf。

注意:
解壓下載的NXP MK66F器件的SVD后,MK66F18.svd文件位于Keil. kinetis_k60_dfp .1.5.0/ SVD下。將此文件夾復(fù)制到emPower文件夾。

最后一步是設(shè)置ARM GDB工具鏈。按F1,輸入“config”。從下拉菜單中選擇C/ c++:Edit Configurations (JSON)

在JSON配置文件中,需要添加編譯器路徑,如下:
?
{
? ? "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-majorin\arm-none-eabi-gcc.exe"
?}
?],
"version": 4
}
?
最終結(jié)果:

在setting文件中,我們必須指定armToolchainPath。按F1并鍵入“settings”,選擇“Open settings (JSON)”:

"cortex-debug.armToolchainPath": "C:\Tool\C\Arm\7_2018-q2-update\bin"一行
應(yīng)該指向arm-none-eabi-gdb.exe所在的文件夾:

現(xiàn)在設(shè)置已經(jīng)全部完成??梢酝ㄟ^(guò)按F5或從RUN菜單→Start Debugging來(lái)開始調(diào)試。
進(jìn)入調(diào)試后,輸出如下:

在左側(cè)面板上可以查看調(diào)試變量(局部,全局和靜態(tài)),調(diào)用堆棧,斷點(diǎn),MCU外設(shè)和內(nèi)核寄存器等調(diào)試項(xiàng)目所需的信息。
現(xiàn)在可以在Visual Studio Code中調(diào)試目標(biāo)應(yīng)用程序了。
當(dāng)你添加和設(shè)置用于調(diào)試和編譯的擴(kuò)展時(shí),Visual Studio Code是一個(gè)很好的選擇。在上述配置中,我們添加了“request”:“l(fā)aunch”選項(xiàng),但如果希望連接到運(yùn)行中的目標(biāo)上,你可以簡(jiǎn)單地將其設(shè)置為“request”:“attach”。或者,可以添加一個(gè)extra.json文件連接到目標(biāo)。通過(guò)上述配置,即可以在Visual Studio Code下使用J-Link調(diào)試了。
電子發(fā)燒友App








評(píng)論