OpenOCD-Jlink配置方法

本文详细介绍了如何从源码编译并安装OpenOCD,包括克隆库、安装依赖、配置选项、编译和安装过程,以及如何配置JLink进行STM32F4x设备的调试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

OpenOCD Jlink配置

1. 编译安装OpenOCD

  1. 克隆OpenOCD库到本地
user@user:~$ git clone https://github.com/openocd-org/openocd.git
Cloning into 'openocd'...
remote: Enumerating objects: 72495, done.
remote: Counting objects: 100% (489/489), done.
remote: Compressing objects: 100% (212/212), done.
remote: Total 72495 (delta 303), reused 440 (delta 276), pack-reused 72006
Receiving objects: 100% (72495/72495), 31.47 MiB | 1.58 MiB/s, done.
Resolving deltas: 100% (59552/59552), done.
  1. 安装依赖
user@user:~$ sudo apt-get install -y build-essential pkg-config autoconf automake libtool libusb-dev libusb-1.0-0-dev libhidapi-dev libtool libsysfs-dev
  1. 自动配置
user@user:~/openocd$ sudo ./bootstrap
+ aclocal --warnings=all
+ libtoolize --automake --copy
+ autoconf --warnings=all
+ autoheader --warnings=all
+ automake --warnings=all --gnu --add-missing --copy
Setting up submodules
Cloning into '/home/user/openocd/src/jtag/drivers/libjaylink'...
Submodule path 'jimtcl': checked out 'a77ef1a6218fad4c928ddbdc03c1aedc41007e70'
Submodule path 'src/jtag/drivers/libjaylink': checked out '9aa7a5957c07bb6e862fc1a6d3153d109c7407e4'
Submodule path 'tools/git2cl': checked out '8373c9f74993e218a08819cbcdbab3f3564bbeba'
Generating build system...
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/config.guess'
libtoolize: copying file 'build-aux/config.sub'
libtoolize: copying file 'build-aux/install-sh'
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
configure.ac:43: installing 'build-aux/ar-lib'
configure.ac:37: installing 'build-aux/compile'
configure.ac:30: installing 'build-aux/missing'
libjaylink/Makefile.am: installing 'build-aux/depcomp'
Bootstrap complete. Quick build instructions:
./configure ....
  1. 自动配置
user@user:~/openocd$ sudo ./configure 
checking for makeinfo... makeinfo
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
...
#####################中间省略##########################
...
libjaylink configuration summary:
 - Package version ................ 0.2.0
 - Library version ................ 1:0:1
 - Installation prefix ............ /usr/local
 - Building on .................... x86_64-pc-linux-gnu
 - Building for ................... x86_64-pc-linux-gnu

Enabled transports:
 - USB ............................ yes
 - TCP ............................ yes

OpenOCD configuration summary
--------------------------------------------------
MPSSE mode of FTDI based devices        yes (auto)
ST-Link Programmer                      yes (auto)
TI ICDI JTAG Programmer                 yes (auto)
Keil ULINK JTAG Programmer              yes (auto)
Altera USB-Blaster II Compatible        yes (auto)
Bitbang mode of FT232R based devices    yes (auto)
Versaloon-Link JTAG Programmer          yes (auto)
TI XDS110 Debug Probe                   yes (auto)
CMSIS-DAP v2 Compliant Debugger         yes (auto)
OSBDM (JTAG only) Programmer            yes (auto)
eStick/opendous JTAG Programmer         yes (auto)
Olimex ARM-JTAG-EW Programmer           yes (auto)
Raisonance RLink JTAG Programmer        yes (auto)
USBProg JTAG Programmer                 yes (auto)
Andes JTAG Programmer                   yes (auto)
CMSIS-DAP Compliant Debugger            yes (auto)
Nu-Link Programmer                      yes (auto)
Cypress KitProg Programmer              yes (auto)
Altera USB-Blaster Compatible           no
ASIX Presto Adapter                     no
OpenJTAG Adapter                        no
Linux GPIO bitbang through libgpiod     no
SEGGER J-Link Programmer                yes (auto)
Bus Pirate                              yes (auto)
Use Capstone disassembly framework      no

  1. 编译
user@user:~/openocd$ sudo make
  1. 安装
user@user:~/openocd$ sudo make install
  1. 查看版本(安装成功)
user@user:~/openocd$ openocd --version
Open On-Chip Debugger 0.11.0+dev-00615-gbe0d68eb6 (2022-03-15-23:06)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html

2. 配置OpenOCD

  1. 修改jlink.cfg
#
# SEGGER J-Link
#
# http://www.segger.com/jlink.html
#

adapter driver jlink
# add swd config
transport select swd
# add speed config
adapter speed 20000 #khz
# The serial number can be used to select a specific device in case more than
# one is connected to the host.
#
# Example: Select J-Link with serial number 123456789
#
# adapter serial 123456789
  1. 应用配置
user@user:~/openocd$ sudo openocd -f /usr/local/share/openocd/scripts/interface/jlink.cfg -f /usr/local/share/openocd/scripts/target/stm32f4x.cfg
Open On-Chip Debugger 0.11.0+dev-00615-gbe0d68eb6 (2022-03-15-23:06)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
adapter speed: 50000 kHz

Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : J-Link ARM-OB STM32 compiled Aug 22 2012 19:52:04
Info : Hardware version: 7.00
Info : VTarget = 3.300 V
Info : clock speed 2000 kHz
Info : SWD DPIDR 0x00000000
### 配置和使用OpenOCD与J-Link驱动器 #### 安装J-Link驱动程序 为了使OpenOCD能够识别并正常工作于J-Link硬件之上,需先安装由SEGGER官方提供的J-Link驱动程序。访问官方网站下载适用于操作系统的最新版本驱动包,并按照提示完成整个安装流程[^1]。 #### 设置环境变量 确保已将J-Link软件工具链路径加入到系统的`PATH`环境中,以便命令行可以全局调用这些工具。对于Windows操作系统而言,这通常意味着向系统环境变量添加类似如下目录(具体取决于实际安装位置): ```plaintext C:\Program Files (x86)\ SEGGER\JLink\ ``` #### 编辑OpenOCD配置文件 创建或编辑用于启动OpenOCD服务的`.cfg`配置脚本,指定目标设备类型及接口参数。针对STM32系列MCU的一个简单例子可能看起来像这样: ```tcl source [find interface/jlink.cfg] set CHIPNAME stm32f407vg source [find target/stm32f4x.cfg] adapter_khz 1000 transport select swd reset_config srst_only ``` 上述配置指定了采用SWD模式通信、设置适配器速度为1MHz,并选择了仅通过SRST信号实现复位的方式[^2]。 #### 启动OpenOCD服务器端 打开终端窗口,导航至包含之前准备好的配置文件所在的位置,执行以下指令来开启OpenOCD监听进程: ```bash openocd -f your_custom_configuration_file.cfg ``` 此时如果一切顺利的话,应该可以看到有关成功连接到JTAG/SWD调试探针的日志输出信息。 #### 连接GDB客户端进行调试会话 最后一步是从任意支持GNU GDB协议的IDE或者直接运行gdb本身建立远程调试连接。假设正在处理的是ARM架构的目标,则可以在本地机器上输入下列命令之一尝试接入已经处于等待状态下的OpenOCD实例: ```bash arm-none-eabi-gdb.exe --eval-command="target extended-remote :3333" ``` 一旦建立了有效的链接关系之后就可以开始正常的断点设定、单步执行等功能了。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值