如何使用 OpenOCD 同时与两个 STM32 板对话?

How to use OpenOCD to talk to two STM32 boards at once?

假设我有两个 STM32,我正在使用这个编程器 here

我想分别连接到它们和debug/reflash/itterate。

所以,我的设置如下:

硬件

PC |-> USB1 -> ST-LINK-Programmer1 -> STM32_Board1 |-> USB2 -> ST-LINK-Programmer2 -> STM32_Board2

西南

他们通常用一块板来做这个的方式非常简单。

openocd -f config.cfg

这是我正在调用的配置文件:

source [find interface/stlink-v2.cfg] transport select hla_swd source [find target/stm32f4x.cfg] reset_config none

然后,在另一个终端中,我这样调用 arm-gdb:

arm-none-eabi-gdb build/FW.elf

在 ~/.gdbinit 中,我有一行:

target remote localhost:3333

什么不起作用

这很明显...我为第一个 OpenOCD 使用端口 3333,但第二个实例试图使用相同的端口并失败

Error: couldn't bind tcl to socket: Address already in use

我试过的

我查看了文档 here,但我没有看到如何在我的 config.cfg 文件中调用这些选项。

我也试过将这些关于 tcl_port 和 gdb_port 的命令添加到实际的命令行参数中,比如 openocd -f config.cfg -c tcl_port 4444,但这也不起作用...套接字仍在使用中。

我真正的问题

正确的做法是什么?在配置 openocd 以便连接到正确的 OpenOCD 实例之后,是否有任何 gotchas 处理 arm-none-eabi-gdb?

stlinkv2.cfg 来自 openocd

#
# STMicroelectronics ST-LINK/V2 in-circuit debugger/programmer
#

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

# Optionally specify the serial number of ST-LINK/V2 usb device.  ST-LINK/V2
# devices seem to have serial numbers with unreadable characters.  ST-LINK/V2
# firmware version >= V2.J21.S4 recommended to avoid issues with adapter serial
# number reset issues.
# eg.
#hla_serial "\xaa\xbc\x6e\x06\x50\x75\xff\x55\x17\x42\x19\x3f"

你的配置正在采购这个,注释掉该文件行的源并替换为这个

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

无论特定的 stlinks 序列号是什么(希望它们有所不同)

为每个重复一个新配置,然后为每个更改 tcp/gdb 端口号,我从不使用 gdb,所以我

telnet_port 4442
gdb_port 0
tcl_port 0

lsusb -vvv

Bus 002 Device 011: ID 0483:374b STMicroelectronics ST-LINK/V2.1 (Nucleo-F103RB)
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 ?
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x0483 STMicroelectronics
  idProduct          0x374b ST-LINK/V2.1 (Nucleo-F103RB)
  bcdDevice            1.00
  iManufacturer           1 STMicroelectronics
  iProduct                2 STM32 STLink
  iSerial                 3 12345623498723497
  bNumConfigurations      1

我编造了那个 iSerial 号码不是我的真实号码,如果每个人都知道这个板的真实号码可能无关紧要...

我没有尝试使用两块板,如果我添加 hla_serial 行并使用 iSerial 编号,那么它就会发挥作用。如果我修改序列号使其不匹配,它会改变 openocd 的工作方式,它找不到 stlink。我将不得不挖掘更多的电路板来全面测试这个,但你已经有了这些电路板,所以会让你看看这是否适合你。

texane/stlink 中还有一个名为 st-info 的非常方便的实用程序,可帮助查找 ST-LINK 程序员的序列号,例如:

$ st-info --probe
Found 2 stlink programmers
 serial: 543f6e06723f495507372267
openocd: "\x54\x3f\x6e\x06\x72\x3f\x49\x55\x07\x37\x22\x67"
  flash: 16384 (pagesize: 128)
   sram: 8192
 chipid: 0x0457
  descr: L011 device
 serial: 303030303030303030303031
openocd: "\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31"
  flash: 131072 (pagesize: 2048)
   sram: 16384
 chipid: 0x0448
  descr: F07x device

然后可以在 OpenOCD 脚本中使用该十六进制序列号字符串来识别不同的 ST-LINK/V2 程序员,如前所述 (hla_serial)。例如:

$ cat openocd.cfg 
source [find interface/stlink.cfg]
source [find target/stm32f0x.cfg]
hla_serial "\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x30\x31"

$ openocd -f openocd.cfg

希望这适用于所有情况...

对于想要避免 texane/stlink as suggested by rel's answer, I wrote a tiny C-Program to convert the serial: openocdser

所需开销的任何人