我们可以在 openocd 0.9+ 中使用 hla_serial 选项ONLY。我建议从下载GNU ARM 日食 http://gnuarmeclipse.livius.net/blog/2015/03/20/gnu-arm-eclipse-openocd-0-9-0-20150320-dev-released/自己项目或编译。
要获取 hla_serial,阅读包含此选项的补丁后找到的最简单方法(http://openocd.zylin.com/#/c/2198/ http://openocd.zylin.com/#/c/2198/),更具体的功能“字符串描述符等于 http://openocd.zylin.com/#/c/2198/8/src/jtag/drivers/libusb0_common.c”,就是提供一个错误的序列号,这样它就会打印出正确的序列号。
下面的命令将创建文件log_with_ Correct_serial.txt。当前正在使用的交换机板配置文件。
openocd.exe -d3 -f board/stm32f4discovery.cfg -c "hla_serial wrong_serial" 2>log_with_correct_serial.txt
Opening log_with_ Correct_serial.txt您会在包含类似内容的行中找到正确的序列号
Debug: 229 23 libusb1_common.c:67 string_descriptor_equal(): Device serial number 'xxxxxxxxxxx' doesn't match requested serial 'wrong_serial'
因此创建一个派生配置(例如stm32f4discovery-mydevice1.cfg,假设使用 stm32f4discovery)在文件夹内board在 openocd 根目录下。使用 Notepad++ 之类的工具来复制序列号,因为它是十六进制数字。
# This is an STM32F4 discovery board with a single STM32F407VGT6 chip.
# http://www.st.com/internet/evalboard/product/252419.jsp
# hla_serial thanks to http://wunderkis.de/stlink-serialno/index.html
source [find board/stm32f4discovery.cfg]
hla_serial V?nIpSU)?
现在要打开您的设备,您可以使用以下命令开始使用 ST-Link 适配器进行调试。
openocd.exe -f board/stm32f4discovery-mydevice1.cfg
在每个 Eclipse 项目中,为每个项目提供了不同的板配置,您就可以开始了。