首页 > 解决方案 > Openocd 错误:命令名称“dap”无效 - 无法通过 ST-Link/V2 连接 Blue Pill

问题描述

我正在通过像这样的克隆 ST-Link/V2 使用 Blue Pill 板(根据 st-info --probe 具有 128kB 闪存的 STM32F103CB)。我还使用像这样的正版 ST-Link/V2 进行了测试。我得到了与两个程序员相同的结果,如下所述。

我的系统是 Linux (Debian LXDE),我在这里安装了 Liviu Ionescu 发布的 OpenOCD 。

我的 OpenOCD 安装工作正常。除了 Blue Pill,我还有一个 ST-Nucleo-F103RB 板,我可以使用 OpenOCD 连接到它。命令

openocd -f board/st_nucleo_f103rb.cfg

使用 OpenOCD 附带的标准 .cfg 文件给出

    Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 1000 kHz
adapter_nsrst_delay: 100
none separate
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : Unable to match requested speed 1000 kHz, using 950 kHz
Info : clock speed 950 kHz
Info : STLINK v2 JTAG v29 API v2 SWIM v18 VID 0x0483 PID 0x374B
Info : using stlink api v2
Info : Target voltage: 3.271135
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints

但是我仍然没有设法使用 ST-Link/V2 编程器连接到我的 Blue Pill。我已经阅读了我能找到的所有内容,包括https://elinux.org/Category:OpenOCD的相关部分以及我个人能消化的http://openocd.org/doc/的内容。以下是我必须要去的地方。

.cfg 文件 stm32f103c8_blue_pill.cfg 对我不起作用。它产生如下所述的输出。

根据我读到的内容,我在 ../board/stm32f103.cfg 准备了我自己的 .cfg 文件。它说:

source [find interface/stlink.cfg]
transport select hla_swd
source [find target/stm32f1x.cfg]
#source [find board/stm32f103c8_blue_pill.cfg]
#reset_config srst_only
#reset_config none separate

我读过的资料表明这应该有效,但事实并非如此。使用我上面描述的 .cfg,我可以使用 target/stm32f1x.cfg 或 board/stm32f103c7_blue_pill.cfg,我仍然得到如下所述的相同输出。(对于这两个 .cfg 文件,我使用的是标准文件,与 OpenOCD 一起提供。)我已经使用上面显示的两个 reset_config 变体进行了测试,但都没有。这些组合都不起作用。

我正在使用的文件 interface/stlink.cfg 已修改。我已将其更改为声明正确的 device_desc "ST-LINK/V2" 和正确的 vid_pid 0x0483 0x3748。(两者都使用 lsusb 确认。)因此,忽略注释行,stlink.cfg 读取

interface hla
hla_layout stlink
hla_device_desc "ST-LINK/V2"
hla_vid_pid 0x0483 0x3748

我已经尝试过包含程序员的 hla_serial 。有趣的是,lsusb 找不到完整的序列号。st-info --probe 查找序列号,但给出的编号与 STLinkUpgrade 固件应用程序略有不同。我试过使用两个序列号。没有不同。

这是我给 OpenOCD 的命令:

openocd -s ~/stm32/openocd/scripts -f board/stm32f103.cfg

请注意,我必须为此命令使用 -s 设置路径。使用 ST-Nucleo-F103RB 板,我不必这样做。但是,使用 stm32f103.cfg 文件,如果我不设置路径,我会得到:

Error: Can't find board/stm32f103.cfg
in procedure 'script'

如果我使用上面显示的完整命令,使用 -s 设置路径,我会得到:

Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
/[..]stm32/openocd/scripts/target/stm32f1x.cfg:47: Error: invalid command name "dap"
in procedure 'script' 
at file "embedded:startup.tcl", line 60
at file "/[..]stm32/openocd/scripts/board/stm32f103.cfg", line 18
at file "/[..]stm32/openocd/scripts/target/stm32f1x.cfg", line 47

这是 stm32f1x.cfg 的违规行 47:

dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu

我在 Stackoverflow 上搜索过类似的项目Error: invalid command name "dap"。使用 OpenOCD 文档,我了解dap create命令存在,以及它的作用。我发现记录的最相似的报告错误位于https://elinux.org/OpenOCD_Troubleshooting:_Invalid_Command_Name_JTAG,并且建议的解决方案似乎不适用,因为我没有从命令调用 interface/stlink.cfg线。

我看不出我做错了什么,我现在完全被卡住了。如果有人能给我一个指导,我将非常感激。抱歉,这么长的帖子。

标签: openocdstm32f1bluepill

解决方案


我也刚遇到这个问题。官方没有提供二进制文件,只有源代码。但是 OpenOCD 官方推荐了两个发布二进制文件的站点: 1. 由Freddie Chopin
维护。2. 由 Liviu Ionescu 在Github 维护。

我尝试了OpenOCD 0.10.0 commit date: 2017-01-22 20:31:28 build date: 2017-01-23从 Freddie Chopin 的网站发布的最新版本(),我遇到了这个错误:无效的命令名称“dap”问题。但是*.cfg我引用的所有文件都在我的另一台计算机上正常运行,并带有另一个 OpenOCD 二进制文件(尽管我忘记了我在哪里下载了那个二进制文件)。

不知道出了什么问题,所以我求助于GNU MCU Eclipse(由 Liviu Ionescu 维护gnu-mcu-eclipse-openocd-0.10.0-11-20190118-1134-win64.zip)发布的最新版本() ,错误消失了,问题解决了。

PS:我并不是说 Freddie Chopin 的构建中有错误,但是如果有人遇到这个问题,也许你可以通过尝试当前正在积极维护的版本来解决它。


推荐阅读