-
Notifications
You must be signed in to change notification settings - Fork 149
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
Suggest compatible command when SNAP/PICKit4 in PIC mode is detected #1947
base: main
Are you sure you want to change the base?
Conversation
Alright, I'm not sure how I can add something to this PR, so I'll just copy paste the added code here. The code fragment has to be pasted into this line: Line 629 in 7668a1f
|
@MX682X Thanks! I pasted your code, but for some reason I'm getting the following error:
However, it is connected, and in AVR mode. ![]() |
Oh, I see. |
Oops, my fault, forgot to change the defines (like the VID), here is the fix.
|
It still doesn't work. I added a // No PICkit4 / SNAP (PIC mode) nor PICkit5 found, look for programmer in AVR mode
if(rv < 0) {
int i = 0;
for(LNODEID ln = lfirst(pgm->id); ln; ln = lnext(ln)) {
msg_info("i: %d, pgm->id: %s\n", i, ldata(ln));
if(str_starts(ldata(ln), "snap") || str_starts(ldata(ln), "pickit4")) {
bool is_snap_pgm = str_starts(ldata(ln), "snap");
pinfo.usbinfo.vid = USB_VENDOR_ATMEL;
pinfo.usbinfo.pid = is_snap_pgm? USB_DEVICE_SNAP_AVR_MODE: USB_DEVICE_PICKIT4_AVR_MODE;
const char *pgmstr = is_snap_pgm? "MPLAB SNAP": "PICkit 4";
// ... |
You're right, sorry for not thinking through everything - I've noticed from the screenshot that the VIDs and PIDs didn't align and focused too much on that. If this won't work, first thing I'll do after is to figure out how to commit to this PR, copy pasting code is awful... EDIT: I just realized that by redefining the defines I am able to test it with the PICkit 5.... Exams are really draining.
|
No worries @MX682X! I'm just happy you're willing to look into it. It does work, but I've never seen these perimission denied errors before...
|
Weird. If I don't use sudo, I'm not able to connect to the SNAP/PICkit4 when using |
I have never seen those errors either. I think I found the culprit though - wrong endpoints. Unluckily, Atmel and Microchip decided on using the exact opposite numbering. (AVR Mode is using 0x82 while PIC mode is using 0x81 on bulk reads, as an example). Trying to use the endpoints the wrong way might be a reason for permission problems.
|
Adjusting the USB parameters is a good thing, but changing the endpoints (and the other USB parameters) didn't make a difference. However, what did work was if I added I would prefer to only have to rely on one driver, so it would be neat if we could figure out why libusb requires Anyways, I've pushed a commit that uses hidapi if present. |
For macOS we should really only use hidapi for HID devices. And in fact I will say we should use hidapi whenever it is avaialble for any OS and then only use libusb as a fall-back in case hidapi is not available. References from libusb FAQ. |
Maybe you want to post the output of You need to install usbutil package by |
IIRC we have to use libusb when using a PICkit 5 or a PICKIT4/SNAP in PIC mode. See PR #1863 where @MX682X added UPDI support. And the reason is that we need to write to specific endpoints.
I'll try this later today |
Ah, I see. Now I remember from the comments in PR #1863. PICKit 4/SNAP in PIC mode is not an HID device, unlike in AVR mode, in that case, libusb has to be used.
|
Yes, this is still good to understand why sudo is required. By right you should not need to use sudo under macOS for generic vendor specific USB device. But if you use Linux, then you need to set up the right udev rules in order to use libusb without using sudo. |
I know that MPLAP has added the udev rules for the PICkit5 (and the other debuggers) during the installation. That's why I didn't had any problems using it. Can avrdude also add the udev rules when installed through apt when there aren't any rules yet? I can imagine there will be people trying to use the PK5 without an installed MPLAB. |
That is the responsibility of the discerning respective package maintainer within the many distros. Fedora's avrdude package installs udev rules when avrdude is installed, I believe. Avrdude offers help to formulate rules through its
|
@mcuee here is the
|
With this PR Avrdude suggests either switching the SNAP/PICkit4 to AVR mode (
-xmode=avr)
, or providing an alternative command where the appropriatepickit5
programmer option is selected. And now it wont print-p (null)
if no-p
option is specified.This has only been implemented for SNAP/PICkit4 in PIC mode. Similar functionality should be implemented for the
pickit5
programmer option if a SNAP/PICkit4 in AVR mode is detected. @MX682X probably has thoughts on how something like this could be implemented. Ideally something like this: