簡體   English   中英

使用 openocd 顯示 Cortex-M4 SWO 日志

[英]show Cortex-M4 SWO log with openocd

我正在使用 ubuntu、openocd 和 stlink 開發 stm32f407-discovery,我正在學習通過 SWO 引腳使用 ITM 模塊從芯片獲取日志。 最后發現openocd命令

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

從臨時文件中獲取日志是完美的,但是無論如何都可以直接在 openocd 控制台上顯示日志,例如半主機日志。 謝謝

其實你在那里很接近達到理想的結果。 首先,您不必指定輸出流,默認值是在 openocd 的控制台上公開的命名管道。我的意思是您可以簡單地更改:

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

和:

tpiu config internal - uart off 168000000

雖然發生的問題是你需要一個解析器來讀取 swo 原始字節,但幸運的是有一個非常不為人知但非常有用的存儲庫,它使用單個 python 腳本來完成: swo_parser

所以總結一下我從 jtag 調試 f1 時的配置(因為 uart 被用於其他目的)是:

  1. 打開兩個終端
  2. 在第一個終端運行openocd -f debug.cfg
  3. 在第二個終端運行python3 swo_parser.py

debug.cfg 只包含:

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

我也忘了提到你必須做一個像這樣ITM_SEND_CHAR 定義的_write 函數

我使用Orbuculum作為輔助程序讓它工作。

為了在與 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

-iex參數告訴 gdb 在啟動時立即執行命令。 以下是命令的作用:

  1. target extended ...啟動 openocd 並使用管道在它和 gdb 之間進行通信。
  2. mon halt告訴 OpenOCD 停止任何正在執行的程序。
  3. mon tpiu ...配置 OpenOCD 以接收跟蹤輸出並將其寫入swo.log文件。
  4. shell bash -m "orbuculum ...啟動 Orbuculum 服務器並告訴它從swo.log讀取。 &使它在后台運行,而bash -m在單獨的進程組中運行它,以便 GDB 中的ctrl-c不會不要不小心阻止它。
  5. shell bash -m "orbcat ...啟動 Orbuculum 工具從 ITM 端口 0 讀取任何輸出並將其作為字符寫入終端。

這是它的樣子:

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
.....

Orbuculum 套件中還有其他有用的工具。 例如orbtop -e firmware.elf顯示執行時間花費的地方。

搜索了幾天后,我沒有發現直接在控制台中進行 openocd 打印的任何信息。

你可以做的是將它重定向到一個 UART(需要更多的硬件來設置)並使用另一個程序(如 st 鏈接實用程序)來查看輸出,但在你的終端。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM