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

SWO support is not being fully enabled in pyOCD #646

Closed
grigorig opened this issue May 5, 2022 · 8 comments
Closed

SWO support is not being fully enabled in pyOCD #646

grigorig opened this issue May 5, 2022 · 8 comments

Comments

@grigorig
Copy link

grigorig commented May 5, 2022

When I try to enable SWO console output with pyOCD, I don't get any output. My configurations looks like this:

"swoConfig": {
    "enabled": true,
    "cpuFrequency": 32000000,
    "swoFrequency": 2000000,
    "source": "probe",
    "decoders": [
        {
            "type": "console",
            "port": 0,
            "label": "Output",
            "encoding": "ascii",
            "timestamp": true
        }
    ]
},

When I add -Oenable_swv=1 to serverArgs, it starts working. I think this should be added when SWO is configured.

@haneefdm
Copy link
Collaborator

haneefdm commented May 5, 2022

Thanks for reporting this. Not sure when that was added. We did not need that before. If SWO is enabled, we added the following

                const args = [
                    '-O', 'swv_raw_enable=true',
                    '-O', `swv_raw_port=${swoPort}`,
                    '-O', `swv_system_clock=${cpuF}`,
                    '-O', `swv_clock=${swoF}`];

The variables you see with $ are simply the variables you specified for the frequencies

Note that we split the -O from the next word and you seem to have concatenated them. Perhaps it works both ways? Can you try the following and make sure that also works?

"serverArgs": [
    "-O",
    "enable_swv=1"
]

I don't want to change any more code in the extension than I have to. Since I don't have a good board to try this out, I have to trust you for the change, but I will be happy to make that change.

@haneefdm
Copy link
Collaborator

haneefdm commented May 5, 2022

I think before, swv_raw_enable=true did the trick. Wonder when it changed and why it is not working.

If we did not set it to raw, we got already parsed results so, it was not standard (pre-parsed) SWO packets. We need the raw byte stream.

@grigorig
Copy link
Author

grigorig commented May 5, 2022

Yes, it seems to work both ways. No idea if it changed at some point, the flag was introduced with the initial SWO support in pyOCD. It sounds like it's supposed to be needed to enable SWO. I don't get any extra output in the pyOCD terminal.

@haneefdm
Copy link
Collaborator

haneefdm commented May 5, 2022

Yes it was there originally, but when tested it, it did not require it. Now it looks like we need both enable_swv and swv_raw_enable

@grigorig
Copy link
Author

grigorig commented May 5, 2022

pyocd/pyOCD#1014 also kind of implies that the flag should be used with the raw output. Maybe it worked before without it as a happy little accident.

@haneefdm
Copy link
Collaborator

haneefdm commented May 5, 2022

I think we have a problem...
image

They are initialiing a bunch of stuff and so are we. These are the GDB macros that are executed

        const ratio = Math.floor(cpuFrequency / swoFrequency) - 1;
        const commands: string[] = [
            'EnableITMAccess',
            `BaseSWOSetup ${ratio}`,
            'SetITMId 1',
            'ITMDWTTransferEnable',
            'DisableITMPorts 0xFFFFFFFF',
            `EnableITMPorts ${portMask}`,
            'EnableDWTSync',
            'ITMSyncEnable',
            'ITMGlobalEnable'
        ];

This stuff predates me.

These macros are in the gdbsupport.init file in /support directory. I don't think the first four lines are needed because it will trample on what pyOCD is doing. In fact, maybe none of it is needed except for the portmasks. You can probably edit that file in the install dir. and experiment. Those macros also use hard-coded addresses for TPIU/DWTetc. and with more recent MCU, they are no longer at ARM specified default addresses for some devices.

You can make a copy of the file and load it in your preLaunchCommands and it will override the original macros.

All of this is if you have the time or inclination to help. It will be much appreciated.

@grigorig
Copy link
Author

grigorig commented May 5, 2022

Hm, yeah I noticed that TPIU/ITM configuration is a bit of a problem.

I guess in an ideal world, the debug server would know all device specific details and offer some high-level interface to configure TPIU/ITM, right? I wonder if it's worth the effort to work towards that.

@haneefdm
Copy link
Collaborator

The original issue should be fixed in 1.5.0

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

2 participants