Creating custom board for STM32F429ZGT6

Did not help, still linkage error…

Taking a look in SWO demo

So I’m trying to use SWO.

I’ve modified to platformio.ini:

[common_env_data]
build_flags =
    -D VERSION=1.2.3
    -D DEBUG=1
    -Wall
    -mcpu=cortex-m4
    -ffunction-sections
    -fdata-sections
    ; --specs=nosys.specs
    -fstack-usage -MMD -MP
    -std=c++17
    -g3
    -D DEBUG
    -D USE_HAL_DRIVER
    -D STM32F429xx
    -mfloat-abi=hard
    -mfpu=fpv4-sp-d16
    -mthumb



[env:erica_black_dsp]
platform = ststm32
board = erica_black_dsp
framework = stm32cube


lib_extra_dirs = ../../../zenlib

; Build options
build_flags =
    ${common_env_data.build_flags}



extra_scripts = pre:add_swo_viewer.py
    update_link_flags.py

swo_trace_clkin_freq = 180000000

debug_server = $PLATFORMIO_CORE_DIR/packages/tool-openocd/bin/openocd
  -f $PLATFORMIO_CORE_DIR/packages/tool-openocd/scripts/interface/stlink.cfg
  -f $PLATFORMIO_CORE_DIR/packages/tool-openocd/scripts/target/stm32f4x.cfg
  -c "tpiu config internal - uart off 180000000"
  -c "itm ports on"
  -c "tcl_port 6666"

Copied from demo repo

add_swo_viewer.py
swo_parser.py

On build time I’m getting warning:

Warning! Ignore unknown configuration option swo_trace_clkin_freq in section [env:erica_black_dsp]

Then when I try to connect after main() breakpoint with

python3 swo_parser.py --dont-run

I’m getting no output.

I tried to do General → Upload and then Custom-> SWO viewer:

*** [swo_viewer] NameError : name 'link' is not defined
Traceback (most recent call last):
  File "/Users/t/.platformio/packages/tool-scons/scons-local-4.2.0/SCons/Action.py", line 1279, in execute
    result = self.execfunction(target=target, source=rsources, env=env)
  File "/Users/t/GitHub/synths/zendelay/targets/BDSP/add_swo_viewer.py", line 28, in swo_viewer_task
    "-f", "interface/%s.cfg" % link,
NameError: name 'link' is not defined

Can be ignored, the value is custom-used in the script.

Funny that the code worked for me, but there’s definitely an error there. Copy the latest version again from pio-swo-demo/add_swo_viewer.py at main · maxgerhardt/pio-swo-demo · GitHub.

I’d also suggest opening a CLI and doing a pio upgrade --dev so that you’re on the very latest core version.

I upgraded pio, copied that file

Monitor error dissapeared, but Im still not getting printf in to console.

If I try to set a breakpoint on _write overriding method it never gets to that point.

Do you get SWO output through the ST-Link utility as shown in Support viewing SWO data · Issue #4069 · platformio/platformio-core · GitHub? With what system frequency?

To blame my hands or ST Semi but I can’t make ST-Link Util tool to run on Mac, even not in VM.

Using instead

st-util --clock=180

It does not print anything.

I tried to launch stm32IDE project with print loop with SWV as per following manual:
https://embeddedarea.com/stm32-debugging-with-printf-by-using-swv-or-openocd/

And it did work out. Running same

st-util --clock=180
prints out to terminal

I have strong feeling that ITM port is not enabled or some thing similar

Besides that I noticed that

board_build.stm32cube.custom_config_header = yes

did not work, it still compiles whole HAL library and seems to bypass my config file.

Could these issues be related?

Update to previous ^^^

This code:

while (1)
{
	ITM_SendChar(65);
	ITM_SendChar(10);
	ITM_SendChar(13);
	HAL_Delay(1000);
}

Prints in to terminal output:

st-trace --clock=180

A letter once a second on a new line

Running script or upload & monitor from platformio still silent

Upload & Monitor will not display SWO data, Upload + Custom → SWO Viewer should.

If not, can you change this line

to

    swo_trace_freq = str(env.GetProjectOption("swo_trace_freq", ""))

and retry?

I could not find Custom section in Project Tasks. What did I forget to set up to have it available?

Removing that rate number at L37 did not help, same results so far.

Is not available per screenshot at GitHub - maxgerhardt/pio-swo-demo: Demo on how to view SWO output with PlatformIO?

Did you switch to the correct environment of the project using the project environment switcher?

Pressing the refresh button in the top right corner of the “Project Tasks” panel doesn’t help either?

No it’s not, I’m quite sure im in the environment, refresh did not help

I pushed current state in github

Please show a screenshot of what VSCode looks like when you have the Project Tasks panel open.

You have not copied the swo_viewer.py correctly from my repo in your project. In the lower part of zendelay/add_swo_viewer.py at platformio · peersky/zendelay · GitHub, the indentation is all of.

1 Like

Okey that had to be something stupid! Now I can have that SWO view option, but output still silent.

> Executing task in folder BDSP: platformio run --target swo_viewer --environment erica_black_dsp <

Warning! Ignore unknown configuration option `swo_trace_clkin_freq` in section [env:erica_black_dsp]
Processing erica_black_dsp (platform: ststm32; board: erica_black_dsp; framework: stm32cube)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/erica_black_dsp.html
PLATFORM: ST STM32 (14.2.0) > BDSP
HARDWARE: STM32F429ZGT6 180MHz, 256KB RAM, 1MB Flash
DEBUG: Current (stlink) External (blackmagic, cmsis-dap, jlink, stlink)
PACKAGES: 
 - framework-stm32cubef4 1.26.2 
 - tool-ldscripts-ststm32 0.1.0 
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://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 180000000, SWO trace frequency 115200. Invocation:
['/Users/t/.platformio/packages/tool-openocd/bin/openocd', '-s', '/Users/t/.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 180000000 115200; itm ports on']
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-18:44)
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 V2J37M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.243627
Traceback (most recent call last):
  File "/Users/t/GitHub/synths/zendelay/targets/BDSP/swo_parser.py", line 198, in <module>
    swo_parser_main()
  File "/Users/t/GitHub/synths/zendelay/targets/BDSP/swo_parser.py", line 145, in swo_parser_main
    tcl_socket.connect((HOST, PORT))
ConnectionRefusedError: [Errno 61] Connection refused
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections

Weird, it got a connection refused from OpenOCD – when I tested it, it always waited properly for a connection.

The last two lines of swo_parser.py are

if __name__ == "__main__":
    swo_parser_main()

can you change it it to

if __name__ == "__main__":
    time.sleep(1)
    swo_parser_main()

and retry? (Ctrl+C to abort the old SWO viewer)

It seems to help but still no prints

Starting OpenOCD with SWO Trace clock-in frequency 180000000, SWO trace frequency 115200. Invocation:
['/Users/t/.platformio/packages/tool-openocd/bin/openocd', '-s', '/Users/t/.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 180000000 115200; itm ports on']
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.11.0-00155-ge392e485e (2021-03-15-18:44)
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 V2J37M27 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.243627
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32f4x.cpu on 3333
Info : Listening on port 3333 for gdb connections
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : accepting 'tcl' connection on tcp/6666
Info : Target trace output  is enabled
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz

ctrl+C out from that monitor prints following

Exited from TCL client
*** [swo_viewer] Build interrupted.
SWO client successfully connected to OpenOCD on localhost:6666
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
[Stream ID 0] 
==== Terminating SWO / TCL client program ====
Error: Aborted by user
The terminal process "platformio 'run', '--target', 'swo_viewer', '--environment', 'erica_black_dsp'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

Empty [Stream ID 0]'s come from sending new line character, but still no print,

I suppose there are two issues:

  1. VScode does not get output stream from SWO (it clearly exists from st-trace --clock=180. Or it does not flush or something like that
  2. printf is using different function than _write that I’m overriding in main.cpp

I doubt you can write that in a CPP file. Write it as

extern "C" int _write(int file, char *ptr, int len)
{