Close
0%
0%

SWO with Mbed Studio

How to view SWO output in Mbed Studio (sort of)

Similar projects worth following
63 views
0 followers
More about SWO: https://hackaday.com/2022/05/25/swo-an-arm-printf-by-any-other-name/

The Mbed Studio used pyOCD as a debugger so you can set it up to handle SWO output and then use tools to display it inside the IDE. Not seamless but workable.

There are two methods. With one, you pass some options to PyOCD and you can use Telnet to look at all the SWO output directly. With the other you can use a decoder software to pick and format output.

You need Mbed Studio and Orbuculum (see links; Orbuculum is optional).

You do NOT run the Orbuculum program. It is made to grab the SWO data and we are going to do that with the built-in copy of PyOCD in Mbed Studio. What you need are the tools like orbcat that think they are talking to Orbuculum. You can also skip orbcat and use the semihosting port to read the SWO data easily, but with no special formatting or filtering.

  • 1
    Setup Debugger

    From Mbed Studio, select Target and click the little chip to set up a new debug probe.

    Under Debug Flags, you'll find a large number of items populated once you pick the USB device. Add the following (don't change anything that is there):

     -O enable_swv=1 -O swv_system_clock=96000000 -O swv_raw_port=3443 -O swv_clock=2000000

    Set everything else up as normal. You may have to adjust your system clock and/or baud rate. Here we have 96MHz and 2MHz.

    By default the decoded port is on 4444. 

    If you are not using Orbuculum, you can omit the -O swv_raw_port=3443 option.

  • 2
    Test

    When running the debugger, you should be able to connect  via telnet to localhost:3443. If not, something is wrong. This is the same port the Orbuculum tools use. If you run your program you will see the output but it is in the SWV format so it will be gibberish mixed in with your data. This step isn't necessary, but it is a quick way to tell if you have the command line right.

  • 3
    Set up for real

    Close the telnet program if you opened it. When you start the debugger, use the top menu bar to open a new terminal. Inside the new terminal enter:

    orbcat -c 0,"%c"

    This will decode channel 0 as a character in the display. You can add more -c if you want to mix in different channels or use different channels. For example:

    orbcat -c 4,"%c"

    The %c is a printf specifier so you could do more decoding that way.

    You can also connect to port 4444 to see the decoded SWO data directly from PyOCD. Then it is mixed up and unformatted, but you can do it that way with no extra tools. 

View all 3 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates