1. The problem explained
I'm trying to use OpenOCD for something uncommon. Instead of connecting to the chip, I'd like to merely detect the chip.
The procedure I have in mind would look like this:
Start OpenOCD with the probe config file (eg.
stlink.cfg
) given as-f
parameter. So OpenOCD knows what probe to use, but doesn't know what chip it will find.OpenOCD detects a chip and reports this somehow (eg. write something to stdout). If possible, this action should not be intrusive to the chip (like resetting it).
OpenOCD shuts down.
Here are some more notes about the procedure:
Note 1: It would be nice if OpenOCD doesn't reach the server state where I need to setup a Telnet or GDB client to interact with it. I'd be happy to get the chip detection reported in a more convenient way, like getting the chip info on the stdout channel.
Note 2: The detection should be non-intrusive to the chip. However, if OpenOCD doesn't find anything, I'd like to have a backup method where OpenOCD tries to find a chip more aggressively (like holding down the nRST
pin). I can invoke this other approach myself if needed (so there's no need for OpenOCD to do that automatically).
Note 3: At first, I'll just apply this "chip detection" only on STM32 chips with an STLinkV2 or STLinkV3 probe, later on other probes and chips as well.
Note 4: Some boards only have an SWD connection (no JTAG).
Note 5: I'm working on a Windows 10 computer, and got a very recent OpenOCD build (version 0.10.0_dev00921, built on 06 July 2019) downloaded from https://www.playembedded.org/blog/download/
2. What I've tried so far
Mr. Tommy Murphy referred me to Section 10.7 in the OpenOCD reference manual (see http://openocd.org/doc/pdf/openocd.pdf). I've read the section and observed the following example:
# openocd.cfg file
# -----------------
source [find interface/olimex-arm-usb-tiny-h.cfg]
reset_config trst_and_srst
jtag_rclk 8
Because my chip connects through the STLink probe and uses SWD transport protocol (instead of JTAG), I made a few modifications to the example:
# openocd.cfg file
# -----------------
source [find interface/stlink.cfg]
transport select hla_swd
reset_config srst_only
adapter_khz 480
I connect a NUCLEO_F303K8 board to my PC for this test. Then I issue the following command in my console:
> openocd -s "C:\...\scripts" -f "C:\...\openocd.cfg"
OpenOCD outputs the following and then terminates:
Open On-Chip Debugger 0.10.0+dev-00921-gef8c69ff9 (2019-07-06-01:00)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 480 kHz
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 480 kHz
Error: BUG: current_target out of bounds
So I end up with a few questions concerning autoprobing.
3. My questions
Question 1:
Is "Autoprobing" (as described in Section 10.7) really what I need here? If the answer is No, please ignore the next questions.
Question 2:
I've tried to imitate the example given in Section 10.7, with some minor modifications to make the example suitable for my Nucleo board. Unfortunately the Autoprobing fails. Is this because OpenOCD doesn't support autoprobing with the SWD protocol? Or am I simply making a mistake in my .cfg
file?
Question 3:
I noticed that the Autoprobing example from Section 10.7 configures the reset behaviour of OpenOCD. Does this mean that Autoprobing will always be "intrusive" in the sense that it resets the chip?
Question 4:
The Autoprobing example from Section 10.7 seems to bring OpenOCD into the server state anyhow. Is it possible to avoid that? I want to keep this "chip detection" thing simple, without the need for a Telnet or GDB client.
EDITS
Thank you @nattgris for your remarkable answer. I've got a few more practical questions though.
1. With ST-Link
Suppose we're using the ST-Link, despite its sub-optimal cooperation with OpenOCD. You said:
.. if all you need is to know is whether a chip is there at all, in some configurations the ST-Link can probably be persuaded to give you that info.
How do I practically persuade the ST-Link to do that? In other words, what should I put in my openocd.cfg
file to achieve this?
2. With SWD-probe (but not ST-Link)
Suppose we're using a true SWD-probe. You said:
Autoprobing, as described in Section 10.7, is only relevant for JTAG [...]. Simply connecting via SWD prints the corresponding information (the
DPIDR
register instead of the TAPIDCODE
). So either way, you can get similar info about the chip over both protocols. [...]
For all Cortex-chips, you will basically get "ARM" instead of the actual manufacturer of the chip (e.g. "ST"). Though ST (and perhaps other manufacturers) chips have a separate boundary scan TAP (i.e. JTAG only) that provides an actual STIDCODE
that can be used for chip identification.
From this, I conclude that:
Autoprobing as described in Section 10.7 is only applicable on JTAG, not on SWD.
As Autoprobing is not available for SWD, the alternative approach is to simply connect to the chip, after which OpenOCD automatically prints the
DPIDR
register. ThisDPIDR
register is the SWD-equivalent of the JTAG TAPIDCODE
, so to speak, and can identify the chip to some extent.
But how does one simply connect to the chip, if one doesn't know what chip is attached to the PC in the first place? If I'm not mistaken, OpenOCD always needs the specific config file, likestm32f7x.cfg
,stm32f4x.cfg
,stm32l0.cfg
, ... to connect to the chip.Apparently, the JTAG
IDCODE
and the SWD-equivalentDPIDR
register provide the chip designer, which would always be "ARM" for the ARM-Cortex chips. This is not enough for complete chip identification. However, you say that ARM-chips have separate boundary scan TAPs providing furtherIDCODE
registers for more complete identification. Unfortunately, these are JTAG-only. This means that SWD is on a dead-end here in terms of chip identification?Autoprobing with JTAG (and therefore reading the
IDCODE
reg) can be completely non-intrusive. Therefore, one can make the system reset signal unavailable:reset_config none
You say that reading theDPIDR
over SWD (which I consider to be the SWD-equivalent of JTAG autoprobing) is also non-intrusive. Could I also enforce that "non-intrusiveness" by making the reset signal unavailable?
3. With JTAG-probe (but not ST-Link)
The JTAG protocol seems to provide the best support for chip identification (using Autoprobing). My conclusions:
The Autoprobing described in Section 10.7 would print the TAP
IDCODE
from the chip. For ARM-chips that would simply print "ARM", not the actual manufacturer (like "ST") and the chip name (like "STM32F767ZI").How do I practically make sure that the procedure also prints these further info's, more in particular the actual chip name? In other words, what should I put in my
openocd.cfg
file (and possibly the openocd startup command) to achieve this?
Thank you very much :-)