From owner-freebsd-usb@FreeBSD.ORG Wed Jul 4 17:33:11 2007 Return-Path: X-Original-To: freebsd-usb@freebsd.org Delivered-To: freebsd-usb@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id A1B8C16A400 for ; Wed, 4 Jul 2007 17:33:11 +0000 (UTC) (envelope-from xiaofanc@gmail.com) Received: from nz-out-0506.google.com (nz-out-0506.google.com [64.233.162.224]) by mx1.freebsd.org (Postfix) with ESMTP id 5DDB513C44B for ; Wed, 4 Jul 2007 17:33:11 +0000 (UTC) (envelope-from xiaofanc@gmail.com) Received: by nz-out-0506.google.com with SMTP id l8so1375083nzf for ; Wed, 04 Jul 2007 10:33:10 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=fVMFvc9Pk3pr+ZLq8absOVle1+NeDYepizWb7E//wWjAGtpTmax80iXRmwistbKhx5y1MNDDYjxbXSN5M4A1deEKk8VeVa6BKK8LNTKbC7+vIjkdnMnuYg7Uug4InQH/F2BYv3+qjuh8cDnUCG55H/NJfwntM9hUQIc7vpnR11k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=sROGhp43OCBe//J6B8Fpxui0RevtUsSniojSlXVzry12cGpdDOXkvdO2uJam3HWXwZ5n3fZtHxBxmgcKIrZIxOftQNl6kjYpYZPehIqjwR1DMP/ulhFVO9YsbzQLaUvp8IzTDvPUUaAQ55M9s0zatFSUhk6woexhMdJlKvai+ug= Received: by 10.114.173.15 with SMTP id v15mr7385287wae.1183568753659; Wed, 04 Jul 2007 10:05:53 -0700 (PDT) Received: by 10.114.176.17 with HTTP; Wed, 4 Jul 2007 10:05:53 -0700 (PDT) Message-ID: Date: Wed, 4 Jul 2007 13:05:53 -0400 From: "Xiaofan Chen" To: "Hans Petter Selasky" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200704031642.26519.hselasky@c2i.net> <200704040937.02219.hselasky@c2i.net> Cc: freebsd-usb@freebsd.org Subject: Re: libusb usb_interrupt_read hangs under FreeBSD X-BeenThere: freebsd-usb@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: FreeBSD support for USB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2007 17:33:11 -0000 > On 4/4/07, Hans Petter Selasky wrote: > > On Wednesday 04 April 2007 01:55, Xiaofan Chen wrote: > > > On 4/3/07, Hans Petter Selasky wrote: > > > > Hi, > > > > > > > > I think that your device is broken, and goes bad when it receives a > > > > clear-stall request for the interrupt pipe. That is not very uncommon. > > > > > > Could you be more clearer? I'd like to communicate this problem > > > to the firmware developer of PICKit 2 inside Microchip. Thanks. > > > > The chip does not handle a clear-stall request on the control pipe to > > clear-stall on the interrupt pipe. The result is that the interrupt pipe > > stops, or at least all buffers are cleared. > > > > I could be more detailed, but I think the developers will understand what I > > mean. > > Sorry to dig out this again. I read a bit more on the firmware source code and I found the following. Seems a bit dubious. The USB controller used is Microchip 18F2550. Any comments? Thanks in advance. /****************************************************************************** * Function: void USBStallHandler(void) * * PreCondition: A STALL packet is sent to the host by the SIE. * * Input: None * * Output: None * * Side Effects: None * * Overview: The STALLIF is set anytime the SIE sends out a STALL * packet regardless of which endpoint causes it. * A Setup transaction overrides the STALL function. A stalled * endpoint stops stalling once it receives a setup packet. * In this case, the SIE will accepts the Setup packet and * set the TRNIF flag to notify the firmware. STALL function * for that particular endpoint pipe will be automatically * disabled (direction specific). * * There are a few reasons for an endpoint to be stalled. * 1. When a non-supported USB request is received. * Example: GET_DESCRIPTOR(DEVICE_QUALIFIER) * 2. When an endpoint is currently halted. * 3. When the device class specifies that an endpoint must * stall in response to a specific event. * Example: Mass Storage Device Class * If the CBW is not valid, the device shall * STALL the Bulk-In pipe. * See USB Mass Storage Class Bulk-only Transport * Specification for more details. * * Note: UEPn.EPSTALL can be scanned to see which endpoint causes * the stall event. * If *****************************************************************************/ void USBStallHandler(void) { /* * Does not really have to do anything here, * even for the control endpoint. * All BDs of Endpoint 0 are owned by SIE right now, * but once a Setup Transaction is received, the ownership * for EP0_OUT will be returned to CPU. * When the Setup Transaction is serviced, the ownership * for EP0_IN will then be forced back to CPU by firmware. * * NOTE: Above description is not quite true at this point. * It seems the SIE never returns the UOWN bit to CPU, * and a TRNIF is never generated upon successful * reception of a SETUP transaction. * Firmware work-around is implemented below. */ if(UEP0bits.EPSTALL == 1) { USBPrepareForNextSetupTrf(); // Firmware Work-Around UEP0bits.EPSTALL = 0; } UIRbits.STALLIF = 0; }//end USBStallHandler /****************************************************************************** * Function: void USBPrepareForNextSetupTrf(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: The routine forces EP0 OUT to be ready for a new Setup * transaction, and forces EP0 IN to be owned by CPU. * * Note: None *****************************************************************************/ void USBPrepareForNextSetupTrf(void) { ctrl_trf_state = WAIT_SETUP; // See usbctrltrf.h ep0Bo.Cnt = EP0_BUFF_SIZE; // Defined in usbcfg.h ep0Bo.ADR = (byte*)&SetupPkt; ep0Bo.Stat._byte = _USIE|_DAT0|_DTSEN; // EP0 buff dsc init, see usbmmap.h ep0Bi.Stat._byte = _UCPU; // EP0 IN buffer initialization }//end USBPrepareForNextSetupTrf /** EOF usbctrltrf.c *********************************************************/