pyocd / pyOCD

Open source Python library for programming and debugging Arm Cortex-M microcontrollers
https://pyocd.io
Apache License 2.0
1.13k stars 484 forks source link

pyocd 0.36.0, VS Code and Zephyr #1706

Open rtborg opened 4 months ago

rtborg commented 4 months ago

I'm using pyocd 0.36.0 and STM32F303K8Tx. My VS Code launch configuration is:

{
    "name": "Launch Nucleo F303K8",
    "device": "STM32F303K8Tx",
    "cwd": "${workspaceFolder}",
    "executable": "build/zephyr/zephyr.elf",
    "request": "launch",
    "type": "cortex-debug",
    "runToEntryPoint": "main",
    "servertype": "pyocd",
    "gdbPath": "${userHome}/zephyr-sdk-0.16.5-1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb",
    "preLaunchTask": "West Build",
    "showDevDebugOutput": "both"
}

The output I get when launching is below:

"configuration": {
    "name": "Launch Nucleo F303K8",
    "device": "STM32F303K8Tx",
    "cwd": "/home/void/Documents/projects/zephyr/mimxrt1060_projects/app",
    "executable": "/home/void/Documents/projects/zephyr/mimxrt1060_projects/app/build/zephyr/zephyr.elf",
    "request": "launch",
    "type": "cortex-debug",
    "runToEntryPoint": "main",
    "servertype": "pyocd",
    "gdbPath": "/home/void/zephyr-sdk-0.16.5-1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb",
    "preLaunchTask": "West Build",
    "showDevDebugOutput": "both",
    "__configurationTarget": 5,
    "gdbServerConsolePort": 60000,
    "pvtAvoidPorts": [],
    "chainedConfigurations": {
        "enabled": false
    },
    "debuggerArgs": [],
    "swoConfig": {
        "enabled": false,
        "decoders": [],
        "cpuFrequency": 0,
        "swoFrequency": 0,
        "source": "probe"
    },
    "rttConfig": {
        "enabled": false,
        "decoders": []
    },
    "graphConfig": [],
    "preLaunchCommands": [],
    "postLaunchCommands": [],
    "preAttachCommands": [],
    "postAttachCommands": [],
    "preRestartCommands": [],
    "postRestartCommands": [],
    "preResetCommands": [],
    "postResetCommands": [],
    "toolchainPrefix": "arm-none-eabi",
    "extensionPath": "/home/void/.vscode/extensions/marus25.cortex-debug-1.12.1",
    "registerUseNaturalFormat": true,
    "variableUseNaturalFormat": true,
    "pvtVersion": "1.12.1",
    "__sessionId": "92fd644d-1ce3-4385-a456-128c973442cc",
    "pvtShowDevDebugOutput": "both"
}
Reading symbols from /home/void/zephyr-sdk-0.16.5-1/arm-zephyr-eabi/bin/arm-zephyr-eabi-objdump --syms -C -h -w /home/void/Documents/projects/zephyr/mimxrt1060_projects/app/build/zephyr/zephyr.elf
Reading symbols from /home/void/zephyr-sdk-0.16.5-1/arm-zephyr-eabi/bin/arm-zephyr-eabi-nm --defined-only -S -l -C -p /home/void/Documents/projects/zephyr/mimxrt1060_projects/app/build/zephyr/zephyr.elf
Launching GDB: /home/void/zephyr-sdk-0.16.5-1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gdb -q --interpreter=mi2
1-gdb-version
Launching gdb-server: pyocd gdbserver --port 50000 --telnet-port 50001
    Please check TERMINAL tab (gdb-server) for output from pyocd
Finished reading symbols from objdump: Time: 16 ms
Failed to launch PyOCD GDB Server: Error: spawn pyocd ENOENT

And the terminal tab output:

[2024-07-07T16:45:37.815Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session connected. You can switch to "DEBUG CONSOLE" to see GDB interactions.
pyocd gdbserver --port 50000 --telnet-port 50001
[2024-07-07T16:45:39.945Z] SERVER CONSOLE DEBUG: onBackendConnect: gdb-server session closed
GDB server session ended. This terminal will be reused, waiting for next session to start...

When running west debug, everything seems to work fine, but I want to get debugging working from VS code.

hagibr commented 3 months ago

I think you need to specify the target. Add these lines to launch.json:

      "serverArgs": [
        "-t", "STM32F303K8Tx"
      ],

I'm assuming that you've already have the cmsis pack installed. If not, also install it by executing pyocd pack install STM32F303K8Tx