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

pico Timers not counting when debugging with picoprobe-cmsis-v1.0.1 and upstream openocd 0.12.0-rc2 #45

Closed
BestClaws opened this issue Nov 16, 2022 · 7 comments

Comments

@BestClaws
Copy link

BestClaws commented Nov 16, 2022

My Raspberry Pi Pico's timers are not working the counter is stuck at zero after switicing to the latest release of picoprobe

When It used to work:

followed usual guide from pico c/c++ sdk to compile openocd and picoprobe
have used openocd 0.11.x and the latest uf2 provided (one without cmsis-dap support)

my vscode launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Pico",
            "request": "launch",
            "type": "cortex-debug",
            "cwd": "${workspaceRoot}",
            "executable": "${workspaceFolder}/target/thumbv6m-none-eabi/debug/learn_pico",
            "preLaunchTask": "build_binary",
            "servertype": "external",
            "gdbPath" : "gdb-multiarch",
            "gdbTarget": "localhost:3333",
            "runToEntryPoint": "main",
            "preLaunchCommands": [
                "monitor init",
                "monitor reset init",
                "monitor halt",
            ],
            "postRestartCommands": [
                "break main",
                "continue"
            ],
        }
    ]
}

timers are working correctly

When it stopped working

with upstream openocd 0.12.0-rc2 (build steps followed: $ ./bootstrap $ ./configure $ make -j4)
and picoprobe-cmsis-v1.0.1

and with the following command to start openocd

openocd -d2 -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c 'adapter speed 10000;'

My timers' counter no longer counts up.

monitor reset command makes them tick again. but

upon using any thing else like in above vscode config preLaunchCommands, they stop counting.

@P33M
Copy link
Contributor

P33M commented Nov 16, 2022

Two things have changed in your setup. Which was the breaking change? picoprobe-cmsis-v1.0.1 will work on both downstream openocd and upstream.

@BestClaws
Copy link
Author

Two things have changed in your setup. Which was the breaking change? picoprobe-cmsis-v1.0.1 will work on both downstream openocd and upstream.

right, the upstream openocd (openocd 0.12.0-rc2) seems to break it. i decided to switch to it based on this comment from a different thread. thanks for the input that it works with both openocd.

@P33M
Copy link
Contributor

P33M commented Nov 16, 2022

When are you expecting the timers to increment - do they run when the target isn't halted, and is the downstream behaviour that they always run even when halted?

@BestClaws
Copy link
Author

I expect the timer specifically the 64 bit counter to start counting as soon as the program starts. And the counter to stop when I raise a halt. In both openocd the counter counts up when you just do a reset via monitor reset and I can monitor halt and continue to stop and resume aswell. but with upstream when I or vscode try to do anything like monitor reset halt or monitor reset init and then continue my code just reports the counter value as 0 all the time.

here's a sample rust code: https://gist.github.com/BobyClaws/0e224d66b62b6a6a6d1bc680c1908395#file-main-rs-L73

@cstoitner
Copy link

I have the same problem. With OpenOCD 0.12.0-rc2 and picoprobe-cmsis-v1.0.1 the timer hardware always returns 0 when gdb is connected. When running the same file without gdb, even if flashed with openocd over the picoprobe, the timer will start returning non zero values very quickly after starting main.

Example code:

#include <cstdio>
#include <pico/stdlib.h>
#include <hardware/structs/systick.h>

int main()
{
    stdio_init_all();
    systick_hw->csr = 0x5;
    systick_hw->rvr = 0x00FFFFFF;

    printf( "start...\n" );
    while ( true )
    {
        printf( "time: %llu systick: %lu\n", time_us_64(), systick_hw->cvr);
    }
}

The systick hardware works as expected.

@cstoitner
Copy link

cstoitner commented Nov 30, 2022

I got another CMSIS based probe to test. Turns out this is not a bug with the pico probe or openocd.

The default configuration for openocd 0.12rc2 with an rp2040 target will debug both cores with dedicated gdb instances. With my configuration this meant the second core was always stopped as I never connected the second gdb instance. The rp2040 timer is set up by default to stop counting when any core is stopped by a debugger and so the timer would never advance.

You can use set USE_CORE 0 in the openocd config to select just the first core for debugging and the problem disappears. Multicore debugging with a single gdb instance is not yet supported with upstream openocd on the rp2040.

@dojoe
Copy link

dojoe commented Apr 13, 2024

You can use set USE_CORE 0 in the openocd config to select just the first core for debugging and the problem disappears. Multicore debugging with a single gdb instance is not yet supported with upstream openocd on the rp2040.

For others finding this issue, here are two details I tripped over at first that weren't immediately clear to me:

  1. If you're launching OpenOCD manually, set USE_CORE 0 must be set before rp2040.cfg is loaded since the variable influences the behavior of rp2040.cfg. If OpenOCD only brings up a single gdb server according to its output, the setting worked correctly.
  2. If the Pico still hangs after you changed the setting, core 1 might still be in debug mode from when OpenOCD was configured to control both cores. Power cycle or reset the Pico, that should clear things up.

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

4 participants