Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Apr 2007 19:27:38 +0800
From:      "Xiaofan Chen" <xiaofanc@gmail.com>
To:        freebsd-usb@freebsd.org
Subject:   libusb usb_interrupt_read hangs under FreeBSD
Message-ID:  <a276da400704030427g6fcfdc37u43bdf0fd1cd69ea8@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
I was redirected to this list as per the suggestion from the
libusb mailing list.

It will be greatly appreciated that someone can suggest
how to debug this problem?

Some more information:
===[mcuee] ~ # sudo usbdevs -v
Password:
Controller /dev/usb0:
addr 127: full speed, self powered, config 1, OHCI root hub(0x0000),
nVidia(0x0000), rev 1.00
 port 1 powered
 port 2 powered
 port 3 powered
 port 4 powered
Controller /dev/usb1:
addr 126: full speed, power 100 mA, config 1, PICkit 2 Microcontroller
Programmer(0x0033), Microchip Technology Inc.(0x04d8), rev 0.01
addr 127: full speed, self powered, config 1, OHCI root hub(0x0000),
nVidia(0x0000), rev 1.00
 port 1 powered
  port 2 addr 126: full speed, power 100 mA, config 1, PICkit 2
Microcontroller Programmer(0x0033), Microchip Technology Inc.(0x04d8),
rev 0.01
 port 3 powered
 port 4 powered
Controller /dev/usb2:
addr 127: high speed, self powered, config 1, EHCI root hub(0x0000),
nVidia(0x0000), rev 1.00
 port 1 powered
 port 2 powered
 port 3 powered
 port 4 powered
 port 5 powered
 port 6 powered
 port 7 powered
 port 8 powered

===[mcuee] ~ # uname -a
FreeBSD FreeBsd61.Mshome 6.2-STABLE FreeBSD 6.2-STABLE #0: Mon Apr  2
19:03:07 SGT 2007
root@FreeBsd61.Mshome:/home/obj/home/src/sys/USBDEBUG  i386

===[mcuee] ~/Desktop/build/pyusb-0.3.5/samples # sudo ./usbenum.py
usb_set_debug: Setting debugging level to 255 (on)
usb_os_find_busses: Found /dev/usb0
usb_os_find_busses: Found /dev/usb1
usb_os_find_busses: Found /dev/usb2
usb_os_find_devices: Found /dev/ugen0 on /dev/usb1
usb_control_msg: 128 6 512 0 0xbfbfe458 8 1000
usb_control_msg: 128 6 512 0 0x8122240 41 1000
skipped 1 class/vendor specific interface descriptors
usb_control_msg: 128 6 513 0 0xbfbfe458 8 1000
usb_control_msg: 128 6 513 0 0x8116900 32 1000
Device: /dev/ugen0
  Device class: 0
  Device sub class: 0
  Device protocol: 0
  Max packet size: 8
  idVendor: 1240
  idProduct: 51
  Device Version: 00.01
  Configuration: 1
    Total length: 41
    selfPowered: 0
    remoteWakeup: 0
    maxPower: 200
    Interface: 0
    Alternate Setting: 0
      Interface class: 3
      Interface sub class: 0
      Interface protocol: 0
      Endpoint: 0x81
        Type: 3
        Max packet size: 64
        Interval: 1
      Endpoint: 0x1
        Type: 3
        Max packet size: 64
        Interval: 1
  Configuration: 2
    Total length: 32
    selfPowered: 0
    remoteWakeup: 0
    maxPower: 200
    Interface: 0
    Alternate Setting: 0
      Interface class: 255
      Interface sub class: 0
      Interface protocol: 0
      Endpoint: 0x81
        Type: 3
        Max packet size: 64
        Interval: 1
      Endpoint: 0x1
        Type: 3
        Max packet size: 64
        Interval: 1


---------- Forwarded message ----------
From: Xiaofan Chen <xiaofanc@gmail.com>
Date: Apr 2, 2007 8:02 PM
Subject: Re: libusb usb_interrupt_write hangs under FreeBSD
To: libusb-devel@lists.sourceforge.net

On 3/24/07, Xiaofan Chen <xiaofanc@gmail.com> wrote:
> PICKit 2 is a small USB programmer from Microchip. It is an HID
> device just to avoid using a driver under Windows. Microchip
> has released the firmware and Windows host software code.
> http://www.microchip.com/pickit2
>
> I was trying to get libusb based pk2 application to work under
> FreeBSD but so far no success yet. pk2 works under Linux,
> Mac OS X and Windows.
>
> pk2 is at http://home.pacbell.net/theposts/picmicro/.
>
> I recompiled the FreeBSD kernel to disable uhid and use ugen for
> PICKit 2. So pk2 can find PICKit 2. But usb interrupt write just hangs.
>

After searching the Internet, I found the alternative USB stack for
FreeBSD.
http://lists.freebsd.org/pipermail/freebsd-usb/2006-July/002410.html

I installed the new kernel and with a simple test program using pyusb,
I found out that usb interrupt write is now working but usb interrupt
reading is still not working.

===[mcuee] ~/Desktop/build/mypk2 # cat testpk2.py
 #!/usr/local/bin/python -i

import usb

def opendevice(idVendor, idProduct):
    devices=[]

    for b in usb.busses():
        for d in b.devices:
            if d.idVendor==idVendor and d.idProduct==idProduct:
                devices.append(d)

    if len(devices)==1:
        device=devices[0]
        return device

    elif not devices:
        raise "Device not found"
    else:
        raise "More than one device found"

if __name__=="__main__":

    device=opendevice(0x04d8, 0x0033)
    packet_len=64

    dh=device.open()

    dh.setConfiguration(1)
    print "set Configuration 1"
    dh.claimInterface(0)
    print "claim Interface 0"
    #dh.setAltInterface(0)

    # First test, turn power on
    print "Turing power on by USB interrupt write"
    dh.interruptWrite(1,"V1"+(packet_len-2)*"Z",1000)
    # Second test, get version number
    print "Sending version command by USB interrupt write"
    dh.interruptWrite(1,"v"+(packet_len-1)*"Z",1000)
    print "Getting version command by USB interrupt write"
    r=dh.interruptRead(0x81,64,1000)
    print r

===[mcuee] ~/Desktop/build/mypk2 # sudo python testpk2.py
usb_set_debug: Setting debugging level to 255 (on)
usb_os_find_busses: Found /dev/usb0
usb_os_find_busses: Found /dev/usb1
usb_os_find_busses: Found /dev/usb2
usb_os_find_devices: Found /dev/ugen1 on /dev/usb1
usb_os_find_devices: Found /dev/ugen0 on /dev/usb1
usb_control_msg: 128 6 512 0 0xbfbfe2d8 8 1000
usb_control_msg: 128 6 512 0 0x8119500 218 1000
usb_control_msg: 128 6 512 0 0xbfbfe2d8 8 1000
usb_control_msg: 128 6 512 0 0x81222c0 41 1000
skipped 1 class/vendor specific interface descriptors
usb_control_msg: 128 6 513 0 0xbfbfe2d8 8 1000
usb_control_msg: 128 6 513 0 0x8116940 32 1000
setConfiguration params:
        configuration: 1
set Configuration 1
claimInterface params:
        interfaceNumber: 0
claim Interface 0
Turing power on by USB interrupt write
interruptWrite params:
        endpoint: 1
        timeout: 1000
interruptWrite buffer param:
56 31 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a
5a 5a 5a
Sending version command by USB interrupt write
interruptWrite params:
        endpoint: 1
        timeout: 1000
interruptWrite buffer param:
76 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a
5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a 5a
5a 5a 5a
Getting version command by USB interrupt write
interruptRead params:
        endpoint: 129
        size: 64
        timeout: 1000
^CUSB error: error reading from interrupt endpoint /dev/ugen1.1:
Interrupted system call
Traceback (most recent call last):
  File "testpk2.py", line 42, in ?
    r=dh.interruptRead(0x81,64,1000)
usb_os_close: closing endpoint 4

It seems to me that the alternative USB stack still suffers from usb
interrupt read problem.

Any suggestions?

Regards,
Xiaofan



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?a276da400704030427g6fcfdc37u43bdf0fd1cd69ea8>