PlatformIO Community

Viewing SWO output within PIO?

After hearing about SWO I’ve modified my ST Link and made the necessary code changes for it to transmit printf’s via SWO, when testing it with the ST Link Utility I successfully am presented the messages I log, however I cannot figure out how to view these from within vscode / PIO itself. Judging by how sparse information about this is its probably straight forward and I just dont see it. Help would be much appreciated, thanks in advance :slight_smile:

Partially discussed in Using SWO trace output from Atmel-ICE and STM32, libopencm3 and SWV/SWO but I’ve not yet seen information about it with PIO. The serial monitor is designed to connect to serial devices (/dev/ttyX / COMX devices). OpenOCD seems to be able to write it into a logfile (ref)… Do you know of a cross-platform tool for viewing SWO output?

I have seen those posts however those seem to be doing much more than I seemed to need to make it work. To have it work all I needed to do is switch my Debug mode to Trace Asynchronous Sw and add the couple lines of code and thats it. My ST Link has not introduced a new com port to the system nor is there anything on the mentioned port 2332 that you can find here and there.

As far as a cross platform tool goes, i dont know one no. I’m on windows so I’ve used the ST Link Utility and that works for me, unfortunately I obviously need to disconnect the debugger in vscode before i can connect with that to view the output, hence its not really a viable solution.

I’m assuming that the STM32CubeIDE might be able to view the output but I dont really know as I dont use that.

Actually, as little update, seems like OpenOCD, which Platformio uses anyways, does support SWO tracing. PIO just doesnt make use of it.

We have a feature request for this and plan to implement soon

1 Like

As a workaround I used to configure openocd (that ships with pio) like this (platformio.ini):

debug_server = $PLATFORMIO_CORE_DIR/packages/tool-openocd/bin/openocd
  -f $PLATFORMIO_CORE_DIR/packages/tool-openocd/scripts/board/st_nucleo_l4.cfg
  -f $PLATFORMIO_CORE_DIR/packages/tool-openocd/scripts/interface/stlink-v2-1.cfg
  -c "tpiu config internal - uart off 80000000"
  -c "itm ports on"
  -c "tcl_port 6666"

What is does, it turns all itm ports on and reopen tcl server that is disabled by default. You have of course to change the interface and board cfg to the one of your board. Also change 80000000 to the clock of your microcontroller.

Use this python script to listen on tcl server (port 6666):

You can open this script inside of vscode, so it is as near as having it “builtin” to vscode.

With this setup you can debug your program with pio debugger and simultaniously listen to itm packages. Of course you can overwrite _io_putchar to use printf:

extern "C"
int __io_putchar(int ch){
	//HAL_UART_Transmit(&huart2,(uint8_t *)&ch, 1, 10);
	return ch;
1 Like

Good to know that its already a planned feature, thanks a lot! I will definitely check out your workaround. For now I’ve been using the ST-Link utility but being unable to use SWO and SWD at the same time is kind of annoying some times.