-
Notifications
You must be signed in to change notification settings - Fork 145
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
Differentiate multiple USB programmers of the same VID/PID (libusb or hidapi or libftdi) #973
Comments
Specific to hidapi: at least you can get the |
For libusb, same that you can get the |
For libftdi, |
Ref: OpenOCD libusb-1.0 helper may give some hints as well. It can be done using libusb-0.1 API as well since avrdude is still mostly using libusb-0.1 API. |
I have some working code for USBASP, specifying programmer with -P usb:xxx:xxx. Any interest in adding this to the project? |
How did you solve the multiplatform aspects? (Windows, Linux, MacOS, BSD) |
It would be great if you could create a PR for this! |
As a remark (since I once implemented the serno matcher in stk500v2/jtag): serial numbers can sometimes be long, and it makes most sense to just match the trailing part. (OpenOCD requires the full serial number, which is hard to type when typing manually on the commandline.) |
Sounds like there's some value to potentially adding that. I'll do some cleanup/testing and then submit something if it looks like it's working. I've only tested on Linux so far. I could check on Windows/Mac as well; not sure what the usblib differences are there. The method I'm using is by USB bus (usb:xxx:xxx). Not sure if serial no. is prefereable. |
Using a serial number is much preferable – however, I'm afraid most (all?) USBasp implementations just don't offer a serial number at all. |
The USB bus:port number may be another way to distinguish the devices: |
Indeed, unless the user is willing to rebuild the FW and program different units with different serial number. It would be good to such FW capability to usbasp FW but then we need to have a host software as well (Microchip PICKit 2 FW and host SW have the capability to program the SN and differentiate the units). @dioannidis |
I already implement it. The serial number ( 4 digits only ) is stored in eeprom and one can read / write it via HID calls only ( do I need to support control requests calls also ? ) . Didn't commit it yet cause I didn't test it enough. FYI, I choose to add, the eeprom read / write functionality, to the V-USB driver ( see obdev/v-usb#35 ) instead of using the usbFunctionDescriptor / usbFunctionSetup mechanism, because I thought that one may choose to store all the descriptors to eeprom instead of flash to save space. I'll try to find time to test it little more and upload it ASAP . |
Also we need to inform the avrdude that there is a serial number descriptor read / write functionality using the 4 bytes capability control request response ( USBASP_FUNC_GETCAPABILITIES ). Currently, the capability response ( in my firmware ) uses the 1st byte to report if it supports TPI and / or HIDUART and the 2nd byte if the USBasp device uses a different crystal from the default 12MHz. <snip>
/* USBASP capabilities */
#define USBASP_CAP_0_TPI 0x01
#define USBASP_CAP_6_UART 0x40
#define USBASP_CAP_HIDUART 0x80
#define USBASP_CAP_12MHZ_CLOCK 0x00
#define USBASP_CAP_16MHZ_CLOCK 0x01
#define USBASP_CAP_18MHZ_CLOCK 0x02
#define USBASP_CAP_20MHZ_CLOCK 0x03
<snip> Where do you propose to add the serial number capability ? <snip>
#define USBASP_FUNC_SETSERIALNUMBER 125
#define USBASP_FUNC_GETSERIALNUMBER 126
<snip> Do I need to change the USBASP_FUNC_SETSERIALNUMBER, USBASP_FUNC_GETSERIALNUMBER defines to other values ? |
I am not so sure if avrdude wants to be involved in that function of write the serial number as it is specific to your usbasp firmware. I tend to think you have to provide that functionality through your host application, outside of avrdude. avrdude will just read the serail number of your device and utilize to differentiate different units. Adding @stefanrueger as well in this discussion. |
Releavent discussion from libusb project. Take note HIDAPI provides multiple aspects of the HID device for matching the device.
|
Me neither. Since it's HIDAPI, I guess it would be easy enough to offer some Python implementation, and thus be quite platform independant. If I were you @dioannidis I wouldn't bother too much with capabilties: just hack a Python script that produces a semi-random serial number, and fire it to the USBasp device: if the device can handle it, it's fine. If not, the user is just at the same point where it has been before. ;-)
Pah, that would be really lengthy to type … |
@dl8dtl, @mcuee , @MCUdude , @stefanrueger Well, I tend to think that USBasp goes hand to hand with avrdude, over 90% ( or more ) of the time. I don't think I ever used a USBasp device using other software which is not using avrdude under the hood . As I already wrote above, I've already implemented the functionality in my USBasp fork locally and after some tests this week it will be commited . Anyway, I thought that it will be useful if the avrdude project "dictates" / "proposes" an entry point for all the usbasp firmwares to implement the serial number change set, HIDAPI or not. That will solve the platform independent issue also ... |
I've looked into this a bit more and come to a couple of conclusions: 1.) The USB path method for differentiating between multiple USBASP devices isn't great for my workflow. At least on my Ubuntu VM, the -P usb:xxx:yyy doesn't correspond to physical hub/port, so it changes each bootup or when a device is plugged in. That means it's only useful within a single session and requires some experimentation to determine which USBASP is which. 2.) I reprogrammed the USBASP firmware with the code from here https://www.fischl.de/usbasp/ with a specified serial number in the firmware/usbconfig.h file, and it seemed like a relatively painless process. It does require two USBASPs (a target and another to program the firmware on the target). That's now working with my avrdude modification to allow for -P usb:xxx (where xxx is serial number). I still have the option of specifying -P usb:xxx:yyy for the USB bus/device in my changes here, and it seems to make sense to leave that in as well for users who don't want to go to the trouble of reprogramming their USBASP. Any thoughts? |
Where can I found your avrdude patch reg. serial number ? I see no repos at https://github.com/MikeRaffa ... |
I haven't uploaded anything yet. Just got it working in my environment. Still need to get it working with the different libusb versions and test on Windows. |
Well, there is no obligation to have everything already tested and final before uploading it to your own forked repository. ;-) So if you decide to publish your own fork, others just get the possibility to peek at your work already. |
I uploaded a development version of the firmware ( for atmega88 ) at https://www.nephelae.eu/usbasp88.zip . Also the host app ( only for win64 ) is at https://www.nephelae.eu/vusbserialnumber-x86_64-win64.zip . Any feedback is appreciated ...
|
Preliminary version of -P bus/device and serial_number support for USBASP is here https://github.com/MikeRaffa/avrdude. |
Can you provide the hex file for ATmega8A? My USBAsp unit based on ATmega88 is a bit fragile and not as robust as the ones based on ATmega8A. Thanks. |
Of course. Here it is https://www.nephelae.eu/usbasp8.zip . |
Please download the hex files again, because I forgot to build them for 12Mhz crystal . I have a custom usbasp board which I test various crystals and it had an 18MHz on .... Apologies ... ( don't forget this firmware implements a composite device so only the mingw build of avrdude will work .... ) |
Your FW works very well. Itested with two USBASP (Atmega8A) units. The only minor issue is with the host software -- I need to hit a return to exit.
|
@MikeRaffa Take note all three units are still using WinUSB for Interface 0 and HID driver for Interface 1 (USB composite device) so I have to use MinGW to build avrdude binary due to issue #968 as mentioned @dioannidis.
|
Fixed both issues . Please download again the host app https://www.nephelae.eu/vusbserialnumber-x86_64-win64.zip . |
Thanks. Now the issues are fixed. |
I will remove the zip files as I updated the repository ( https://github.com/dioannidis/usbasp ) with all the changes . C:\USBaspHIDUART.exe
USBasp HIDUART Test App
-l List USBasp HID devices
-i Select USBasp index ( default 0 )
-b Set Baud ( default 9600 )
-c Set Crystal Hz ( default 12 MHz or 12000000 Hz )
-s Select USBasp with serial number.
4 Digits numeric only i.e. 3456, 2222, etc ).
-u Serial Number to update ( 4 Digits numeric only i.e. 3456, 2222, etc ).
Use with index -i when more than one USBasp are connected.
-r Continuous read input
-w Interactive send output
examples
Read from USBasp at index 0 with 4800 baud
USBaspHIDUART -b 4800 -r
Interactive write to USBasp at index 1 with 9600 baud
USBaspHIDUART -i 1 -w
Interactive write to USBasp with serial number 1111 with 9600 baud
USBaspHIDUART -s 1111 -w
Read from USBasp at index 1 with 19200 baud from a device with 20 MHz crystal
USBaspHIDUART -i 1 -b 19200 -c 20000000 -r
Read from USBasp with serial number 2345 with 19200 baud from a device with 20 MHz crystal
USBaspHIDUART -s 2345 -b 19200 -c 20000000 -r
Update the first found USBasp's serial number with 3456
USBaspHIDUART -u 3456
Update the USBasp's at index 3 serial number with 3456
USBaspHIDUART -i 3 -u 3456 After adding the capability functionality there will be a release 1.11 . Thanks for testing and for the feedback . |
Pre-release v1.11 is ready |
From here:
The user will need to put the USB Serial Number in the avrdude configure file. The code has also the place holder for using the unique descriptor or index to identify the programmers, but not implemented yet. Lines 668 to 677 in 9269102
|
Just wondering if you are interested to create a PR based on the above codes. Thanks. |
Yes, I've been meaning to do that but have been busy with other stuff. I'll try to get it done this week. |
…e VID/PID (libusb or hidapi or libftdi) Added code for USBasp to check for bus:device match using the -P option. Syntax is -P usb:<bus>:<device> (same as current USBTiny implementation). This also supports serial number check with the alternative -P usb:<serial_number> format (no ':'). In verbose mode, prints out bus/device/serial number for any found USBasps. Only tested on Linux, but it works with HAVE_LIBUSB_1_0 on or off (there's some slightly different code in the two versions of usbOpenDevice()).
Issue #973: Differentiate multiple USB programmers of the same VID/PI…
Ref: the following enhancement requests talk about usbasp
But this can be extended to other USB based programmers. If you have multiple programmers of the same types connected, the best is to differentiate them by serial number. Or you can differentiate with the Manufacturer/Product strings. Then there is another possibility is to use the locations (USB ports).
The text was updated successfully, but these errors were encountered: