-
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
PICkit4 and SNAP serial numbers not read by Avrdude #1038
Comments
So looks like the following two lines do not work for PICkit 4 and SNAP. Line 2424 in affe4cb
Edit: this is not correct. |
From https://github.com/microchip-pic-avr-tools/pymcuprog/blob/main/pymcuprog/backend.py |
That was my conclusion too. However, I couldn't find out how to send a generic message, to the programmer. |
My SNAP was just delivered to me. I upgraded the FW using MPLAB X and then switched the mode to AVR using Microchip Studio. In ISP mode, avrdude does not even to attempt to read the serial number, not even with
|
Hmm, by right the following should work using hidapi. But then the output of the following (using -vvvv) seems to be strange. Probably something needs to be fixed for the usb_hidapi.c code within avrdude.
I just checked hidapi's hidtest app and it works fine.
|
Just a simplified test from the hidapi's hidtest example application.
|
@MCUdude
|
Still something is not so correct about the alternative code path. By right it should still be able to find the device, just without the serial number matching. It should not complained about https://github.com/avrdudes/avrdude/blob/main/src/usb_hidapi.c#L136
|
With simple debugging, I know the reason of the message, because it tries to open 03eb:217f first but my SNAP is 03eb:2180.
|
I'm able to retrieve the serial number by adding the a code snippet to static int usbhid_open(char *port, union pinfo pinfo, union filedescriptor *fd)
{
hid_device *dev;
char *serno, *cp2;
size_t x;
unsigned char usbbuf[USBDEV_MAX_XFER_3 + 1];
// Test code to retrieve the USB serial number
struct hid_device_info *get_sn;
get_sn = hid_enumerate(pinfo.usbinfo.vid, pinfo.usbinfo.pid);
if (get_sn)
avrdude_message(MSG_INFO, "sn2: %ls\n", get_sn->serial_number);
...
However, it doesn't work in jtag3.c, since |
It looks like pymcuprog (pyedbglib) uses |
@mcuee do you know if JTAG3 compatible programmers has to use EDIT: Yes, the user may use Lines 1457 to 1489 in 159d126
|
The current avrdude codes will use hidapi first if it is available. If not it will fall back to libusb (not working for macOS). BTW hidapi in Linux may use either hidraw backend or libusb backend. hidapi under FreeBSD uses libusb backend. You will not be able to use libusb backend under macOS. But please go ahead to implement the hidapi way and we should be able to figure out the fallback libusb way later. |
For libusb, you can refer to the example here to get the USB serial number. https://github.com/libusb/libusb/blob/master/examples/testlibusb.c#L193-L211
Example output from
|
Another reference from libusb's xusb example.
|
@mcuee I think I have a working solution for hidapi. Would be great if you could give this a try: https://github.com/MCUdude/avrdude/tree/pickit4-snap-serialnumber. I'll look into how it can be accomplished with libusb later. |
It does not seem to work under Windows, also Linux, for ISP mode.
|
It oes work for the UPDI mode. The following test result is using HIDAPI libusb backend under Linux.
|
It doesn't work in ISP mode because of #1212, but this is a separate issue. |
Thanks for the clarifications. UPDI mode works fine. Test results under Windows,
|
I am having a strange issue under macOS. But the issue is not with this PR since git main also crashed. I will need to debug further.
But github action git main binary is okay. Strange.
|
It works well in printing out the serial number but then it does not go further. Kind of strange.
|
Does this happen with git main as well? I'm trying to figure out if this is caused by my commits or not. |
The behavior is a bit different but git main will not work either.
|
I just tested under Linux and git main does not work either with libusb. So the issue is not with your changes. For this test, I build avrdude without hidapi support. And I make sure the hid drver is already detached and then libusb is used. hidapi version works fine (with hidapi-libusb backend). So there is a bug here in git main.
|
The issue has been sorted out -- root cause is due to a legacy avrdude dependency libhid problem. Removing the old libhid sorted out the issue. @MCUdude
Without HIDAPI it will not work as the kernel HID driver can not be detached.
|
Thanks for testing! You can actually test libusb if you use an AVRISPmkII. Now it will print its serial number, something Avrdude didn't do before. I'll create a PR tonight. |
Good suggestion. I have only one more proper AVRISPmkii clone and it seems to work well here.
|
For some reason, the serial number string is blank with the SNAP and PICkit4.
It does however work with pkobn_updi (nEDBG) and mEDBG boards.
@janegilruud is there a different command we have to use on these gen4 programmers?
SNAP output in verbose mode:
PICkit4 output in verbose mode:
The text was updated successfully, but these errors were encountered: