Using Visual Code with Zephyr (linux) some useful info

Hi Guys,

I have been working on getting VSCode/Zephyr on linux, working to build, flash and debug. Intellisense also works for all the zephyr code.

It’s a bit of a bodge but it works!

So In your zephyrproject folder create a .vscode folder and add the following three files:

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Uno Q Attach",
            "cwd": "${workspaceFolder}",
            "type": "cppdbg",
            "request": "launch",
            "program": "./zephyr/build/zephyr/zephyr.elf",
            "MIMode": "gdb",
            "miDebuggerServerAddress": "127.0.0.1:3333",
            "miDebuggerPath": "${userHome}/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb-py"
        },
        {
            "name": "Uno Q launch",
            "preLaunchTask": "Flash",
            "cwd": "${workspaceFolder}",
            "type": "cppdbg",
            "request": "launch",
            "program": "./zephyr/build/zephyr/zephyr.elf",
            "MIMode": "gdb",
            "miDebuggerServerAddress": "127.0.0.1:3333",
            "miDebuggerPath": "${userHome}/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb-py"
        }
    ]
}

settings.json:

{
    "C_Cpp.default.compileCommands": [
        "zephyr/build/compile_commands.json"
    ]
}

tasks.json:

{
  "version": "2.0.0",
  "tasks": [
    {
        "label": "Flash",
        "dependsOn": "West Build App",
        "type": "shell",
        "command": "${userHome}/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb-py -ex 'target extended-remote :3333' -ex 'set pagination off' /home/andrewcapon/zephyrproject/zephyr/build/zephyr/zephyr.elf -ex load -ex='set confirm off' -ex exit",
        "problemMatcher": []
    },
    {
        "label": "West Build App",
        "options": {
            "cwd": "${workspaceFolder}/zephyr"
        },
        "type": "process",
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "command": "west",
        "args": [
            "build"
        ],
        "problemMatcher": [ "$gcc" ]
   },
]
}

Visual code needs to be started from your venv:

(.venv) :~/zephyrproject$ code .

Now you can build and flash, there are two debug options one will just attach, the other with build and flash.

You need to have the adb port forwarding and opened running on the board:

From linux host:adb forward tcp:3333 tcp:3333 && adb shell arduino-debug

You also need to have built from the command line once for the project before using this.

Hopefully this is useful for someone…

5 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.