美文网首页
vscode通过task让其有编译下载工程,甚至在线仿真的能力

vscode通过task让其有编译下载工程,甚至在线仿真的能力

作者: vencol | 来源:发表于2023-01-30 10:47 被阅读0次

理论上这个方法适合于绝大多数的软件工程代码,不仅仅局限于make、gn、nijia、grade等,或者直接通过脚本执行,凡是可以通过命令编译的软件工程代码,都可以把vscode改成对应的ide进行coding。不管是Windows还是linux,修改的task.json,都在当前工作空间的.vscode文件夹中,如果没有请通过Terminal ---> Configure Tasks 打开

image.png
PS:从0开始,利用wsl+vscode+gdb实现linux应用层软件的开发调试 - 简书 (jianshu.com)
PS:不想用Android Studio,教你如何用vscode搭建原生app开发环境 - 简书 (jianshu.com)

一、 在Windows上可以通过如下的形式把相应的命令集成到vscode

    "version": "2.0.0",
    "tasks": [
        {
            "label": "rebuild_mouse",
            "type": "shell",
            // "command": "D:\\Keil_v5\\UV4\\UV4.exe -r e:\\item\\221223-Realtek2k\\2022_12_15trimouse_dongle_sdk_v1.0.1.2\\board\\evb\\trimode_mouse\\mdk\\trimode_mouse.uvprojx -j0 -t trimode_mouse -o e:\\item\\221223-Realtek2k\\2022_12_15trimouse_dongle_sdk_v1.0.1.2\\board\\evb\\trimode_mouse\\mdk\\.vscode\\uv4.log; cat e:\\item\\221223-Realtek2k\\2022_12_15trimouse_dongle_sdk_v1.0.1.2\\board\\evb\\trimode_mouse\\mdk\\.vscode\\uv4.log",
            "command": "UV4 -r trimode_mouse.uvprojx -j0 -t trimode_mouse -o .vscode\\uv4.log | Out-Null; cat .vscode\\uv4.log",
            "options": {
                "shell": {"executable": "PowerShell"},
                "cwd": "e:\\item\\221223-Realtek2k\\2022_12_15trimouse_dongle_sdk_v1.0.1.2\\board\\evb\\trimode_mouse\\mdk",
            },
            "presentation": {
                "reveal": "always",
                "echo": true,
                "clear": true,
                "panel": "shared"
            },
            "problemMatcher": []
        },
        {
            "label": "build_mouse",
            "type": "shell",
            // "command": "D:\\Keil_v5\\UV4\\UV4.exe -b e:\\item\\221223-Realtek2k\\2022_12_15trimouse_dongle_sdk_v1.0.1.2\\board\\evb\\trimode_mouse\\mdk\\trimode_mouse.uvprojx -j0 -t trimode_mouse -o e:\\item\\221223-Realtek2k\\2022_12_15trimouse_dongle_sdk_v1.0.1.2\\board\\evb\\trimode_mouse\\mdk\\.vscode\\uv4.log; cat e:\\item\\221223-Realtek2k\\2022_12_15trimouse_dongle_sdk_v1.0.1.2\\board\\evb\\trimode_mouse\\mdk\\.vscode\\uv4.log",
            "command": "UV4 -b trimode_mouse.uvprojx -j0 -t trimode_mouse -o .vscode\\uv4.log | Out-Null; cat .vscode\\uv4.log",
            "options": {
                "shell": {"executable": "PowerShell"},
                "cwd": "e:\\item\\221223-Realtek2k\\2022_12_15trimouse_dongle_sdk_v1.0.1.2\\board\\evb\\trimode_mouse\\mdk",
            },
            "presentation": {
                "reveal": "always",
                "echo": true,
                "clear": true,
                "panel": "shared"
            },
            "problemMatcher": []
        },
      ]

二、 在linux(使用ssh后,可以直接windows设置)上可以通过如下的形式把相应的命令集成到vscode

    "version": "2.0.0",
    "tasks": [
        {
            "label": "km4_make",
            "type": "shell",
            "command": "make 2>&1 | tee ./asdk/image/build.log ",
            "options": {
                "cwd": "/home/iton/hms/realtek/sdk-RTL872XEA_v10.1a_beta/project/realtek_amebaLite_va0_example/GCC-RELEASE/project_km4"
            },
            "presentation": {
                "reveal": "always",
                "echo": true,
                "clear": true,
                "panel": "shared"
            },
            "problemMatcher": []
        },
        {
            "label": "km4_make_mp",
            "type": "shell",
            "command": "make mp 2>&1 | tee ./asdk/image/build.log ",
            "options": {
                "cwd": "/home/iton/hms/realtek/sdk-RTL872XEA_v10.1a_beta/project/realtek_amebaLite_va0_example/GCC-RELEASE/project_km4"
            },
            "presentation": {
                "reveal": "always",
                "echo": true,
                "clear": true,
                "panel": "shared"
            },
            "problemMatcher": []
        },

三、 task.json对应的配置说明
具体请参考VSCode中Task的使用_ljc204822324的博客-CSDN博客_vscode 执行task

四、 通过keybindings.json配置相应task对应的快捷键,其实就配置一个F7就可以了

image.png
    {
        "key": "F7",                    // ctrl+right  alt+right配置快捷键
        "command": "workbench.action.tasks.runTask",    // runtask
       // "args": "build_mouse"    //  task的名称,对应定义的label,不定义更换,可以弹框选择对应的task
    },
    {
        "key": "F8",
        "command": "workbench.action.tasks.runTask",
        "args": "rebuild_mouse"
    }
image.png
五、 使用socat使主机和虚拟机之间进行命令行通讯(网络安全需要另外处理)
  1. win可以使用开源仓库下的socat,honuonhval/socat-win10: Compiled socat for Windows 10 included instruction for reproducibility (github.com)

  2. 把win的socat加入到对应的路径的系统的环境变量path中


  3. 在win下,写下如下setsocat.bat文件,作用是把win主机作为一个可供远程连接的shell终端,这样当linux客户端连接的时候,可以直接使用命令行操作(注意网络安全)

@echo off
:start
    socat TCP-LISTEN:12345,forever,reuseaddr EXEC:sh,pty,stderr
goto start
pause
  1. 在终端执行setsocat.bat脚本,建议不要放到后台,需要使用的时候才开启,比较socat没有自动处理网络安全问题
  2. linux可以使用git仓库,Releases · 3ndG4me/socat (github.com),同win把对应的路径加入到linux的环境变量中
  3. 在linux终端,执行测试命令(主机ip为),echo "git -v" | socat - tcp:192.168.78.1:12345,这里建议使用虚拟网卡的地址,这样网络安全直接限制虚拟网卡的网段就好。这里的git -v可以随意设置,只是通过这个可以明确的看到时linux访问win的提示,如下图
  4. 有了上面的功能,就可以在vscode的task里面加入linux调用win,或者win调用linux的指令了

六、 通过jlink gdb方式添加gdb调试方法

  1. 开启gdbserver,不同芯片有所不同,大概如下
"D:\Program Files (x86)\SEGGER\JLink\JLinkGDBServerCL.exe" -device RISC-V -if SWD -speed 1000 -JLinkScriptFile "E:\item\202030129-haisi\sdk\jlink\ConnectCore1.JLinkScript" 
  1. 配置lunch.json文件
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gdb app",
            "type": "cppdbg",
            "request": "launch",
            "program": "E:\\item\\202030129-haisi\\sdk\\sdk\\output\\bs25\\application_core\\standard-bs25-app-fpga\\application.elf",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\item\\202030129-haisi\\sdk\\sdk\\tools\\bin\\compiler\\linx\\linx_131\\hcc_riscv32_musl_1.2.0.B050\\hcc_riscv32_musl_win\\bin\\riscv32-linux-musl-gdb.exe",
            "miDebuggerServerAddress": "localhost:2331",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        },
    ]
}
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "gdb server",
            "type": "shell",
            "command": "cmd mcu_gdb.bat",
            "options": {
                "shell": {"executable": "PowerShell"},
                "cwd": "E:\\item\\202030129-haisi\\sdk\\jlink",
            },
            "presentation": {
                "reveal": "always",
                "echo": true,
                "clear": true,
                "panel": "shared"
            },
            "problemMatcher": []
        },
        {
            "label": "build app",
            "type": "shell",
            "command": "python ./build.py standard-bs25-app-fpga -j8 ; python tools/pkg/bs25_packet.py",
            "options": {
                "shell": {"executable": "PowerShell"},
                "cwd": "E:\\item\\202030129-haisi\\sdk\\sdk",
            },
            "presentation": {
                "reveal": "always",
                "echo": true,
                "clear": true,
                "panel": "shared"
            },
            "problemMatcher": []
        },
        {
            "label": "rebuild app",
            "type": "shell",
            "command": "python ./build.py standard-bs25-app-fpga -c -j8 ; python tools/pkg/bs25_packet.py",
            "options": {
                "shell": {"executable": "PowerShell"},
                "cwd": "E:\\item\\202030129-haisi\\sdk\\sdk",
            },
            "presentation": {
                "reveal": "always",
                "echo": true,
                "clear": true,
                "panel": "shared"
            },
            "problemMatcher": []
        },
    ]
}
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gdb app",
            "type": "cppdbg",
            "request": "launch",
            "program": "E:\\item\\202030129-haisi\\sdk\\sdk\\output\\bs25\\application_core\\standard-bs25-app-fpga\\application.elf",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\item\\202030129-haisi\\sdk\\sdk\\tools\\bin\\compiler\\linx\\linx_131\\hcc_riscv32_musl_1.2.0.B050\\hcc_riscv32_musl_win\\bin\\riscv32-linux-musl-gdb.exe",
            "miDebuggerServerAddress": "localhost:2331",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        },
    ]
}

相关文章

网友评论

      本文标题:vscode通过task让其有编译下载工程,甚至在线仿真的能力

      本文链接:https://www.haomeiwen.com/subject/yvsmhdtx.html