Arch Linux VSCODE使用 pyocd + Cortex-Debug 结合 DAPLINK 或者 Jlink 调试

环境搭建

VSCODE 安装 Cortex-Debug

安装 python3

1
sudo pacman -S python

安装 pyocd

1
pip3 install --user --break-system-packages pyocd

之所以选择用pyocd 是因为pyocd 用起来简单而且通用, 它可以指定pack 包, 对于一些小众芯片很有用
并且可以自适应 DAPLINK 和 JLINK

安装 arm-none-eabi-gdb

由于我使用的工具链的版本是 11.2.1, 该版本的 arm-none-eabi-gdb 依赖于 python3.6 的库, 而我本身的python 环境已经升级到python3.12
所以用不了, 只能另外安装新arm-none-eabi-gdb

1
2
3
yay -S arm-none-eabi-gdb
cp /home/wcq/tools/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb /home/wcq/tools/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb_bak
ln -sf /usr/bin/arm-none-eabi-gdb /home/wcq/tools/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb

以上命令安装 arm-none-eabi-gdb 之后把工具链的gdb 改个名字, 再新建个软链接, 这样只arm-none-eabi-gdb 的路径写入 launch.json
或者在Cortex-Debug 的设置里面设置一下就可以了

基本用法

新建 .vscode/launch.json

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Cortex Debug",
            "cwd": "${workspaceFolder}",
            "executable": "build/SGK_HIGH_FAN.elf",
            "request": "launch",
            "type": "cortex-debug",
            "runToEntryPoint": "main",
            "servertype": "external",
            "gdbTarget": "localhost:3333",
            "gdbPath" : "/home/wcq/tools/gcc-arm-11.2-2022.02-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb",
            "svdFile": "/home/wcq/work/SGK32F031_DFP.Pack.1.1.1/SVD/SGK32F031.svd"
        }
    ] 
}

如果不需要看外设寄存器可以不用设置 svdFile

在外部启动 gdb server

1
pyocd gdbserver --target=SGK32F031XXXX --pack=/home/wcq/work/gen_packs/PACK/new_pack/SGK32F031_DFP.Pack.1.1.1.pack

这会启动一个gdbserver 会自动识别调试器, 支持 DAPLINK 和 JLINK

在 VSCODE 中启动 Cortex-Debug

Licensed under CC BY-NC-SA 4.0