SWO (Single Wire Output) in ARM cores is probably one of the most under-used features. Which is surprising, because SWO can be very useful. In a nut shell: SWO is a single wire output pin/signal channel which can provide lots of different data, like PC sampling for coverage information, interrupt tracing data or ‘uart-like’ text packets.
Despite its usefulness, using SWO can be challenging: it requires a physical pin, support in the debugger, plus despite it is a standard ARM feature, using it might be different for each MCU because of clocking. Tool vendors try to make things easier with ‘automatic’ setup of all the SWO hardware registers. That’s OK if that works, but unfortunately this is not always the case. In addition to that it conflicts with SWO configuration and settings done in the application. One might argue that the application should not touch SWO: but handling SWO in the application is my preferred way as that way I know what is going on. And I don’t have to rely on some ‘magic code’ from the tool vendors. Handling SWO in the application and to rely on the tool vendor ‘black box’ configuration allows me to use SWO without any external tools involved: so I can use the Saleae or Sigrok tools to capture the data and process it, without the interference of other tools.
Standalone SWO Viewer
After some debates and discussions, I’m very happy to report that SEGGER has added a ‘standalone’ SWO functionality to their SWO viewer V7.22 and later. From the release notes:
[SWOViewer]: Added command line option “-swoattach <OnOff>” that disables all J-Link side initialization of SWO and relies on the target application to perform SWO init.SEGGER V6.22 Release Note
💡 Note that I have to use the V6.22b, as at least in the actual V7.50b (both 32bit and 64bit) the feature seems not to work any more.
With this, the SEGGER SWOViewer can be used in combination with application level SWO setup and configuration. How this configuration works: check SWO with ARM Cortex-M33 which describes the McuSWO module which gives you access and configuration of the SWO feature across ARM cores.
Here is how to use it, using the example presented in SWO with ARM Cortex-M33.
Start the SWO viewer with the following command line (see https://wiki.segger.com/J-Link_SWO_Viewer for the list of options):
JLinkSWOViewerCL -swoattach on -swofreq 64000 -device LPC55S16 -itmport 0x1
This starts the JLinkSWOViewer in standalone mode:
The application can now use SWO. I’m using for example the McuSWO:
The application has configured SWO with a baud of 64k baud:
Using the console I can send data over the SWO pin:
It is fine if tools configure SWO. I wish that the settings and changed applied by the tools would be more transparent. For the case where the application needs to set up SWO, SEGGER has now added an ‘attach’ option which does not tamper with the application SWO configuration. With this a ‘standalone’ SWO usage can be realized.
Happy wiring 🙂