使用 OpenOCD 调试 STM32,用于 VSCODE 的 STM32 无法工作或闪烁,可能是配置问题?

问题描述

首先,对于大多数人来说,我用谷歌搜索了很多,搜索了一周,根本没有解决方案。请和我一起裸体!

我尝试添加所有必要的信息!如果您需要,请请求更多。

我的问题是:

我正在尝试使用 STM32-for-vscode、OpenOCD 和 Cortex 调试在 Vscode 中调试带有骨架代码项目的 STM32 bluepill 板,但没有任何成功。调试会话失败!

我的环境是:

1- Mac OS Big Sur 版本 11.1 (20C69)。

2- VSCODE。

3- Cortex 调试插件

4- STM32-for-Vscode 插件

5- ARM 插件

6- 该项目是根据 STM32-for-Vscode 指令使用 STM32CubeMax 创建的骨架代码

7- Brew "Opened --HEAD" 版本应该与 Cortex 调试插件一起使用。

8- 使用带有 STlink V2.1 固件的 STM32f103c8 bluepill 作为 STlink 加密狗。我已经编辑了 .cfg 文件以允许使用非正版 STM32 cpu ID。

9- 使用 stm32f103c8 bluepill 作为目标板上传代码和调试。

请注意完全相同的硬件集与 PlatformIO 完美配合,并且可以正确刷新和调试。

Launch.json 配置:

{
    "configurations": [
        {
            "showDevDebugOutput": true,"cwd": "${workspaceRoot}","executable": "./build/SkeletonCode.elf","name": "Debug STM32","request": "launch","type": "cortex-debug","servertype": "openocd","prelaunchTask": "Build STM","device": "stlink","configFiles": [
                "interface/stlink.cfg","target/stm32f1x.cfg"
            ]
        }
    ]
}

tasks.json 配置

{
    "version": "2.0.0","tasks": [
        {
            "label": "Build STM","type": "process","command": "${command:stm32-for-vscode.build}","options": {
                "cwd": "${workspaceRoot}"
            },"group": {
                "kind": "build","isDefault": true
            },"problemmatcher": [
                "$gcc"
            ]
        },{
            "label": "Build Clean STM","command": "${command:stm32-for-vscode.cleanBuild}",{
            "label": "Flash STM","command": "${command:stm32-for-vscode.flash}","problemmatcher": [
                "$gcc"
            ]
        }
    ]
}

当我开始调试时,我在 movs r1,#0 上的 启动文件 中获得了代码控制 使用以下调试器控件:

输出

Open On-Chip Debugger 0.11.0-rc2+dev-g427552c-dirty (2021-01-30-10:09)
Licensed under GNU GPL v2
For bug reports,read
    http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J37S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 5.022309
Info : stm32f1x.cpu: hardware has 6 breakpoints,4 watchpoints
Info : starting gdb server for stm32f1x.cpu on 50000
Info : Listening on port 50000 for gdb connections
Info : accepting 'gdb' connection on tcp/50000
target halted due to debug-request,current mode: Handler HardFault
xPSR: 0x01000003 pc: 0xfffffffe msp: 0xffffffd8
Info : device id = 0x20036410
Info : flash size = 64kbytes
target halted due to debug-request,current mode: Thread 
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
target halted due to debug-request,current mode: Thread 
xPSR: 0x01000000 pc: 0x08000974 msp: 0x20005000

Error: jtag status contains invalid mode value - communication failure
Polling target stm32f1x.cpu Failed,trying to reexamine
Examination Failed,GDB will be halted. Polling again in 100ms
Info : PrevIoUs state query Failed,trying to reconnect
Error: jtag status contains invalid mode value - communication failure
Polling target stm32f1x.cpu Failed,GDB will be halted. Polling again in 300ms
Info : PrevIoUs state query Failed,GDB will be halted. Polling again in 700ms
Info : PrevIoUs state query Failed,GDB will be halted. Polling again in 1500ms
Info : PrevIoUs state query Failed,GDB will be halted. Polling again in 3100ms
Info : PrevIoUs state query Failed,GDB will be halted. Polling again in 6300ms
Info : PrevIoUs state query Failed,GDB will be halted. Polling again in 6300ms

调试控制台输出

Reading symbols from '/Users/engmoh/Embedded/VSCODE_Projects/2-STM32_Skeleton/build/SkeletonCode.elf'
Finished reading symbols
Please check OUTPUT tab (Adapter Output) for output from /usr/local/bin/openocd
Launching server: "/usr/local/bin/openocd" "-c" "gdb_port 50000" "-s" "/Users/engmoh/Embedded/VSCODE_Projects/2-STM32_Skeleton" "-f" "interface/stlink.cfg" "-f" "target/stm32f1x.cfg"
Launching GDB: "arm-none-eabi-gdb" "-q" "--interpreter=mi2"
1-gdb-set target-async on
2-interpreter-exec console "source /Users/engmoh/.vscode/extensions/marus25.cortex-debug-0.3.10/support/gdbsupport.init"
3-target-select extended-remote localhost:50000
4-interpreter-exec console "monitor reset halt"
5-target-download
6-interpreter-exec console "monitor reset halt"
7-enable-pretty-printing
GDB -> App: {"outOfBandRecord":[{"isstream":false,"type":"notify","asyncclass":"thread-group-added","output":[["id","i1"]]}]}
GDB -> App: {"outOfBandRecord":[{"isstream":true,"type":"console","content":"Reading symbols from /Users/engmoh/Embedded/VSCODE_Projects/2-STM32_Skeleton/build/SkeletonCode.elf...\n"}]}
Reading symbols from /Users/engmoh/Embedded/VSCODE_Projects/2-STM32_Skeleton/build/SkeletonCode.elf...
GDB -> App: {"token":1,"outOfBandRecord":[],"resultRecords":{"resultClass":"done","results":[]}}
GDB -> App: {"token":2,"results":[]}}
GDB -> App: {"outOfBandRecord":[{"isstream":false,"asyncclass":"thread-group-started","i1"],["pid","42000"]]}]}
GDB -> App: {"outOfBandRecord":[{"isstream":false,"asyncclass":"thread-created","1"],["group-id","content":"0xfffffffe in ?? ()\n"}]}
0xfffffffe in ?? ()
GDB -> App: {"outOfBandRecord":[{"isstream":false,"type":"exec","asyncclass":"stopped","output":[["frame",[["addr","0xfffffffe"],["func","??"],["args",[]],["arch","armv7"]]],["thread-id",["stopped-threads","all"]]}]}
Not implemented stop reason (assuming exception): undefined
GDB -> App: {"token":3,"resultRecords":{"resultClass":"connected","results":[]}}
8-thread-list-ids
GDB -> App: {"outOfBandRecord":[{"isstream":true,"type":"target","content":"target halted due to debug-request,current mode: Thread \n"}]}
target halted due to debug-request,current mode: Thread
GDB -> App: {"outOfBandRecord":[{"isstream":true,"content":"xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc\n"}]}
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
GDB -> App: {"token":4,"results":[]}}
9-thread-list-ids
GDB -> App: {"token":5,"outOfBandRecord":[{"isstream":false,"type":"status","asyncclass":"download","output":[]}]}
GDB -> App: {"token":5,"results":[["address","0x08000974"],["load-size","4116"],["transfer-rate","159072"],["write-rate","686"]]}}
GDB -> App: {"outOfBandRecord":[{"isstream":true,"content":"\n"}]}

GDB -> App: {"outOfBandRecord":[{"isstream":true,"content":"jtag status contains invalid mode value - communication failure\n"}]}
jtag status contains invalid mode value - communication failure
GDB -> App: {"outOfBandRecord":[{"isstream":true,"content":"Polling target stm32f1x.cpu Failed,trying to reexamine\n"}]}
Polling target stm32f1x.cpu Failed,trying to reexamine
GDB -> App: {"outOfBandRecord":[{"isstream":true,"content":"Examination Failed,GDB will be halted. Polling again in 100ms\n"}]}
Examination Failed,GDB will be halted. Polling again in 100ms
GDB -> App: {"token":6,"results":[]}}
GDB -> App: {"token":7,"results":[]}}
10-break-insert "/Users/engmoh/Embedded/VSCODE_Projects/2-STM32_Skeleton/Core/Src/main.c:63"
GDB -> App: {"token":8,"results":[["thread-ids",[["thread-id","1"]]],["current-thread-id",["number-of-threads","1"]]}}
11-thread-info 1
GDB -> App: {"token":9,"1"]]}}
12-thread-info 1
GDB -> App: {"outOfBandRecord":[{"isstream":true,"content":"Note: automatically using hardware breakpoints for read-only addresses.\n"}]}
Note: automatically using hardware breakpoints for read-only addresses.
GDB -> App: {"token":10,"results":[["bkpt",[["number",["type","breakpoint"],["disp","keep"],["enabled","y"],["addr","0x080001a4"],"main"],["file","Core/Src/main.c"],["fullname","/Users/engmoh/Embedded/VSCODE_Projects/2-STM32_Skeleton/Core/Src/main.c"],["line","72"],["thread-groups",["i1"]],["times","0"],["original-location","/Users/engmoh/Embedded/VSCODE_Projects/2-STM32_Skeleton/Core/Src/main.c:63"]]]]}}
GDB -> App: {"token":11,"results":[["threads",[[["id",["target-id","Remote target"],["frame",[["level","Reset_Handler"],"startup_stm32f103xb.s"],"/Users/engmoh/Embedded/VSCODE_Projects/2-STM32_Skeleton/startup_stm32f103xb.s"],"65"],["state","stopped"]]]]]}}
GDB -> App: {"token":12,"stopped"]]]]]}}
13-stack-info-depth --thread 1 10000
GDB -> App: {"token":13,"results":[["depth","1"]]}}
14-stack-list-frames --thread 1 0 0
GDB -> App: {"token":14,"results":[["stack",[["frame","armv7"]]]]]]}}
15-thread-list-ids
GDB -> App: {"token":15,"1"]]}}
16-thread-info 1
17-data-list-register-names
GDB -> App: {"token":16,"stopped"]]]]]}}
GDB -> App: {"token":17,"results":[["register-names",["r0","r1","r2","r3","r4","r5","r6","r7","r8","r9","r10","r11","r12","sp","lr","pc","","xPSR","msp","psp","primask","basepri","faultmask","control"]]]}}
18-stack-info-depth --thread 1 10000
GDB -> App: {"token":18,"1"]]}}
19-stack-list-frames --thread 1 0 0
GDB -> App: {"token":19,"armv7"]]]]]]}}
20-stack-info-depth --thread 1 10000
GDB -> App: {"token":20,"1"]]}}
21-stack-list-frames --thread 1 0 0
GDB -> App: {"token":21,"armv7"]]]]]]}}
22-thread-list-ids
GDB -> App: {"token":22,"1"]]}}
23-thread-info 1
GDB -> App: {"token":23,"stopped"]]]]]}}
24-data-list-register-values N
GDB -> App: {"token":24,"results":[["register-values",[[["number",["value","0"]],"2"],"3"],"4"],"5"],"6"],"7"],"8"],"9"],"10"],"11"],"12"],"13"],"0xffffffd8"]],"14"],"-7"]],"15"],"0x8000974 <Reset_Handler>"]],"25"],"16777219"]],"91"],"0x20005000"]],"92"],"0x0"]],"93"],"94"],"95"],"96"],"0"]]]]]}}
25-stack-list-variables --thread 1 --frame 0 --simple-values
GDB -> App: {"token":25,"results":[["variables",[]]]}}
26-data-evaluate-expression --thread 1 --frame 0 LoopcopyDataInit
GDB -> App: {"token":26,"results":[["value","{<text variable,no debug info>} 0x8000980 <Reset_Handler+12>"]]}}
27-data-evaluate-expression --thread 1 --frame 0 Reset_Handler
GDB -> App: {"token":27,no debug info>} 0x8000974 <Reset_Handler>"]]}}
28-data-evaluate-expression --thread 1 --frame 0 .weak
GDB -> App: {"token":28,"resultRecords":{"resultClass":"error","results":[["msg","A Syntax error in expression,near `.weak'."]]}}
hover: A Syntax error in expression,near `.weak'. (from data-evaluate-expression --thread 1 --frame 0 .weak)

一旦我从调试器控件中单击进入,我就会得到以下控制台输出

DB -> App: {"token":29,"results":[["frame","armv7"]]]]}}
30-exec-step --thread 1
GDB -> App: {"token":30,"resultRecords":{"resultClass":"running","asyncclass":"running","output":[["thread-id","all"]]}]}
GDB -> App: {"outOfBandRecord":[{"isstream":true,"type":"log","content":"Warning:\n"}]}
Warning:
GDB -> App: {"outOfBandRecord":[{"isstream":true,"content":"Cannot insert hardware breakpoint 1.\n"}]}
Cannot insert hardware breakpoint 1.
GDB -> App: {"outOfBandRecord":[{"isstream":true,"content":"Could not insert hardware breakpoints:\n"}]}

虽然,我根本没有设置任何断点!

在 **Output ** 我得到:

Info : dropped 'gdb' connection
shutdown command invoked

然后调试器控件按钮变灰了!我的 MCU 变砖了,我需要使用 UART 连接擦除它才能让它恢复工作!

怎么办?如何能够使用我的环境对该板进行编程和调试!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)