[应用相关] 使用 openocd 调试 STM32F103

[复制链接]
2046|35
 楼主| 工程师犹饿死 发表于 2021-8-4 16:27 | 显示全部楼层
cargo readobj --bin app -- -file-headers
 楼主| 工程师犹饿死 发表于 2021-8-4 16:28 | 显示全部楼层
提示错误:
  1. Finished dev [unoptimized + debuginfo] target(s) in 0.02s
  2. Failed to execute tool: readobj
 楼主| 工程师犹饿死 发表于 2021-8-4 16:28 | 显示全部楼层
可以直接使用 arm-none-eabi-xxx 命令代替吧:
 楼主| 工程师犹饿死 发表于 2021-8-4 16:29 | 显示全部楼层
  1. arm-none-eabi-readelf -h target/thumbv7m-none-eabi/debug/app
 楼主| 工程师犹饿死 发表于 2021-8-4 16:33 | 显示全部楼层
我们可以看看代码的位置和大小(主要是确认是否和 memory.x 一致)
 楼主| 工程师犹饿死 发表于 2021-8-4 16:35 | 显示全部楼层
  1. arm-none-eabi-size -A -x target/thumbv7m-none-eabi/debug/app
 楼主| 工程师犹饿死 发表于 2021-8-4 16:36 | 显示全部楼层
输出:
  1. target/thumbv7m-none-eabi/debug/app  :
  2. section              size         addr
  3. .vector_table       0x400    0x8000000
  4. .text               0x558    0x8000400
  5. .rodata             0x138    0x8000958
  6. .data                 0x0   0x20000000
  7. .bss                  0x0   0x20000000
  8. .uninit               0x0   0x20000000
  9. .debug_abbrev      0x1432          0x0
  10. .debug_info       0x21e99          0x0
  11. .debug_aranges     0x1ca0          0x0
  12. .debug_ranges     0x17f30          0x0
  13. .debug_str        0x2b41f          0x0
  14. .debug_pubnames    0x9800          0x0
  15. .debug_pubtypes     0xad8          0x0
  16. .ARM.attributes      0x32          0x0
  17. .debug_frame       0x5b5c          0x0
  18. .debug_line       0x2643b          0x0
  19. .debug_loc          0x17e          0x0
  20. .comment             0x6d          0x0
  21. Total             0x9f1d6
 楼主| 工程师犹饿死 发表于 2021-8-4 16:36 | 显示全部楼层
6. 调试
修改 openocd.cfg
 楼主| 工程师犹饿死 发表于 2021-8-4 16:37 | 显示全部楼层
原来内容如下:
 楼主| 工程师犹饿死 发表于 2021-8-4 16:37 | 显示全部楼层
  1. # Sample OpenOCD configuration for the STM32F3DISCOVERY development board

  2. # Depending on the hardware revision you got you'll have to pick ONE of these
  3. # interfaces. At any time only one interface should be commented out.

  4. # Revision C (newer revision)
  5. source [find interface/stlink-v2-1.cfg]

  6. # Revision A and B (older revisions)
  7. # source [find interface/stlink-v2.cfg]

  8. source [find target/stm32f3x.cfg]
 楼主| 工程师犹饿死 发表于 2021-8-4 17:04 | 显示全部楼层
因为我用的是 jlink,所以改成如下内容:
 楼主| 工程师犹饿死 发表于 2021-8-4 17:05 | 显示全部楼层
  1. # Sample OpenOCD configuration for the STM32F3DISCOVERY development board

  2. # Depending on the hardware revision you got you'll have to pick ONE of these
  3. # interfaces. At any time only one interface should be commented out.

  4. # Revision C (newer revision)
  5. source [find interface/jlink.cfg]

  6. source [find target/stm32f3x.cfg]
 楼主| 工程师犹饿死 发表于 2021-8-4 17:05 | 显示全部楼层
启动 openocd

正常输出如下,提示监听 3333 端口:
  1. Open On-Chip Debugger 0.11.0
  2. Licensed under GNU GPL v2
  3. For bug reports, read
  4.         http://openocd.org/doc/doxygen/bugs.html
  5. Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.
  6. Info : Listening on port 6666 for tcl connections
  7. Info : Listening on port 4444 for telnet connections
  8. Info : J-Link V9 compiled Dec 30 2018 15:35:20
  9. Info : Hardware version: 9.20
  10. Info : VTarget = 3.229 V
  11. Info : clock speed 1000 kHz
  12. Info : JTAG tap: stm32f3x.cpu tap/device found: 0x3ba00477 (mfg: 0x23b (ARM Ltd), part: 0xba00, ver: 0x3)
  13. Warn : JTAG tap: stm32f3x.cpu       UNEXPECTED: 0x3ba00477 (mfg: 0x23b (ARM Ltd), part: 0xba00, ver: 0x3)
  14. Error: JTAG tap: stm32f3x.cpu  expected 1 of 1: 0x4ba00477 (mfg: 0x23b (ARM Ltd), part: 0xba00, ver: 0x4)
  15. Info : JTAG tap: stm32f3x.bs tap/device found: 0x06414041 (mfg: 0x020 (STMicroelectronics), part: 0x6414, ver: 0x0)
  16. Error: Trying to use configured scan chain anyway...
  17. Warn : Bypassing JTAG setup events due to errors
  18. Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
  19. Info : starting gdb server for stm32f3x.cpu on 3333
  20. Info : Listening on port 3333 for gdb connections
 楼主| 工程师犹饿死 发表于 2021-8-4 17:08 | 显示全部楼层
启动 gdb。项目目录下的 openocd.gdb 中有些初始化命令,可以直接使用,免得手工输入。
 楼主| 工程师犹饿死 发表于 2021-8-4 17:09 | 显示全部楼层
arm-none-eabi-gdb target/thumbv7m-none-eabi/debug/app -x openocd.gdb
 楼主| 工程师犹饿死 发表于 2021-8-4 17:10 | 显示全部楼层
后续的调试方法就和 gdb 一样了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 在线客服 返回列表 返回顶部