raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.26k stars 838 forks source link

No RPi5 config file for openocd? #1615

Closed seamusdemora closed 4 months ago

seamusdemora commented 5 months ago

I'm doing development work on a Pico using a RPi5 as the development machine. I'm also using the "Debug Probe" thing-y that you sell. Things are moving along OK, but I'm not doing anything very challenging at the moment.

However there does not appear to be a config file that applies to the RPi5 in the openocd folder. I draw this conclusion from the fact that each time I invoke openocd without the -c "adapter speed 5000" option in the command line, I get a warning in the output:

$ sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "program ina260_trial.elf verify reset exit"
Open On-Chip Debugger 0.12.0-g4d87f6d (2024-01-22-05:04)
...
Warn : An adapter speed is not selected in the init scripts. OpenOCD will try to run the adapter at the low speed (100 kHz)
Warn : To remove this warnings and achieve reasonable communication speed with the target, set "adapter speed" or "jtag_rclk" in the init scripts.
...

Note the Warning suggests setting adapter speed "in the init scripts". I don't know what the heck they mean by "init scripts", but I could find nothing appropriate in any script in /pico/openocd for setting adapter speed. So, I tried grep-ing in pico/openocd:

$ grep -rni "adapter speed" | less

This produced a rather extensive list, mostly in the pico/openocd/tcl folder. After some searching, I found a few candidates:

tcl/board/pico-debug.cfg
tcl/interface/raspberrypi-swd.cfg
tcl/interface/raspberrypi-native.cfg
tcl/interface/raspberrypi-native.cfg
tcl/target/bcm2835.cfg
testing/test-bcm2835gpio-deprecated-commands.cfg
tcl/target/bcm2711.cfg

However, after inspecting each of these files, it seems that none of them are appropriate for the RPi5 and appear to be a logical place for setting adapter speed. Also, there is no cfg file for bcm2712.

If I've missed something, please let me know. If I haven't, I would surely appreciate a configuration file that sets adapter speed, and otherwise covers the RPi5 in openocd.

kilograham commented 5 months ago

see #1611

seamusdemora commented 5 months ago

@kilograham Hey Graham - yeah, I'm aware of #1611 as I submitted that one also. However, #1611 was submitted for a different issue - an issue I've (at least temporarily) overcome by using the "Debug Probe". ... or am I missing something obvious?

peterharperuk commented 5 months ago

I use a debug probe with pi5 every day. I'll check if I get this warning

peterharperuk commented 5 months ago

I seem to have always been running openocd like this which avoids the issue...

openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000"

So I think I agree with you, it should be in target/rp2040.cfg. It can be overridden if needed. However, that would be a change in the openocd repo?

@P33M Is there any reason we're not setting a default adapter speed in openocd target/rp2040.cfg?

P33M commented 5 months ago

The realisable swclk depends on the hardware in question. It's explicitly a user choice to select a clock compatible with their hardware. 5MHz is a recommendation, but should not be a default.

peterharperuk commented 5 months ago

Is 100 kHz a sensible default? That's what your get if you don't set it. I've heard reports of pico debugging being slow - I bet this is the reason

lurch commented 5 months ago

Should this issue be moved to the https://github.com/raspberrypi/openocd/ repo?

peterharperuk commented 5 months ago

Here would be more appropriate? https://github.com/openocd-org/openocd

lurch commented 5 months ago

Our own openocd repo is still what https://github.com/raspberrypi/pico-setup/blob/master/pico_setup.sh#L135 points to, so does that need updating too? :man_shrugging: (I'm still not 100% familiar with how SWD / OpenOCD / PicoProbe / GDB and their various upstream / downstream forks all connect together)

peterharperuk commented 5 months ago

so does that need updating too?

I would guess, "yes"

P33M commented 5 months ago

I'm not averse to wrapping interface/cmsis-dap.cfg in interface/debugprobe.cfg and setting the speed there - it's a reasonable assumption that the JST connector + ribbon will be in use, which will easily do 5MHz.

And if using the Dupont connector, the wires are glued together in almost the same arrangement.

seamusdemora commented 5 months ago

The realisable swclk depends on the hardware in question. It's explicitly a user choice to select a clock compatible with their hardware. 5MHz is a recommendation, but should not be a default.

@P33M :

I mentioned in the first sentence of this issue that I was using the Debug Probe. I assume that settles the question re your comment re the "hardware in question"??

And if one were using a couple of GPIO from the RPi (instead of the Probe), could they not match the speed of the Debug Probe?

seamusdemora commented 5 months ago

I'm going to "muddy the water" a bit with some information I discovered earlier today. If someone thinks this needs go in a separate issue, pls let me know & I'll move it.

In addition to the missing adapter speed setting, it has also bothered me that I'm required to use sudo to run openocd. This gets a bit complex, so I've separated into two (2) threads to hopefully make it less so.

1. To which config file should the adapter speed 5000 be added?

I assumed that all of the required files were installed under the /home/pi/pico folder. The command I use to run openocd is as follows:

$ sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "program ina260_trial.elf verify reset exit"

I assumed that the two files called out in this command were (somewhere) under /home/pi/pico. I further assumed that rp2040.cfg was the most likely one to add the adapter speed. I used locate to find rp2040.cfg. Turns out there are two copies of that file (at least on my system):

$ locate rp2040.cfg
/home/pi/pico/openocd/tcl/target/rp2040.cfg
/usr/local/share/openocd/scripts/target/rp2040.cfg

And so I edited the file /home/pi/pico/openocd/tcl/target/rp2040.cfg to add the single line: adapter speed 5000. When I tried running openocd again, it still defaulted to 100 kHz. And so then I tried the same edit in /usr/local/share/openocd/scripts/target/rp2040.cfg. It worked... this "did the trick".

I feel like I've made progress, but wonder the point of putting two copies of rp2040.cfg on the system, and then using the one in /usr/local/share which is owned by root?

2. Why is sudo required to run openocd?

As all the files in /usr/local/share/openocd are owned by root I thought this might have something to do with it... perhaps openocd wrote something to rp2040??? Anyway, I thought changing it was worth a try:

$ sudo chown pi:pi /usr/local/share/openocd/scripts/target/rp2040.cfg

But this made no difference. There are also duplicates of the cmsis-dap.cfg file used in the openocd command, and so I chownd that file also:

$ sudo chown pi:pi /usr/local/share/openocd/scripts/interface/cmsis-dap.cfg

openocd still errors out without sudo:

$ openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "program ina260_trial.elf verify reset exit"
Open On-Chip Debugger 0.12.0-g4d87f6d (2024-01-22-05:04)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
Info : Hardware thread awareness created
Info : Hardware thread awareness created
Error: unable to find a matching CMSIS-DAP device
** OpenOCD init failed **
shutdown command invoked

At least the error message seems to pin the fault on CMSIS-DAP.

Any ideas what's going on here, and how to fix it so that sudo is not required? Or is that even possible? I think I've run out of steam at present because I don't really understand what openocd does. Hoping someone who's more knowledgeable has a solution.

lurch commented 5 months ago

I feel like I've made progress, but wonder the point of putting two copies of rp2040.cfg on the system, and then using the one in /usr/local/share which is owned by root?

I assume you've used the pico_setup.sh script? The /home/pi/pico/openocd/tcl/target/rp2040.cfg file is created by the "git clone", and the /usr/local/share/openocd/scripts/target/rp2040.cfg file is created by the "make install". (This is the way that things are typically done on Linux when installing software from sourcecode, and isn't specific to openocd). If you're really concerned about there being "two copies of the file", you could delete the entire /home/pi/pico/openocd folder after the pico_setup.sh script has finished, if you want.

Any ideas what's going on here, and how to fix it so that sudo is not required?

I suspect that openocd needs root privileges to be able to talk to the hardware (i.e. the hardware that interface/cmsis-dap.cfg is specifying)? That's probably fixable with udev (e.g. something similar to https://github.com/raspberrypi/picotool/pull/50 ) but that's not something that I'm familiar with myself.

aallan commented 5 months ago

Any ideas what's going on here, and how to fix it so that sudo is not required?

I suspect that openocd needs root privileges to be able to talk to the hardware (i.e. the hardware that interface/cmsisdap.cfg is specifying)? That's probably fixable with udev (e.g. something similar to aspberrypi/picotool#50 ) but that's not something that I'm familiar with myself.

Yes, it'll need root access to access the hardware it's talking to, and also yes, it should be fixable with udev but I've never bothered looking into what would be necessary to do that.

peterharperuk commented 5 months ago

Regarding running openocd. Are you in the plugdev group? Are you in the dialout group? I don't seem to need to run sudo and I don't appear to have a udev rule.

peterharperuk commented 4 months ago

Not sure there's anything to fix here in the pico-sdk. The instructions in the getting started guide seem clear...

src/openocd -f interface/cmsis-dap.cfg -c "adapter speed 5000" -f target/rp2040.cfg -s tcl

seamusdemora commented 4 months ago

I feel like I've made progress, but wonder the point of putting two copies of rp2040.cfg on the system, and then using the one in /usr/local/share which is owned by root?

I assume you've used the pico_setup.sh script? The /home/pi/pico/openocd/tcl/target/rp2040.cfg file is created by the "git clone", and the /usr/local/share/openocd/scripts/target/rp2040.cfg file is created by the "make install". (This is the way that things are typically done on Linux when installing software from sourcecode, and isn't specific to openocd). If you're really concerned about there being "two copies of the file", you could delete the entire /home/pi/pico/openocd folder after the pico_setup.sh script has finished, if you want.

You assume correctly; i.e. "Yes, I used pico_setup.sh to install the SDK."

Any ideas what's going on here, and how to fix it so that sudo is not required?

I suspect that openocd needs root privileges to be able to talk to the hardware (i.e. the hardware that interface/cmsis-dap.cfg is specifying)? That's probably fixable with udev (e.g. something similar to raspberrypi/picotool#50 ) but that's not something that I'm familiar with myself.

Someone ("breaker") has formulated a solution for the sudo issue - it can be found in this forum post... (maybe you should hire this guy?).

My solution was a cop-out: I used an alias for the full command - as suggested by another participant in the forum thread - including sudo and "adapter speed 5000".

Now, if I may: I can understand the sudo issue getting a bit complex. But no one here has even explained why there are two files named rp2040.cfg, and why one of them works to set the adapter speed - but the other does not?? But by all means, let's close the issue & move on.

peterharperuk commented 4 months ago

Charming

seamusdemora commented 4 months ago

@peterharperuk

Charming

Hope you find the edited version a bit less offensive. But really Mr Harper - do you honestly feel this is the way things get fixed and improved?

peterharperuk commented 4 months ago

Perhaps you can suggest to this b team member what fixes to this problem can be put the pico-sdk?

seamusdemora commented 4 months ago

Perhaps you could actually read the comments? Like this one from two weeks ago? The relevant part being:

And so then I tried the same edit in /usr/local/share/openocd/scripts/target/rp2040.cfg. It worked... this "did the trick". I feel like I've made progress, but wonder the point of putting two copies of rp2040.cfg on the system, and then using the one in /usr/local/share which is owned by root?

Forgive me please if I missed something, but I don't think anyone followed up on this point.

seamusdemora commented 4 months ago

... and crickets.

Well, after all, it's a "closed issue", isn't it?

lurch commented 4 months ago

but wonder the point of putting two copies of rp2040.cfg on the system

I already answered that: The /home/pi/pico/openocd/tcl/target/rp2040.cfg file is created by the "git clone", and the /usr/local/share/openocd/scripts/target/rp2040.cfg file is created by the "make install".

... and crickets.

:cricket: :cricket_game:

seamusdemora commented 4 months ago

@lurch Ah - so that answers the question re why there are two files, but does it also answer the question "Why is the adapter speed 5000 config item ignored in the file that's at /home/pi/pico/openocd/tcl/target/rp2040.cfg?"

lurch commented 4 months ago

Because when you run openocd at the command-line, that'll use the binary that exists in your $PATH (i.e. the one in /usr/local/bin/ rather than the one in /home/pi/pico/openocd/src/) and as you might expect, the systemwide-installed version of /usr/local/bin/openocd will look for the corresponding systemwide-installed config files in /usr/local/share/openocd/scripts/ .

I guess you also missed the part where I said: If you're really concerned about there being "two copies of the file", you could delete the entire /home/pi/pico/openocd folder after the pico_setup.sh script has finished, if you want.

seamusdemora commented 4 months ago

@lurch

Even when the command line specifies: sudo openocd -d0 ... -f target/rp2040.cfg ... ? What did it do with the target part? And I'm not really concerned about there being "two copies of the file" - I think you know that. I am trying to follow the documentation, and I am trying to factor in other input that I get here. I don't think I'm wrong for expecting it to work, and I know from reading on the forum that I'm not the only one that's confused by this openocd business - e.g. REF #1611.

The command I used comes from the "Getting Started" Guide:

openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -s tcl 

So, if I made a mistake, please feel free to point that out. And I still maintain it's wrong to close issues before they're resolved.

lurch commented 4 months ago

What did it do with the target part?

cleverca22 already answered that here: https://github.com/raspberrypi/pico-sdk/issues/1611#issuecomment-1923467090

And I'm not really concerned about there being "two copies of the file" - I think you know that.

Sorry, perhaps I should have written "confused" rather than "concerned".

The command I used comes from the "Getting Started" Guide:

If you have problems with the PDF documentation, the correct place for reporting that is at https://github.com/raspberrypi/pico-feedback not the pico-sdk repo.

seamusdemora commented 4 months ago

What did it do with the target part?

cleverca22 already answered that here: #1611 (comment)

That is a rather ambiguous answer.

And I'm not really concerned about there being "two copies of the file" - I think you know that.

Sorry, perhaps I should have written "confused" rather than "concerned".

Perhaps you should.

The command I used comes from the "Getting Started" Guide:

If you have problems with the PDF documentation, the correct place for reporting that is at https://github.com/raspberrypi/pico-feedback not the pico-sdk repo.

Oh, how very smart... But how do we know the problem is with the documentation? It could be - as has been shown here - that the location of the problem is very hard to pin down!