platformio / platformio-core

Your Gateway to Embedded Software Development Excellence :alien:
https://platformio.org
Apache License 2.0
7.81k stars 787 forks source link

Support viewing SWO data #4069

Open maxgerhardt opened 2 years ago

maxgerhardt commented 2 years ago

What kind of issue is this?

You can erase any parts of this template not applicable to your Issue.


Configuration

Operating system: Win 10 x64

PlatformIO Version (platformio --version): version 5.2.1b2

Description of problem

Per https://community.platformio.org/t/viewing-swo-output-within-pio/13853.

PlatformIO currently has no built-in facilities to view printf() output sent via the SWO (single-wire-output) pin present in many ARM-type microcontrollers.

SWO (using the "SWO" pin) is a different technique to SWD semihosting (uses SWDIO + SWDCLK pins), thus this issue is not a duplicate of #3516 .

Steps to Reproduce

  1. Create firmware that uses the SWO output (e.g., STM32Cube firmware using the ITM_SendChar() function to send data)
  2. Upload firmware
  3. View SWO output normally via the e.g. ST-Link Utility

grafik

  1. Search for the option to view SWO output within PlatformIO (e.g., via "Monitor" task)

Actual Results

The "Monitor" task cannot be configured to view SWO output. No other button for "show me SWO output" exists.

Expected Results

PlatformIO is capable of viewing SWO output out-of-the-box.

If problems with PlatformIO Build System:

N/A

Additional info

By using OpenOCD to read SWO output and forward it to a TCL server (it cannot output it in stdout by default) and using a SWO decoder script (https://github.com/robertlong13/SWO-Parser) that connects to OpenOCD's TCL server, one can view the SWO output.

The repo https://github.com/maxgerhardt/pio-swo-demo demonstratess that and implements a "SWO Viewer" task that acts like a serial monitior, just for SWO data.

t

cocodmdr commented 10 months ago

Hi,

I was trying out your example to print debug information via SWO https://github.com/maxgerhardt/pio-swo-demo

I am using a different board: "WeAct Studio BlackPill V2.0 (STM32F401CC)" I got ITM print to work while previously working with STM32CubeIDE.

I adapted the frequency of the script to match the one of the board (84MHz),

However I am facing problems while connecting with the "SWO Viewer " job in VSCode PlatformIO.

It seems that it refuses to connect to the board: ConnectionRefusedError: [Errno 111] Connection refused

I also have these warnings : Info : DEPRECATED 'tpiu config' command: Running: 'stm32f4x.tpiu configure -protocol uart -traceclk 84000000 -pin-freq 115200 -output - -formatter false'

Thank you for your help !

Full output :



Warning! Ignore unknown configuration option `swo_trace_clkin_freq` in section [env:blackpill_f401cc]
Processing blackpill_f401cc (platform: ststm32; board: blackpill_f401cc; framework: stm32cube)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/blackpill_f401cc.html
PLATFORM: ST STM32 (16.1.0) > WeAct Studio BlackPill V2.0 (STM32F401CC)
HARDWARE: STM32F401CCU6 84MHz, 64KB RAM, 256KB Flash
DEBUG: Current (stlink) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES:
 - framework-stm32cubef4 @ 1.26.2
 - tool-ldscripts-ststm32 @ 0.2.0
 - toolchain-gccarmnoneeabi @ 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 52 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
swo_viewer_task(["swo_viewer"], [])
Entrypoint
Starting OpenOCD with SWO Trace clock-in frequency 84000000, SWO trace frequency 115200. Invocation:
['/home/cocodmdr/.platformio/packages/tool-openocd/bin/openocd', '-s', '/home/cocodmdr/.platformio/packages/tool-openocd/scripts', '-f', 'interface/stlink.cfg', '-c', 'transport select hla_swd', '-f', 'target/stm32f4x.cfg', '-c', 'init; tpiu config internal - uart false 84000000 115200; itm ports on']
xPack Open On-Chip Debugger 0.12.0-01004-g9ea7f3d64-dirty (2023-01-30-15:03)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : clock speed 2000 kHz
Info : STLINK V2J29S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.151453
Traceback (most recent call last):
  File "/home/cocodmdr/Documents/PlatformIO/Projects/pio-swo-demo/swo_parser.py", line 198, in <module>
    swo_parser_main()
  File "/home/cocodmdr/Documents/PlatformIO/Projects/pio-swo-demo/swo_parser.py", line 145, in swo_parser_main
    tcl_socket.connect((HOST, PORT))
ConnectionRefusedError: [Errno 111] Connection refused
Info : [stm32f4x.cpu] Cortex-M4 r0p1 processor detected
Info : [stm32f4x.cpu] target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : DEPRECATED 'tpiu config' command: Using stm32f4x.tpiu
Info : DEPRECATED 'tpiu config' command: Running: 'stm32f4x.tpiu configure -protocol uart -traceclk 84000000 -pin-freq 115200 -output - -formatter false'
Info : DEPRECATED 'tpiu config' command: Running: 'stm32f4x.tpiu enable'
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections```
maxgerhardt commented 10 months ago

If you have issues with connection refused, one script is starting up too fast. See https://github.com/maxgerhardt/pio-swo-demo/issues/3#issuecomment-1685880644.