openocd使用介绍

一款调试工具

1.环境

默认已经搭建好了开发环境,使用brew安装好了openocd
各种介绍网上有很多这里就不多说
下面是我的openocd的安装路径/usr/local/Homebrew/share/openocd 一会要用到

2.使用

这部分仅介绍使用,具体更深层次的介绍,可以看以后的介绍

a.连接设备

连接stm32开发板之后使用命令连接openocd -f /usr/local/Homebrew/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/local/Homebrew/share/openocd/scripts/target/stm32g0x.cfg
这里第一个参数.cfg是指定连接的工具stlink等等,后面的stm32g0x.cfg是选择的芯片型号;选择对应的型号就可以
运行成功之后的提示信息,注意提示的端口

 ✘ yjhm@yjhmdeMacBook-Pro  /usr/local/Homebrew/share/openocd/scripts/interface   stable  openocd -f /usr/local/Homebrew/share/openocd/scripts/interface/stlink-v2-1.cfg -f /usr/local/Homebrew/share/openocd/scripts/target/stm32g0x.cfg
Open On-Chip Debugger 0.11.0
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2-1.cfg is deprecated, please switch to interface/stlink.cfg
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 2000 kHz
Info : STLINK V2J37M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.240865
Info : stm32g0x.cpu: hardware has 4 breakpoints, 2 watchpoints
Info : starting gdb server for stm32g0x.cpu on 3333
Info : Listening on port 3333 for gdb connections

b.使用telnet连接openocd

在openocd连接成功后会发现这条信息,就可以使用telnet通过4444端口,连接openocd了

Info : Listening on port 4444 for telnet connections

执行telnet指定端口
telnet localhost 4444
连接上之后是这样的,右边是telnet
image.png

c.常用命令

  1. halt
    停止
  2. resume
    继续,在halt之后才可以继续执行
  3. reset
    复位
  4. init
    Initializes configured targets and servers. Changes command mode
    from CONFIG to EXEC. Unless 'noinit' is called, this command is called automatically at the end of startup. (command valid any time)
    初始化配置的目标和服务器。 更改命令模式从 CONFIG 到 EXEC。 除非调用“noinit”,否则此命令为在启动结束时自动调用。 (命令随时有效)
  5. ms
    Returns ever increasing milliseconds. Used to calculate differences in time. (command valid any time)

d.下载

使用这个命令下载
flash write_image erase target.bin 0x08000000
如果使用.bin文件刷,一定要指定flash的地址这里是0x0800 0000,具体可查手册

END