First symptom: Running usb_pickit produces the following error message:
./usb_pickit --config
Locating USB Microchip(tm) PICkit(tm) (vendor 0x04d8/product 0x0032)
Found USB PICkit as device '007' on USB bus 004
Fatal error> Error setting USB configuration.
So, something's wrong. Here's what dmesg has to say (/var/log/messages
also has it):
usb 4-2: new low speed USB device using ohci_hcd and address 7
usb 4-2: configuration #1 chosen from 2 choices
hiddev96: USB HID v1.00 Device [Microchip Technology Inc. PICkit(TM) 1
FLASH Starter Kit] on usb-0000:00:13.2-2
usb 4-2: usbfs: interface 0 claimed by usbhid while 'usb_pickit' sets
config #2
This shows the kernel binding the device to the usbhid driver when it's
plugged in. Yet the usb_pickit needs to access it through the usbfs
driver (I think) later. I don't know why on Earth the kernel thinks
this is an HID device (I haven't spent the time required to grok the
udevinfo output, but there's tons of numbers in there; presumably one
of them is cueing the kernel about the usbhid link). I tried looking
for the blacklist file (to force it to ignore the device), but that's
been done away with in the name of the new udev system. And I don't
know that much about sysfs. OK. So, I just have to get the kernel to
let go of the device driver for usbhid. I did it manually using the
unbind feature conveniently built into userspace, as described here:
http://lwn.net/Articles/143397/
First, find the device. I did the following (only relevant entries
shown):
tree /sys/bus/usb/drivers/
/sys/bus/usb/drivers/
|-- usbhid
| |-- 4-2:1.0 ->
../../../../devices/pci0000:00/0000:00:13.2/usb4/4-2/4-2:1.0
| |-- bind
| |-- new_id
| `-- unbind
This shows both the relevant entry (match the usb 4-2 address with the
dmesg output) and the unbinder we need to use.
Do the following (as root) to remove the usbhid binding:
echo -n "4-2:1.0" > /sys/bus/usb/drivers/usbhid/unbind
Done. Now that the usbhid driver has let go of the device, usb_pickit
is free to reconfigure it and it works great, as usual.
Cheers,
- Bill Alexander
P.S. This email is what I use for public venues - I don't read anything
that arrives there. I'll watch the group for a few days in case
there's anything else I can add...
P.P.S. My apologies if this is OT. Orion's and Jeff's websites
indicated this might be an appropriate venue for usb_pickit discussions.
You can try to patch usb_pickit.c under Linux.
if (d){
/* add the following to detach the kernel HID driver under Linux */
int retval;
char dname[32] = {0};
retval = usb_get_driver_np(d, 0, dname, 31);
if (!retval)
usb_detach_kernel_driver_np(d, 0);
/* End of added code */
/* This is our device-- claim it */
byte retData[reqLen];
if (usb_set_configuration(d,pickit_configuration)) {
bad("Error setting USB configuration.\n");
}
...
}
PICkit 1 and PICkit 2 both have two configurations. The first
configurations is HID. This makes PICkit 1/2 work under Windows
without the need of a customized driver. They can use the
built-in HID driver under Windows 98SE and above.
Under Linux, the kernel HID driver will claim it.
By the way, you can use hotplug script to run usb_pickit under
Linux as a normal user under FC4. Under FC5, it is said that
hotplug script is not working. You need to use udev rules.
It is also said that the above kernel driver detaching
function help the hotplug scripts or udev rules.
Regards,
Xiaofan
I've tested the patch under FC4 and Ubuntu Breezy and now usb_pickit
works fine. I am using the latest version from Jeff Boly.
http://www.teammojo.org/PICkit/pickit1.html
By the way, I am using hotplug script under Ubuntu Breezy and I can
run usb_pickit as normal user.
I am now trying the udev rules under FC4 but it is not working for
pyk and usb_pickit. It does work for pk2. A bit strange. I have not
used FC4 for quite a while since I am mainly using Ubuntu Breezy.
The hotplug scripts and udev rules are listed here:
http://piklab.sourceforge.net/support.php
The next version of piklab should support PICkit 1 along with PICkit 2
and ICD2.
Regards,
Xiaofan
Your patch works perfectly. Thanks also for the explanation about the
two operating USB modes; this clears up my confusion about the HID
issue.
I did try working with some udev rules, but had no luck; the kernel
still insisted on binding the device to the HID driver. Also, in FC5
they have removed hotplug, so we can't use that.
Thanks for the patch!
- Bill