使用VSCODE調試STM32的iar工程


1.打開vscode安裝插件


主要用到IAR for visual studio code,沒有使用IAR Embedded workbench,在編譯的時候卡住,目前不知道什么原因,可能是IAR的版本過低,7.0版本。

2.打開工程文件夾

會由IAR for visual studio code 這個插件自動生成2個文件:c_cpp_properties.json和iar-vsc.json。如果不能自動識別,手動輸入路徑
iar-vsc.json

{
    "ewp": "c:\\Users\\Administrator\\Desktop\\raspi12\\EWARM\\Project.ewp",
    "configuration": "Debug",
    "compiler": "C:\\Program Files (x86)\\IAR Systems\\Embedded Workbench 7.0\\arm\\bin\\iccarm.exe",
    "workbench": "C:\\Program Files (x86)\\IAR Systems\\Embedded Workbench 7.0"
}

點擊Terminal -> RUN TASK,選擇iar -> iar:build

會自動生成tasks.json

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "iar",
			"command": "build",
			"project": "${command:iar-settings.project-file}",
			"config": "${command:iar-settings.project-configuration}",
			"builder": "${command:iar-settings.workbench}/common/bin/IarBuild.exe",
			"label": "iar: Iar Build",
			"problemMatcher": [
				"$iar-cc",
				"$iar-linker"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			}
		}
	]
}

3.編譯

通過Terminal -> RUN build Task
也可以快捷鍵 Ctrl + Shift + B 來進行編譯

4.調試

調試需要用到一個調試器,這里用到了arm交叉編譯工具 gcc-arm-none-eabi。安裝,配置環境變量。
直接在文件夾創建launch.json。按Ctrl + space或右下角點add configuration。
選擇
需要修改的地方:

 "program": "${workspaceFolder}/EWARM/TEST/Exe/Project.out"    //out路徑
 "miDebuggerPath": "arm-none-eabi-gdb.exe",          //上面安裝的交叉編譯工具里的調試器,因為加入了環境變量,所以不需要路徑
 "debugServerPath": "C:/Program Files (x86)/SEGGER/JLink_V502e/JLinkGDBServerCL.exe",  //這里使用了j-link進行調試,該路徑是安裝的j-link驅動的服務路徑
 "debugServerArgs": "-if swd -singlerun -strict -endian little -speed auto -port 3333 -device STM32F405RG -vd -strict -halt",   //這里修改設備名,  STM32F405RG

完整的文件:
launch.json

{
    "configurations": [
    {
        "name": "Debug GDBServer",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/EWARM/TEST/Exe/Project.out",
        "stopAtEntry": true,
        "cwd": "${workspaceFolder}",
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerPath": "arm-none-eabi-gdb.exe",
        "debugServerPath": "C:/Program Files (x86)/SEGGER/JLink_V502e/JLinkGDBServerCL.exe",
        "debugServerArgs": "-if swd -singlerun -strict -endian little -speed auto -port 3333 -device STM32F405RG -vd -strict -halt",
        "serverStarted": "Connected\\ to\\ target",
        "serverLaunchTimeout": 5000,
        "filterStderr": false,
        "filterStdout": true,
        "setupCommands": [
            {
                "text": "target remote localhost:3333"
            },
            {
                "text": "monitor flash breakpoints = 1"
            },
            {
                "text": "monitor flash download = 1"
            },
            {
                "text": "monitor reset"
            },
            {
                "text": "monitor reset"
            }
        ]
    }
    ]
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM