Hi everyone! I'm just starting to make my own USB devices with the Microchip PIC16c745 microcontroller.
For those who don't already know, the 16c745 is a low-speed only device, and hence limited to control and interrupt endpoints. I'll be making various kinds of IO devices and for ease of use I'd like to stick to making HID devices mostly because of good HID driver availability. I'd like to use libusb for accessing my device at least in *ix systems, whether I'll use libusb-win32 in Windows or not will be determined later, I've seen some remarks that the libusb design doesn't fit very well within the Windows driver model (gee, surprise) so at first I'll stick to HID. I want to be able to use both reports and interrupt transfers to communicate with the device, probably not in the same project though. Am I correct in understanding that the libusb usb_bulk_read/write() functions will use interrupt transfers for interrupt endpoints in spite of their names? Anyway, I've started mocking with the descriptors, and with a few lines of libusb code (usb-oops.c, attached) I can make my kernel oops (usb-oops.txt) reliably. What gives? (Should I run ksymoops even though function names are in the oops? No, right?) The system (Thinkpad T20) is powered up with the device detached. I plug the device in, and it shows up fine. (As a mouse though, guess that's because of the report descriptor that I haven't yet changed from the Microchip mouse example.) I run lsusb twice, causing the usbfs: warnings, and then I run usb-oops. I also wonder why lsusb (lsusb.txt) is unable to read the mfr and product strings, while the kernel reads them just fine, as seen in the dmesg output. I hope the attachments are ok. Thanks in advance for any suggestions that you may have and want to tell me about, although a few of my current question marks probably are off-topic for this list. Sorry about that. //Peter
#include <stdio.h> #include <stdlib.h> #include <usb.h> int main(int argc,char **argv) { int i,ep; struct usb_bus *busses,*bus; struct usb_device *dev; usb_dev_handle *dev_handle; usb_init(); usb_find_busses(); usb_find_devices(); busses=usb_get_busses(); for(bus=busses;bus;bus=bus->next) for(dev=bus->devices;dev;dev=dev->next) if(dev->descriptor.idVendor==0x04d8&&dev->descriptor.idProduct==0x0001) goto found; return 0; found: dev_handle=usb_open(dev); i=usb_set_configuration(dev_handle,0); printf("usb_set_configuration=%d\n",i); if(i<0) return 1; i=usb_claim_interface(dev_handle,0); printf("usb_claim_interface=%d\n",i); if(i<0) return 1; ep=dev->config->interface->altsetting->endpoint->bEndpointAddress; printf("using ep 0x%x\n",ep); i=usb_resetep(dev_handle,ep); printf("usb_resetep=%d\n",i); if(i<0) return 1; usb_release_interface(dev_handle,0); usb_close(dev_handle); return 0; }
Linux version 2.6.0-test11 ([EMAIL PROTECTED]) (gcc version 3.2.2 20030322 (Gentoo Linux 1.4 3.2.2-r2)) #4 Tue Dec 16 09:06:15 CET 2003 BIOS-provided physical RAM map: BIOS-e820: 0000000000000000 - 000000000009f800 (usable) BIOS-e820: 000000000009f800 - 00000000000a0000 (reserved) BIOS-e820: 00000000000e0000 - 0000000000100000 (reserved) BIOS-e820: 0000000000100000 - 0000000017ff0000 (usable) BIOS-e820: 0000000017ff0000 - 0000000017ffec00 (ACPI data) BIOS-e820: 0000000017ffec00 - 0000000018000000 (ACPI NVS) BIOS-e820: 00000000fff80000 - 0000000100000000 (reserved) 383MB LOWMEM available. On node 0 totalpages: 98288 DMA zone: 4096 pages, LIFO batch:1 Normal zone: 94192 pages, LIFO batch:16 HighMem zone: 0 pages, LIFO batch:1 DMI 2.3 present. ACPI disabled because your bios is from 1999 and too old You can enable it with acpi=force IBM machine detected. Enabling interrupts during APM calls. IBM machine detected. Disabling SMBus accesses. ACPI: RSDP (v000 PTLTD ) @ 0x000f7170 ACPI: RSDT (v001 PTLTD RSDT 0x06041210 LTP 0x00000000) @ 0x17ff4e36 ACPI: FADT (v001 IBM TP-T20 0x06041210 0x00000000) @ 0x17ffeb65 ACPI: BOOT (v001 PTLTD $SBFTBL$ 0x06041210 LTP 0x00000001) @ 0x17ffebd9 ACPI: DSDT (v001 IBM TP-T20 0x06041210 MSFT 0x0100000c) @ 0x00000000 Building zonelist for node : 0 Kernel command line: auto BOOT_IMAGE=lix260t11 ro root=303 snd-cs46xx:thinkpad=1,mmap_valid=1 Initializing CPU#0 PID hash table entries: 2048 (order 11: 16384 bytes) Detected 647.320 MHz processor. Console: colour VGA+ 80x25 Memory: 382656k/393152k available (4090k kernel code, 9740k reserved, 1213k data, 160k init, 0k highmem) Calibrating delay loop... 1277.95 BogoMIPS Dentry cache hash table entries: 65536 (order: 6, 262144 bytes) Inode-cache hash table entries: 32768 (order: 5, 131072 bytes) Mount-cache hash table entries: 512 (order: 0, 4096 bytes) CPU: After generic identify, caps: 0383f9ff 00000000 00000000 00000000 CPU: After vendor identify, caps: 0383f9ff 00000000 00000000 00000000 CPU: L1 I cache: 16K, L1 D cache: 16K CPU: L2 cache: 256K CPU: After all inits, caps: 0383f9ff 00000000 00000000 00000040 Intel machine check architecture supported. Intel machine check reporting enabled on CPU#0. CPU: Intel Pentium III (Coppermine) stepping 03 Enabling fast FPU save and restore... done. Enabling unmasked SIMD FPU exception support... done. Checking 'hlt' instruction... OK. POSIX conformance testing by UNIFIX NET: Registered protocol family 16 PCI: PCI BIOS revision 2.10 entry at 0xfd94f, last bus=7 PCI: Using configuration type 1 mtrr: v2.0 (20020519) ACPI: Subsystem revision 20031002 ACPI: Interpreter disabled. Linux Kernel Card Services options: [pci] [cardbus] [pm] drivers/usb/core/usb.c: registered new driver usbfs drivers/usb/core/usb.c: registered new driver hub ACPI: ACPI tables contain no PCI IRQ routing entries PCI: Invalid ACPI-PCI IRQ routing table PCI: Probing PCI hardware PCI: Probing PCI hardware (bus 00) PCI: Discovered primary peer bus 08 [IRQ] PCI: Using IRQ router PIIX/ICH [8086/7110] at 0000:00:07.0 NET: Registered protocol family 23 Bluetooth: Core ver 2.3 NET: Registered protocol family 31 Bluetooth: HCI device and connection manager initialized Bluetooth: HCI socket layer initialized SBF: ACPI BOOT descriptor is wrong length (39) SBF: Simple Boot Flag extension found and enabled. SBF: Setting boot flags 0x1 Machine check exception polling timer started. apm: BIOS version 1.2 Flags 0x03 (Driver version 1.16ac) ikconfig 0.7 with /proc/config* devfs: v1.22 (20021013) Richard Gooch ([EMAIL PROTECTED]) devfs: boot_options: 0x1 Installing knfsd (copyright (C) 1996 [EMAIL PROTECTED]). NTFS driver 2.1.5 [Flags: R/O]. udf: registering filesystem SGI XFS for Linux with no debug enabled SGI XFS Quota Management subsystem Limiting direct PCI/PCI transfers. pty: 256 Unix98 ptys configured lp: driver loaded but no devices found Real Time Clock Driver v1.12 Linux agpgart interface v0.100 (c) Dave Jones agpgart: Detected an Intel 440BX Chipset. agpgart: Maximum main memory to use for agp memory: 321M agpgart: AGP aperture is 64M @ 0xf8000000 Serial: 8250/16550 driver $Revision: 1.90 $ 8 ports, IRQ sharing disabled ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A ttyS1 at I/O 0x2f8 (irq = 3) is a NS16550A parport0: PC-style at 0x378 [PCSPP] parport0: cpp_daisy: aa5500ff(38) parport0: assign_addrs: aa5500ff(38) parport0: cpp_daisy: aa5500ff(38) parport0: assign_addrs: aa5500ff(38) lp0: using parport0 (polling). Using anticipatory io scheduler Floppy drive(s): fd0 is 1.44M FDC 0 is a National Semiconductor PC87306 RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize loop: loaded (max 8 devices) nbd: registered device at major 43 PCI: Found IRQ 9 for device 0000:00:03.0 PCI: Sharing IRQ 9 with 0000:00:03.1 3c59x: Donald Becker and others. www.scyld.com/network/vortex.html 0000:00:03.0: 3Com PCI 3c556B Laptop Hurricane at 0x1800. Vers LK1.1.19 PPP generic driver version 2.4.2 PPP Deflate Compression module registered PPP BSD Compression module registered Universal TUN/TAP device driver 1.5 (C)1999-2002 Maxim Krasnyansky orinoco.c 0.13e (David Gibson <[EMAIL PROTECTED]> and others) orinoco_cs.c 0.13e (David Gibson <[EMAIL PROTECTED]> and others) Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2 ide: Assuming 33MHz system bus speed for PIO modes; override with idebus=xx PIIX4: IDE controller at PCI slot 0000:00:07.1 PIIX4: chipset revision 1 PIIX4: not 100% native mode: will probe irqs later ide0: BM-DMA at 0x1c00-0x1c07, BIOS settings: hda:DMA, hdb:pio ide1: BM-DMA at 0x1c08-0x1c0f, BIOS settings: hdc:DMA, hdd:pio hda: HITACHI_DK23AA-12B, ATA DISK drive ide0 at 0x1f0-0x1f7,0x3f6 on irq 14 hdc: CRN-8241U, ATAPI CD/DVD-ROM drive ide1 at 0x170-0x177,0x376 on irq 15 hda: max request size: 128KiB hda: 23572080 sectors (12068 MB) w/512KiB Cache, CHS=24944/15/63, UDMA(33) /dev/ide/host0/bus0/target0/lun0: p1 p3 hdc: ATAPI 24X CD-ROM drive, 128kB Cache, UDMA(33) Uniform CD-ROM driver Revision: 3.12 video1394: Installed video1394 module raw1394: /dev/raw1394 device initialized PCI: Found IRQ 11 for device 0000:00:02.0 PCI: Sharing IRQ 11 with 0000:00:05.0 PCI: Sharing IRQ 11 with 0000:01:00.0 Yenta: CardBus bridge found at 0000:00:02.0 [1014:0130] Yenta: Using INTVAL to route CSC interrupts to PCI Yenta: Routing CardBus interrupts to PCI Yenta: ISA IRQ list 04b8, PCI irq11 Socket status: 30000006 PCI: Found IRQ 11 for device 0000:00:02.1 Yenta: CardBus bridge found at 0000:00:02.1 [1014:0130] Yenta: Using INTVAL to route CSC interrupts to PCI Yenta: Routing CardBus interrupts to PCI Yenta: ISA IRQ list 04b8, PCI irq11 Socket status: 30000006 ehci_hcd: block sizes: qh 128 qtd 96 itd 128 sitd 64 drivers/usb/host/uhci-hcd.c: USB Universal Host Controller Interface driver v2.1 PCI: Found IRQ 11 for device 0000:00:07.2 uhci_hcd 0000:00:07.2: UHCI Host Controller uhci_hcd 0000:00:07.2: irq 11, io base 00001c20 uhci_hcd 0000:00:07.2: new USB bus registered, assigned bus number 1 drivers/usb/host/uhci-hcd.c: detected 2 ports uhci_hcd 0000:00:07.2: root hub device address 1 usb usb1: new device strings: Mfr=3, Product=2, SerialNumber=1 drivers/usb/core/message.c: USB device number 1 default language ID 0x409 usb usb1: Product: UHCI Host Controller usb usb1: Manufacturer: Linux 2.6.0-test11 uhci_hcd usb usb1: SerialNumber: 0000:00:07.2 drivers/usb/core/usb.c: usb_hotplug usb usb1: registering 1-0:1.0 (config #1, interface 0) drivers/usb/core/usb.c: usb_hotplug hub 1-0:1.0: usb_probe_interface hub 1-0:1.0: usb_probe_interface - got id hub 1-0:1.0: USB hub found hub 1-0:1.0: 2 ports detected hub 1-0:1.0: standalone hub hub 1-0:1.0: ganged power switching hub 1-0:1.0: global over-current protection hub 1-0:1.0: Port indicators are not supported hub 1-0:1.0: power on to power good time: 2ms hub 1-0:1.0: hub controller current requirement: 0mA hub 1-0:1.0: local power source is good hub 1-0:1.0: no over-current condition exists hub 1-0:1.0: enabling power on all ports drivers/usb/core/usb.c: registered new driver usblp drivers/usb/class/usblp.c: v0.13: USB Printer Device Class driver drivers/usb/core/usb.c: registered new driver hiddev drivers/usb/core/usb.c: registered new driver hid drivers/usb/input/hid-core.c: v2.0:USB HID core driver drivers/usb/core/usb.c: registered new driver usbserial drivers/usb/serial/usb-serial.c: USB Serial Driver core v2.0 drivers/usb/serial/usb-serial.c: USB Serial support registered for Handspring Visor / Palm OS drivers/usb/serial/usb-serial.c: USB Serial support registered for Sony Clie 3.5 drivers/usb/core/usb.c: registered new driver visor drivers/usb/serial/visor.c: USB HandSpring Visor / Palm OS driver v2.1 mice: PS/2 mouse device common for all mice input: PS/2 Generic Mouse on isa0060/serio1 serio: i8042 AUX port at 0x60,0x64 irq 12 input: AT Translated Set 2 keyboard on isa0060/serio0 serio: i8042 KBD port at 0x60,0x64 irq 1 Bluetooth: HCI USB driver ver 2.4 drivers/usb/core/usb.c: registered new driver hci_usb Advanced Linux Sound Architecture Driver Version 0.9.7 (Thu Sep 25 19:16:36 2003 UTC). PCI: Found IRQ 11 for device 0000:00:05.0 PCI: Sharing IRQ 11 with 0000:00:02.0 PCI: Sharing IRQ 11 with 0000:01:00.0 cs46xx: failure waiting for FIFO command to complete ALSA device list: #0: Sound Fusion CS46xx at 0xe8100000/0xe8000000, irq 11 oprofile: using timer interrupt. NET: Registered protocol family 2 IP: routing cache hash table of 4096 buckets, 32Kbytes TCP: Hash tables configured (established 32768 bind 65536) ip_conntrack version 2.1 (3071 buckets, 24568 max) - 300 bytes per conntrack ip_tables: (C) 2000-2002 Netfilter core team NET: Registered protocol family 1 NET: Registered protocol family 17 Bridge firewalling registered Ebtables v2.0 registered IrCOMM protocol (Dag Brattli) Bluetooth: L2CAP ver 2.1 Bluetooth: L2CAP socket layer initialized Bluetooth: SCO (Voice Link) ver 0.3 Bluetooth: SCO socket layer initialized Bluetooth: RFCOMM ver 1.0 Bluetooth: RFCOMM socket layer initialized Bluetooth: RFCOMM TTY layer initialized Bluetooth: BNEP (Ethernet Emulation) ver 1.0 Bluetooth: BNEP filters: protocol 802.1Q VLAN Support v1.8 Ben Greear <[EMAIL PROTECTED]> All bugs added by David S. Miller <[EMAIL PROTECTED]> kjournald starting. Commit interval 5 seconds EXT3-fs: mounted filesystem with ordered data mode. VFS: Mounted root (ext3 filesystem) readonly. Mounted devfs on /dev Freeing unused kernel memory: 160k freed drivers/usb/host/uhci-hcd.c: 1c20: suspend_hc EXT3 FS on hda3, internal journal NTFS volume version 3.1. cs: IO port probe 0x0c00-0x0cff: clean. cs: IO port probe 0x0800-0x08ff: clean. cs: IO port probe 0x0100-0x04ff: excluding 0x3c0-0x3df 0x4d0-0x4d7 cs: IO port probe 0x0a00-0x0aff: clean. drivers/usb/host/uhci-hcd.c: 1c20: wakeup_hc hub 1-0:1.0: port 1, status 301, change 1, 1.5 Mb/s hub 1-0:1.0: debounce: port 1: delay 100ms stable 4 status 0x301 hub 1-0:1.0: new USB device on port 1, assigned address 2 usb 1-1: new device strings: Mfr=1, Product=2, SerialNumber=0 drivers/usb/core/message.c: USB device number 2 default language ID 0x9 usb 1-1: Product: USB test usb 1-1: Manufacturer: Jalla jalla & co drivers/usb/core/usb.c: usb_hotplug usb 1-1: registering 1-1:1.0 (config #1, interface 0) drivers/usb/core/usb.c: usb_hotplug hid 1-1:1.0: usb_probe_interface hid 1-1:1.0: usb_probe_interface - got id drivers/usb/input/hid-core.c: ctrl urb status -32 received devfs_mk_cdev: could not append to parent for input/event2 input: USB HID v1.11 Mouse [Jalla jalla & co USB test] on usb-0000:00:07.2-1 usbfs: process 3558 (lsusb) did not claim interface 0 before use usbfs: process 3560 (lsusb) did not claim interface 0 before use usb 1-1: usb_disable_device nuking non-ep0 URBs uhci_hcd 0000:00:07.2: shutdown urb d443f980 pipe 40408280 ep1in-intr usb 1-1: unregistering interface 1-1:1.0 usb 1-1: hcd_unlink_urb d443f980 fail -16 usb 1-1: hcd_unlink_urb d443fd40 fail -22 usb 1-1: hcd_unlink_urb d443f980 fail -16 drivers/usb/core/usb.c: usb_hotplug Unable to handle kernel NULL pointer dereference at virtual address 00000004 printing eip: c03db6c1 *pde = 00000000 Oops: 0000 [#1] CPU: 0 EIP: 0060:[<c03db6c1>] Not tainted EFLAGS: 00010246 EIP is at findintfif+0x21/0x70 eax: d4a00c00 ebx: d443f440 ecx: fffffff2 edx: 00000000 esi: 00000000 edi: 00000000 ebp: bffff8a4 esp: d39dff00 ds: 007b es: 007b ss: 0068 Process a (pid: 3562, threadinfo=d39de000 task=d3b84d20) Stack: d443f440 8004550f d443f448 bffff8a4 c03dd326 d4a00c00 00000000 d443f440 c03ddbca d443f440 bffff8a4 ffffffe7 d41e55e0 d6888000 c032d781 d39dff5c d41e55e0 40015000 00000018 00000018 00000018 40015018 c0333370 3fdedc43 Call Trace: [<c03dd326>] proc_claiminterface+0x36/0x50 [<c03ddbca>] usbdev_ioctl+0x39a/0x3a0 [<c032d781>] tty_write+0x1b1/0x2d0 [<c0333370>] write_chan+0x0/0x250 [<c016bd85>] file_ioctl+0x75/0x200 [<c016c028>] sys_ioctl+0x118/0x2b0 [<c010b57b>] syscall_call+0x7/0xb Code: 80 7a 04 00 89 d5 74 31 8b 44 b2 0c 31 c9 8b 58 08 39 d9 73
Bus 001 Device 002: ID 04d8:0001 Microchip Technology, Inc. Language IDs: none (invalid length string descriptor bf; len=0) string descriptor 1 invalid (bf bf; len=0) string descriptor 2 invalid (bf bf; len=0) Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.10 bDeviceClass 0 Interface bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 8 idVendor 0x04d8 Microchip Technology, Inc. idProduct 0x0001 bcdDevice 0.00 iManufacturer 1 iProduct 2 iSerial 0 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 34 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xa0 Remote Wakeup MaxPower 100mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 3 Human Interface Devices bInterfaceSubClass 0 No Subclass bInterfaceProtocol 0 None iInterface 0 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.11 bCountryCode 0 bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 50 cannot get report descriptor Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type none wMaxPacketSize 4 bInterval 10 Language IDs: none (invalid length string descriptor bf; len=0) Bus 001 Device 001: ID 0000:0000 Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.10 bDeviceClass 9 Hub bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 8 idVendor 0x0000 idProduct 0x0000 bcdDevice 2.06 iManufacturer 3 Linux 2.6.0-test11 uhci_hcd iProduct 2 UHCI Host Controller iSerial 1 0000:00:07.2 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 25 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0x40 Self Powered MaxPower 0mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 9 Hub bInterfaceSubClass 0 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type none wMaxPacketSize 2 bInterval 255 Language IDs: (length=4) 0409 English(US)