How to use OpenOCD to talk to two STM32 boards at once?
Asked Answered
M

3

5

Let's say I've got two STM32's, and I'm using this programmer here.

I want to connect to both of them and debug/reflash/itterate independently.

So, the setup I have is as follows:

HW

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

SW

They way I normally do this with one board is pretty simple.

openocd -f config.cfg

And here is the config file I'm calling:

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

Then, in a different terminal, I call arm-gdb like so:

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

and in the ~/.gdbinit, I've got this single line:

target remote localhost:3333

What's not Working

This is pretty obvious...I'm using port 3333 for the first OpenOCD, but the second instance is trying to use that same port and fails with

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

What I've Tried

I've looked over the documentation here, but I'm failing to see how to call these options in my config.cfg file.

I've also tried adding these commands about tcl_port and gdb_port to the actual command line arguments, like openocd -f config.cfg -c tcl_port 4444, but this doesn't work either...The socket is still in use.

My Real Question

What's the right way to do this? And are there any gotchas with dealing with arm-none-eabi-gdb after getting openocd configured so that it connects to the right OpenOCD instance?

Manchineel answered 11/1, 2018 at 15:54 Comment(6)
the config file has the port number as you pointed out I have no issue with two or several openocd sessions from one computer to many devices. I am normally using non-stlink in this case, what you want to look for us there may be a serial number or other item you can use for each config file that ties to that specific debugger that way the config file finds the one single device.Bearwood
I use the older ft2232 legacy and there is ft2232_serial, ft2232_desc, etc these come from the ftdi eeprom information for that device. other things like stlink hopefully has something similar.Bearwood
in the cfg file itselfBearwood
# 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"Bearwood
yeah that worked great dont need the string stuff, just put the number you get from lsusb -vvv hla_serial 123456789012334Bearwood
you will want to take the first level generic cfg file stlink-v2.cfg in your case and customize it for each config file and source that and/or just include it in your cfg rather than sourcing it...yeah, like four lines so comment out the source whatever take the lines from that stlinkv2.cfg file pull it into your config then add an hla_serial line.Bearwood
B
4

stlinkv2.cfg from 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"

your config is sourcing this, comment out the source to that file line and replace with this

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

With whatever that specific stlinks serial number is (hopefully they vary)

repeat with a new config for each, then change the tcp/gdb port numbers for each, I never use gdb so I

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

I made up that iSerial number not my real one, probably doesnt matter if everyone knows the real one for this board...

I didnt try with two boards, if I add the hla_serial line and use the iSerial number then it does its thing. If I modify the serial number to not match it changes how openocd works it doesnt find the stlink. I would have to dig up more boards to fully test this, but you have these boards handy already so will let you see if this works for you.

Bearwood answered 11/1, 2018 at 20:51 Comment(0)
S
3

There's also a very handy utility in texane/stlink called st-info that helps with finding out the serial number of an ST-LINK programmer, for example like this:

$ 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

That hexadecimal serial number string can then be used in an OpenOCD script to identify different ST-LINK/V2 programmers, like already described (hla_serial). For example:

$ 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

Hope this works in all cases...

Schmidt answered 9/3, 2018 at 19:6 Comment(0)
H
0

For anyone who wants to avoid the overhead required by texane/stlink as suggested by rel's answer, I wrote a tiny C-Program to convert the serial: openocdser

Hannibal answered 20/8, 2019 at 9:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.