Funny you should ask this question. The other day I was looking into enabling the SWO output of the BlackMagic Probe code. In that quest, I stumbled onto the fact that the SWO output is very low overhead and works quite effciently. The best part, you can use it without any debug hardware. You just need a low cost ebay USB->Serial dongle to get the output.
An overview on this technique can be found by reading this artlcle:
http://blog.japaric.io/itm/
Disregard that the author is talking about the Rust language instead of C++. The meat of this technique, which could help you on a Mac OS/X, can be found if you scroll about half way down. Find the heading “Standalone SWO”. Basically, you need a host program to decode the ITM output and you need to add some code to stm32f103 source that enables DWT and uses ITM_print statemetns.
On a linux host, I used an ITM decoder from black magic probe project called swolisten.
https://github.com/blacksphere/blackmag … wolisten.c
swolisten is written to work in two modes. The first mode reads the usb endpoint that black magic probe uses. The second mode swolisten opens the usb serial device (/dev/ttyUSB0 … on linux) and decodes each message and presents the output on a named pipe, one for each channel. The second mode reading the usb serial device is what we want. There is a readme in the blackmagic code titled something like “Using SWO Debug” if you poke around.
To run this on linux, use the following commands in two windows:
$ swolisten -p /dev/ttyUSB0 -v -b swo/ -s 4000000
and in the second window just run:
$ cat swo/chan00
Now that you have the host side setup, the final part of the puzzle is the code you need to add to your stm32f103 source. Sadly, I don’t have a readily avaliable example for Roger’s core. However, I did write code you can use as an example that uses the CubeMX CMSIS header that you can find here:
https://gist.github.com/RickKimball/55e … d52bbceadd
Basically you configure the DWT module to enable ITM output. When you want to output the value of some variable you call a CMSIS function called ITM_print(). In that example code I provided, it only takes 17 cycles to output the value. Of course, if you add fancy print formatting, you will slow it down considerably. An approach that would work better for what you want to do might be to output the raw values on individual channels and let the host side do the print formatting.
Sorry if this write-up leaves a lot of questions, however there are many articles about printing SWO output.
The thing that surprised me about using SWO was that you could use a low cost USB dongle like an FTDI, CP2102 or PL2303hx, and run them at 4Mbit without issue. Before I looked into SWO, I thought I needed a commercial professional debug probe that supported SWO with corresponding host software. Turns out it is actually simpler if you just use a standalone UART connected to the TDO pin. It is certainly less expensive.
Enjoy!