简体   繁体   English

使用 openocd 显示 Cortex-M4 SWO 日志

[英]show Cortex-M4 SWO log with openocd

I'm using ubuntu, openocd and stlink to develop stm32f407-discovery, I'm learning to use ITM module through SWO pin to get log from chip.我正在使用 ubuntu、openocd 和 stlink 开发 stm32f407-discovery,我正在学习通过 SWO 引脚使用 ITM 模块从芯片获取日志。 Finally, I found that openocd command最后发现openocd命令

tpiu config internal /tmp/swo.out uart off 168000000

It's perfect to get log from the temporary file, but is there anyway to show log on openocd console directly, like semihosting log.从临时文件中获取日志是完美的,但是无论如何都可以直接在 openocd 控制台上显示日志,例如半主机日志。 Thanks谢谢

Actually you where very close to achieve the desirable outcome .其实你在那里很接近达到理想的结果。 First thing first you don't have to specify an output stream ,the default is a named pipe that is exposed on openocd's console .What I mean is you could simply change:首先,您不必指定输出流,默认值是在 openocd 的控制台上公开的命名管道。我的意思是您可以简单地更改:

tpiu config internal /tmp/swo.out uart off 168000000

with:和:

tpiu config internal - uart off 168000000

Although the problem that occurs then is that you need a parser to read the swo raw bytes ,fortunately there is this quite unknown but very useful repository that do just that with a single python script: swo_parser虽然发生的问题是你需要一个解析器来读取 swo 原始字节,但幸运的是有一个非常不为人知但非常有用的存储库,它使用单个 python 脚本来完成: swo_parser

So to sum up my configurations when I was debugging an f1 from a jtag (because the uart was occupied for other purposes) was:所以总结一下我从 jtag 调试 f1 时的配置(因为 uart 被用于其他目的)是:

  1. Open two terminals打开两个终端
  2. At the first terminal run openocd -f debug.cfg在第一个终端运行openocd -f debug.cfg
  3. At the second terminal run python3 swo_parser.py在第二个终端运行python3 swo_parser.py

debug.cfg contains just : debug.cfg 只包含:

source [find interface/stlink-v2.cfg]
source [find target/stm32f1x.cfg]
init
tpiu config internal - uart off 72000000
itm ports on

also I forgot to mention you have to make one _write function like this ITM_SEND_CHAR definition我也忘了提到你必须做一个像这样ITM_SEND_CHAR 定义的_write 函数

I got it to work using Orbuculum as a helper program.我使用Orbuculum作为辅助程序让它工作。

To get the output visible in same terminal as GDB, and to easily start everything at the same time, I start GDB like this:为了在与 GDB 相同的终端中显示输出,并同时轻松启动所有内容,我像这样启动 GDB:

arm-none-eabi-gdb \
       -iex 'target extended | openocd -f interface/stlink.cfg -f target/stm32f3x.cfg -c "gdb_port pipe"' \
       -iex 'mon halt' \
       -iex 'mon tpiu config internal swo.log uart false 2000000' \
       -iex 'shell bash -m -c "orbuculum -f swo.log &"' \
       -iex 'shell bash -m -c "orbcat -c 0,%c &"' \
       firmware.elf

The -iex parameter tells gdb to immediately execute a command when starting. -iex参数告诉 gdb 在启动时立即执行命令。 Here is what the commands do:以下是命令的作用:

  1. target extended ... starts openocd and uses a pipe to communicate between it and gdb. target extended ...启动 openocd 并使用管道在它和 gdb 之间进行通信。
  2. mon halt tells OpenOCD to stop any executing program. mon halt告诉 OpenOCD 停止任何正在执行的程序。
  3. mon tpiu ... configures OpenOCD to receive the trace output and to write it to swo.log file. mon tpiu ...配置 OpenOCD 以接收跟踪输出并将其写入swo.log文件。
  4. shell bash -m "orbuculum ... starts the Orbuculum server and tells it to read from swo.log . The & makes it run on the background, while bash -m runs it in separate process group so that ctrl-c within GDB doesn't accidentally stop it. shell bash -m "orbuculum ...启动 Orbuculum 服务器并告诉它从swo.log读取。 &使它在后台运行,而bash -m在单独的进程组中运行它,以便 GDB 中的ctrl-c不会不要不小心阻止它。
  5. shell bash -m "orbcat ... starts Orbuculum tool to read any output from ITM port 0 and write that as characters to the terminal. shell bash -m "orbcat ...启动 Orbuculum 工具从 ITM 端口 0 读取任何输出并将其作为字符写入终端。

And here is what it looks like:这是它的样子:

GNU gdb (GNU Tools for Arm Embedded Processors 8-2018-q4-major) 8.2.50.20181213-git
....
Reading symbols from firmware.elf...
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: firmware.elf 
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800011c msp: 0x10001000
Boot
ADC ch 1 val -100
ADC ch 3 val 0
ADC ch 4 val 3
ADC ch 1 val 4091
.....

There are also other useful tools in the Orbuculum suite. Orbuculum 套件中还有其他有用的工具。 For example orbtop -e firmware.elf shows the places where execution time is being spent.例如orbtop -e firmware.elf显示执行时间花费的地方。

After searching for a few days, i've found nothing about openocd printing directly in a console.搜索了几天后,我没有发现直接在控制台中进行 openocd 打印的任何信息。

What you can do is redirect it to a UART (requiring more hardware to setup) and use another program(like st link utility) to see the output, but it's way easier to just do a "cat /tmp/swo.out" in your terminal.你可以做的是将它重定向到一个 UART(需要更多的硬件来设置)并使用另一个程序(如 st 链接实用程序)来查看输出,但在你的终端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM