Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple SWO (OpenOCD tpiu_swo_trace) Connections for External OpenOCD Server #853

Closed
Jeremin opened this issue Mar 21, 2023 · 9 comments
Closed

Comments

@Jeremin
Copy link

Jeremin commented Mar 21, 2023

Hello there

First off: Thanks for all the great work you are doing!

To my issue: I am using WSL2, STM32, STLinkV2, OpenOCD and Cortex Debug v1.10.0.

The problem I am facing is: SWO works, however it seems Cortex Debug makes a seemingly random amount of TCP connections (tpiu_swo_trace) to the OpenOCD debug server for the SWO decoder, which then results in the debug output having the same text multiple times. Some times it keeps the number of connections constant (I have never seen less than 8 connections), sometimes more are added during the run. I also verfied that SWO works fine with OpenOCD + telnet client or the STM32 Cube programmer.

Let me know if you need additional information.

Launch Configuration

        {
            "name": "RomRun Cortex Debug WSL GDB Remote Target",
            "preLaunchTask": "WSL launch build_debug",
            "postDebugTask": "WSL kill openocd",
            "type": "cortex-debug",
            "request": "launch",
            "executable": "${workspaceFolder}/build/debug/exe/RomRun.elf",
            "cwd": "${workspaceFolder}/build/debug",
            "servertype": "external",
            "configFiles": [
                "interface/stlink.cfg",
                "target/stm32f4x.cfg"
            ],
            "preLaunchCommands": [
                "set mem inaccessible-by-default off",
                "monitor reset init",
                "monitor halt",
                "monitor set remotetimeout 30",
                "monitor stm32f4x.tpiu configure -protocol uart -traceclk 168000000 -pin-freq 2000000 -output :40195 -formatter off",
                "monitor stm32f4x.tpiu enable",
                "set verbose on"
            ],
            "interface": "swd",
            "device": "STM32F427ZG",
            "runToEntryPoint": "main",
            "showDevDebugOutput": "parsed",
            "showDevDebugTimestamps": true,
            "svdFile": "${workspaceFolder}/.vscode/STM32F427.svd",
            "gdbTarget": "${env:GDB_REMOTE_TARGET}:3333",
            "swoConfig": {
                "enabled": true,
                "source": "socket",
                "swoPort": "${env:GDB_REMOTE_TARGET}:40195",
                "swoFrequency": 2000000,
                "cpuFrequency": 168000000,
                "decoders": [
                    {
                        "port": 0,
                        "label": "Debug Out",
                        "type": "console",
                        "encoding": "ascii"
                    }
                ]
            },
        },

Additional Information

  • "preLaunchTask": "WSL launch build_debug" starts OpenOCD on the Windows Host and builds the firmware.
  • "postDebugTask": "WSL kill openocd" kills the OpenOCD process after debugging.
  • ${env:GDB_REMOTE_TARGET} is the IP of the Windows host.

OpenOCD Trace

xPack OpenOCD x86_64 Open On-Chip Debugger 0.11.0+dev (2022-03-25-17:32)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.   
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections   
Info : Listening on port 4444 for telnet connections
Info : clock speed 2000 kHz
Info : STLINK V2J39S7 (API v2) VID:PID 0483:3748
Info : Target voltage: 3.242772
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 : accepting 'gdb' connection on tcp/3333       
Info : device id = 0x20036419
Info : flash size = 2048 kbytes
Info : Dual Bank 2048 kiB STM32F42x/43x/469/479 found
Info : flash size = 512 bytes
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08039d58 msp: 0x20030000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
30
Info : starting trace server for stm32f4x.tpiu on 40195
Info : Listening on port 40195 for tpiu_swo_trace connections
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08039d58 msp: 0x20030000
Info : accepting 'tpiu_swo_trace' connection on tcp/40195
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08039d58 msp: 0x20030000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : accepting 'tpiu_swo_trace' connection on tcp/40195
Info : Padding image section 0 at 0x080001ac with 596 bytes
Info : Padding image section 1 at 0x08000420 with 32 bytes
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08039d58 msp: 0x20030000
Info : accepting 'tpiu_swo_trace' connection on tcp/40195
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
Info : Unable to match requested speed 2000 kHz, using 1800 kHz
target halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0x08039d58 msp: 0x20030000
Info : accepting 'tpiu_swo_trace' connection on tcp/40195
Info : accepting 'tpiu_swo_trace' connection on tcp/40195
Info : accepting 'tpiu_swo_trace' connection on tcp/40195
Info : accepting 'tpiu_swo_trace' connection on tcp/40195
Info : accepting 'tpiu_swo_trace' connection on tcp/40195

SWO Output

Hello world 1001
Hello world 1001
Hello world 1001
Hello world 1001
Hello world 1001
Hello world 1001
Hello world 1001
Hello world 1001
Hello world 2001
Hello world 2001
Hello world 2001
Hello world 2001
Hello world 2001
Hello world 2001
Hello world 2001
Hello world 2001
Hello world 3001
Hello world 3001
Hello world 3001
Hello world 3001
Hello world 3001
Hello world 3001
Hello world 3001
Hello world 3001
Hello world 4001
Hello world 4001
Hello world 4001
Hello world 4001
Hello world 4001
Hello world 4001
Hello world 4001
Hello world 4001
haneefdm added a commit that referenced this issue Mar 21, 2023
@haneefdm
Copy link
Collaborator

Thanks for reporting the issue. WSL was taking far too long to make the connection succeed and we would timeout and try again. We were also not expecting multiple connections to be possible.

I don't have a proper WSL setup to test but could you try the latest pre-release from the marketplace? v1.11.1

It should be available in a few minutes or run Check for Extension Updates from the extensions manager (you have to enable pre-releases)

image

Please let us know if it is working

@Jeremin
Copy link
Author

Jeremin commented Mar 21, 2023

Thanks for the fast reply.

I am unable to start the debug session with the pre-release, as I get the following error:
grafik

Reloading does not do anything.

Peripheral Viewer seems to be running (locally though).
grafik

And the 1.11.1 pre-release is installed in WSL.
grafik

Am I missing something?

@fitch22
Copy link

fitch22 commented Mar 21, 2023

Just wanted to say I have seen multiple copies of SWO output in my setup which is vanilla windows 11. I am using openocd from ST, an stlink v3, and f4 and g4 flavors do stm32. Language is rust.

I would see in the terminal that multiple traces were accepted. My solution was to exit and reload things and it would generally work the 2nd time.

@haneefdm
Copy link
Collaborator

haneefdm commented Mar 21, 2023

@Jeremin Are you using a Docker container inside WSL2? VSCode seems to have a bug where they misidentify certain extensions and issue that message. All the dependencies including the peripheral viewer work both on the host side or the client side and marked as such but VSCode for some reason is confused. The peripheral viewer even works in a browser.

I updated the peripheral-viewer (please install the latest v1.4.4) and then try to uninstall and reinstall the Cortex-Debug v1.11.1

If this does not work, we may have to configure your docker container. I can probably help with that

@haneefdm
Copy link
Collaborator

@fitch22 If you are seeing this issue with no WSL, I am very surprised but, the pre-release v1.11.1 should also work for you if you want to try.

@fitch22
Copy link

fitch22 commented Mar 21, 2023

v1.11.1 seems to be working for me. I have not seen any of the multiple SWO outputs yet. However, it never happened all the time with any previous version. I will definitely let you know if I see it again, and I will capture as much information as I can.

FYI, I do have WSL2 installed, but it is not part of my debug sessions. That is done just in Windows 11.

Also, I have VMWare Workstation 16 installed. I know that VM installs various network interfaces, and could potentially do something causing the timeouts.

@haneefdm
Copy link
Collaborator

@fitch22 Yes, it is hard if it is intermittent. Let us know even if it happens once. I am working blind here too but I could see how the issue could manifest and put in a mitigation.

I hope @Jeremin can get past his install issues.

@Jeremin
Copy link
Author

Jeremin commented Mar 22, 2023

Good morning

I was already away from the desk yesterday so just replying now: Works like charm!
grafik

I tested it 5 times and it always behaved as expected.

Setup wise today it "just worked" (Peripheral Viewer 1.4.5 was installed in the background and now runs in WSL). I am not using docker inside WSL, but in the end the concept with the VSCode server running remotely should still be similar, running in a docker container vs in the WSL VM?

Let me know if there is something I can test for you. From my side it seems to be resolved.

Thanks for the quick response and fix!

@haneefdm
Copy link
Collaborator

Thanks for testing. I am going to close this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants