visual-studio-codegdbcortex-mraspberry-pi-picoopenocd

How to add arguments to launch.json in VS Code


I am trying to debug the RP2040 using the new picoprobe. When i execute the following command openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" OpenOCD works without an issue.

I just need to add -c "adapter speed 5000" to my launch.json for it to work. I tired "args": ["arg1", [arg2], ... ] but it fails and doesnot consider.

here is my launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Pico Debug",
            "cwd": "${workspaceRoot}",
            "executable": "${command:cmake.launchTargetPath}",
            "request": "launch",
            "type": "cortex-debug",
            "servertype": "openocd",
            // This may need to be "arm-none-eabi-gdb" for some previous builds
            "gdbPath" : "gdb-multiarch",
            //"gdbPath" : "arm-none-eabi-gdb",
            "device": "RP2040",
            "configFiles": [
                // This may need to be "interface/picoprobe.cfg" for some previous builds
                "interface/cmsis-dap.cfg",
                "target/rp2040.cfg"
            ],
            "preLaunchCommands": [
                "adapter speed 5000"
            ],
            "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd",
            "runToEntryPoint": "main",
            // Work around for stopping at main on restart
            "postRestartCommands": [
                "break main",
                "continue"
            ]
        }
    ]
}

When i execute the following command openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000" OpenOCD works without an issue.

I just need to add -c "adapter speed 5000" to my launch.json for it to work. I tired "args": ["arg1", [arg2], ... ] but it fails and doesnot consider.


Solution

  • The field you're looking for is openOCDLaunchCommands, taking a collection of commands.

    I found this by starting a new line in the configurations block and pressing ctrl+space to bring up the auto-complete menu. If anyone has a link to documentation that would help solve this in a less serendipidous way, please share.

    Add this to the configurations block

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Pico Debug",
                "cwd": "${workspaceRoot}",
    
                ...
    
                "openOCDLaunchCommands": [
                    "adapter speed 5000"
                ]
            }
        ]
    }