简体   繁体   中英

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. Finally, I found that openocd command

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

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

So to sum up my configurations when I was debugging an f1 from a jtag (because the uart was occupied for other purposes) was:

  1. Open two terminals
  2. At the first terminal run openocd -f debug.cfg
  3. At the second terminal run python3 swo_parser.py

debug.cfg contains just :

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

I got it to work using Orbuculum as a helper program.

To get the output visible in same terminal as GDB, and to easily start everything at the same time, I start GDB like this:

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. Here is what the commands do:

  1. target extended ... starts openocd and uses a pipe to communicate between it and gdb.
  2. mon halt tells OpenOCD to stop any executing program.
  3. mon tpiu ... configures OpenOCD to receive the trace output and to write it to swo.log file.
  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.
  5. shell bash -m "orbcat ... starts Orbuculum tool to read any output from ITM port 0 and write that as characters to the terminal.

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. For example orbtop -e firmware.elf shows the places where execution time is being spent.

After searching for a few days, i've found nothing about openocd printing directly in a console.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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