STM32, libopencm3 and SWV/SWO

I am trying to use SWO as a debug output using libopencm3 but I 'm kind of lost. Has anyone any example code to share?

I am using a STM32F103C8T6 board (BluePill) and a STLink-V3.
I can successfully program the microcontroller and use STLink as a debug device (set breakpoints, inspect values etc).

I would like to utilize the TRACESWO pin PB3 to redirect the printf statements and also, if possible, monitor variable values in real time using SWV tarce.

A semihosting (e.g. sending printf() values via the SWD connection) example can be found right here with accompanying details here. For the modification of linker flags, see docs.

I’m not so familiar with general SWV tracing but here are infos and code regarding setting up the instrumentation macro cell, and also STM32 has info on it. lastly libopencm3 again has an example for it.

1 Like