-
-
Notifications
You must be signed in to change notification settings - Fork 777
Serial Wire Output
Serial Wire Output (SWO) allows the target to write tracing and logging to the host without using usb or serial port. All data goes over a single pin, the JTAG TDO pin.
To set up SWO, you need to
- connect target and bmp
- configure the target processor
- configure bmp
- set up the viewer
SWO needs a connection between target SWO out and BMP SWO in (PA10 on stm32f103). As the SWO pin is the JTAG TDO pin, you cannot run SWO when using JTAG. SWO is compatible with SWD, not with JTAG.
A setup with blue pills might look like this:
Registers must be set up to configure the SWO pin for output. Different processors have different SWO setup. You can setup SWO in viewer, debugger, or target.
- bmtrace configures target processor in the viewer, button Configure target. Supports stm32 and lpc.
- orbuculum has scripts to configure the target in gdb, and stm32 c source to include in your build.
- SerialWireOutput arduino library, does stm32 set up in code.
As the SWO protocol is unidirectional, if set up is done in code, the logging can be left on in production code (but anyone who connects a wire to the SWO pin can read your logging).
BMP receives SWO from the target and sends decoded SWO to a usb serial port, or undecoded SWO to a viewer. Target and probe:
- must speak the same protocol, async or Manchester
- at the same speed
There are two SWO protocols: Manchester and asynchronous (aka NRZ). You can see what protocol your BMP speaks with monitor help
. The protocol is listed next to the traceswo
command.
Manchester coding auto-synchronizes. For asynchronous protocol, you have to configure the same baud rate in target and bmp. The default baud rate for async is 2250000.
Black Magic Probe can do SWO decoding in the probe itself, or pass the undecodes SWO stream to an external viewer.
You can switch on traveswo decoding in BMP with
monitor traceswo decode
traceswo decode
defaults to 2250000 baud (if using async) and decoding all channels. If using async, you can specify a baud rate. Optionally you can specify which stimulus channels to decode. Example:
monitor traceswo 450000 decode 0 2
sets speed to 4500000 baud, and decodes only channel 0 and 2.
The decoded SWO stream is written to the usb uart. Viewing SWO is simply connecting to the usb uart.
On linux, set up udev-rules and type
cat /dev/ttyBmpTarg
If you have not set up udev-rules, connect to the second of the two serial ports, e.g cat /dev/ttyACM1
.
If the SWO stream is not shown, check baud rate.
Black Magic Probe shows up in the device manager as two COM ports. On Windows , connect PuTTY to the second of the two COM ports, labeled "Black Magic UART Port".
SWO decoding in the probe does not need any special utilities and works on every os. For setups that use only a single channel this may be all you need.
For complex setups, especially with multiple channels, an external viewer may be more suitable.
You can switch on traceswo for external viewers with
monitor traceswo
The SWO stream is written to the usb trace port. (The usb trace port does not show up in /dev). If using async protocol, you can specify a baud rate: monitor traceswo 1125000
. The default for async is 2250000.
Viewers:
- bmtrace (graphical, windows, ubuntu). Configures bmp and target for you.
- orbuculum (linux, command line) Advanced. Has gdb init scripts and target c source in the Support/ directory.
- swo_listen (linux, command line)
- bmp_traceswo and bmp_traceswo (linux, command line) detailed write-up