.vscode文件中各个脚本需要修改的地方
NOTE:
此篇文章由VSCode编辑+GCC for ARM交叉编译工具链+Makefile构建+OpenOCD调试(基于STM32的标准库)派生而来,对.vscode文件中各个脚本需要修改的地方作补充说明。
tasks.json
该json文件的主要作用:使用XX名称去执行XX命令和XX参数。
包含了程序编译、目标及过程文件清除、重新编译、CMSIS-DAP-Link / ST-Link / J-Link下载
需要修改处:
① 修改
"args": [
"-f",
"interface/cmsis-dap.cfg",
"-f",
"target/stm32f4x.cfg",
"-c",
"program build/${workspaceRootFolderName}.elf verify reset", //将工程根目录名称作为可执行文件名称
"-c",
"reset run",
"-c",
"exit"
]
的target/stm32f4x.cfg
为你对应的MCU配置文件(位于OpenOCD文件夹下)。
② 注意修改 J-Link json 块的interface/jlink-swd.cfg
,具体参考笔者的一篇博客OpenOCD之J-Link下载。
………………ST-Link json块和J-Link json块以此类推去修改。
//任务脚本
{
//ctrl+shift+B
"tasks": [
//编译
{
"type": "shell",
// type:Task的类型,分为shell和process两种
// shell:作为Shell命令运行
// process:作为一个进程运行
"label": "build",
"command": "make -j 8",
"args": [],
"problemMatcher": [
"$gcc"
],
"group": "build"
},
//清除
{
"type": "shell",
"label": "clean",
"command": "make clean",
"args": [],
"problemMatcher": [
"$gcc"
],
"group": "build"
},
//重编译
{
"type": "shell",
"label": "rebuild",
"command": "make -j 8",
"args": [],
"problemMatcher": [
"$gcc"
],
"group": "build",
"dependsOn": [ //每次执行这个任务,会先执行clean任务,再执行build任务,这便是所谓的依赖。
"clean"
]
},
//cmsis-dap方式下载
{
"type": "shell",
"label": "flash with cmsis-dap-link",
"command": "openocd",
"args": [
"-f",
"interface/cmsis-dap.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface
"-f",
"target/stm32f4x.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\target
"-c",
// "program build/F401CCU6_demo.elf verify reset exit"
"program build/${workspaceRootFolderName}.elf verify reset", //将工程根目录名称作为可执行文件名称
"-c",
"reset run",
// "-c",
// "shutdown",
"-c",
"exit"
], /*command+args相当于主命令+子命令,也就是openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c "program build/F401CCU6_demo.elf verify reset exit"的效果*/
"problemMatcher": [
"$gcc"
],
"group": "build",
"dependsOn": [ //每次执行这个任务,会先build任务,这便是所谓的依赖。
"build"
]
},
//stlink方式下载
{
"type": "shell",
"label": "flash with ST-link",
"command": "openocd",
"args": [
"-f",
"interface/stlink.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface
"-f",
"target/stm32f4x.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\target
"-c",
// "program build/F401CCU6_demo.elf verify reset exit"
"program build/${workspaceRootFolderName}.elf verify reset", //将工程根目录名称作为可执行文件名称
"-c",
"reset run",
// "-c",
// "shutdown",
"-c",
"exit"
], /*command+args相当于主命令+子命令,也就是openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c "program build/F401CCU6_demo.elf verify reset exit"的效果*/
"problemMatcher": [
"$gcc"
],
"group": "build",
"dependsOn": [ //每次执行这个任务,会先build任务,这便是所谓的依赖。
"build"
]
},
//J-link方式下载
{
"type": "shell",
"label": "flash with J-link",
"command": "openocd",
"args": [
"-f",
"interface/jlink-swd.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface
"-f",
"target/stm32f4x.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\target
"-c",
// "program build/F401CCU6_demo.elf verify reset exit"
"program build/${workspaceRootFolderName}.elf verify reset", //将工程根目录名称作为可执行文件名称
"-c",
"reset run",
// "-c",
// "shutdown",
"-c",
"exit"
], /*command+args相当于主命令+子命令,也就是openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c "program build/F401CCU6_demo.elf verify reset exit"的效果*/
"problemMatcher": [
"$gcc"
],
"group": "build",
"dependsOn": [ //每次执行这个任务,会先build任务,这便是所谓的依赖。
"build"
]
}
],
"version": "2.0.0"
}
launch.json
该json文件的主要作用:用于调试MCU,和选择什么样的调试器件。
需要修改处: 对于 CMSIS-DAP-Link 调试json块,
① 修改"device": "STM32F401CCU6"
为你所需要的MCU型号。
② 修改
"configFiles": [
"interface/cmsis-dap.cfg",
"target/stm32f4x.cfg"
]
的target/stm32f4x.cfg
为你对应的MCU配置文件(位于OpenOCD文件夹下)。
③ 修改"svdFile": "./STM32F401.svd"
对应MCU型号的寄存器文件及路径。
④ 修改"preLaunchTask": "flash with stlink"
的预先任务名称flash with stlink
,对应在tasks.json
文件的label
中。
⑤ 注意修改 J-Link json 块的interface/jlink-swd.cfg
,具体参考笔者的一篇博客OpenOCD之J-Link下载。
………………ST-Link 调试json块和J-Link 调试json块以此类推去修改。
//调试脚本
{
"configurations": [
{
"name": "Debug with CMSIS-DAP-link",
"cwd": "${workspaceRoot}",
// "executable": "./build/F401CCU6_demo.elf",
"executable": "./build/${workspaceRootFolderName}.elf", //将工程根目录名称作为可执行文件名称
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32F401CCU6",
"configFiles": [
"interface/cmsis-dap.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface
"target/stm32f4x.cfg" //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\target
],
"svdFile": "./STM32F401.svd", //选择寄存器文件
"liveWatch": { //变量窗口激活和设置每秒的采样次数
"enabled": true,
"samplesPerSecond": 4
},
"searchDir": [],
"runToEntryPoint": "main",
"showDevDebugOutput": "none",
"preLaunchTask": "flash with cmsis-dap-link"
//每次调试之前,会先下载程序再调试
},
{
"name": "Debug with ST-link",
"cwd": "${workspaceRoot}",
// "executable": "./build/F401CCU6_demo.elf",
"executable": "./build/${workspaceRootFolderName}.elf", //将工程根目录名称作为可执行文件名称
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32F401CCU6",
"configFiles": [
"interface/stlink.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface
"target/stm32f4x.cfg" //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\target
],
"svdFile": "./STM32F401.svd", //选择寄存器文件
"liveWatch": { //变量窗口激活和设置每秒的采样次数
"enabled": true,
"samplesPerSecond": 4
},
"searchDir": [],
"runToEntryPoint": "main",
"showDevDebugOutput": "none",
"preLaunchTask": "flash with stlink" //每次调试之前会先下载再调试
},
{
"name": "Debug with J-link",
"cwd": "${workspaceRoot}",
"executable": "./build/${workspaceRootFolderName}.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd", //要选择的GDB server
"device": "STM32F401CCU6",
"configFiles": [
"interface/jlink-swd.cfg", //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\interface
"target/stm32f4x.cfg" //D:\Software\embedded_dev_tools\xpack-openocd-0.12.0-3\openocd\scripts\target
],
"interface": "swd",
"svdFile": "./STM32F401.svd",
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
},
"runToEntryPoint": "main",
"showDevDebugTimestamps": true,
// "preLaunchTask": "build",
"showDevDebugOutput": "none",
"preLaunchTask": "flash with J-link" //每次调试之前会先下载再调试
}
],
"version": "2.0.0"
}
settings.json
该json文件的主要作用:设置VSCode的一些快捷功能,以及配合【Task Buttons插件】来显示编译、重编译、下载、调试等UI按钮。
各项设置可参考笔者的另外一篇博客:点击this。
需要修改处:
修改"C_Cpp.default.compilerPath": "D:/Software/arm_riscv_develop_tools/arm-none-eabi-gcc/10 2021.10/bin/arm-none-eabi-gcc.exe"
的arm-gcc路径,根据您的安装路径并且参考笔者的路径找到复制即可,切记将可执行文件.exe的的名称也复制上。
//UI和功能设置脚本
{
// 字符集编码格式
"files.encoding": "utf8",
// 设置“严格提醒” = enabled/disabled/enabledIfIncludesResolve
// "C_Cpp.errorSquiggles": "disabled",
// 启用文件自动保存
"files.autoSave": "afterDelay",
// 项目各文件的图标主题
"workbench.iconTheme": "office-material-icon-theme",
// 吸血鬼主题
"workbench.colorTheme": "Dracula Theme",
//粘贴时格式化代码
"editor.formatOnPaste": true,
//保存时格式化代码
"editor.formatOnSave": true,
//设置字体的大小,最小值能设置为6
"editor.fontSize": 16,
//设置字体的粗细
"editor.fontWeight": "500",
//设置字体的样式
// "terminal.integrated.fontFamily":"Courier New",
//使用Ctrl+滚轮缩放编辑区的字体大小
"editor.mouseWheelZoom": true,
//使用Ctrl+滚轮缩放终端Terminal的字体大小
"terminal.integrated.mouseWheelZoom": true,
//设置为false,这样打开新的文件时,不会自动关闭旧的文件
"workbench.editor.enablePreview": false,
"security.workspace.trust.enabled": false,
"VsCodeTaskButtons.showCounter": true,
"VsCodeTaskButtons.tasks": [
{
"label": "$(tools) Build",
"task": "build",
"tooltip": "🛠️ build"
},
{
"label": "$(notebook-delete-cell) Clean",
"task": "clean",
"tooltip": "🧹 clean"
},
{
"label": "$(notebook-delete-cell) $(tools) Re-bulid", //"$(notebook-delete-cell) & $(tools)",
"task": "rebuild",
"tooltip": "🛠️ rebuild" // "🧹 & 🛠️ rebuild"
},
{
"label": "$(zap) Download",
// "task": "flash",
"tasks": [
{
"label": "⚓ CMSIS-dap-link", //icon copied from https://emojipedia.org/
"task": "flash with cmsis-dap-link"
},
{
"label": "⤵️ ST-link", //icon copied from https://emojipedia.org/
"task": "flash with ST-link"
},
{
"label": "🚀 J-link", //icon copied from https://emojipedia.org/
"task": "flash with J-link"
}
],
"tooltip": "⚡ Download"
}
],
// "terminal.integrated.defaultProfile.windows": "Git Bash",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.intelliSenseMode": "gcc-arm",
"C_Cpp.default.cStandard": "c99",
"C_Cpp.default.compilerPath": "D:/Software/arm_riscv_develop_tools/arm-none-eabi-gcc/10 2021.10/bin/arm-none-eabi-gcc.exe"
}
c_cpp_properties.json
该json文件的主要作用:选择代码中的宏定义展开defines
,以及MCU的gcc编译路径compilerPath
、MCU的编译选项参数compilerArgs
(或者说MCU的硬件参数)。
需要修改处:
① 修改"name": "STM32F401CCU6"
的名字,根据工程文件和个人偏好修改。
② 修改
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"USE_STDPERIPH_DRIVER",
"STM32F401xx"
]
的"USE_STDPERIPH_DRIVER",
"STM32F401xx"
,根据不同MCU型号修改。
③ 修改"compilerPath": "D:/Software/embedded_dev_tools/xpack-arm-none-eabi-gcc-13.3.1-1.1/bin/arm-none-eabi-gcc.exe"
的arm-gcc路径
④ 修改"compilerArgs": [
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard"
]
编译选项参数,根据不同MCU型号修改。
{
"configurations": [
{
"name": "STM32F401CCU6",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"USE_STDPERIPH_DRIVER",
"STM32F401xx"
],
"compilerPath": "D:/Software/embedded_dev_tools/xpack-arm-none-eabi-gcc-13.3.1-1.1/bin/arm-none-eabi-gcc.exe",
"compilerArgs": [
"-mcpu=cortex-m4",
"-mthumb",
"-mfpu=fpv4-sp-d16",
"-mfloat-abi=hard"
],
"cStandard": "c99",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-arm"
}
],
"version": 4
}
原文地址:https://blog.csdn.net/ZZLLLLLLZ/article/details/144269004
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!