USB
  OpenSUSE 11.1 libhid-0-2.16 problem

Post New Topic  Post A Reply
profile | register | preferences | faq | search

UBBFriend: Email This Page to Someone! next newest topic | next oldest topic
Author Topic:   OpenSUSE 11.1 libhid-0-2.16 problem
hjsteger
New Member
posted July 19, 2010 06:00 PM     Click Here to See the Profile for hjsteger   Click Here to Email hjsteger     Edit/Delete Message
I've developed USB-to-I2C bridge firmware running on the C8051F340DK board. I based this firmware on the following examples; HIDtoUART example and the SMBus example. I removed the UART functionality from the HIDtoUART and replaced it with SMBus_Master firmware. In addition, using Microsoft Visual Studio 2008, I modified the host-side HIDtoUART code to support this application. Running on a Windows XP PC, the host application and firmware work reliably and have no noticeable problems. Ultimately though, this firmware needs to work with an HID interface on a Linux-based PC. With my initial attempts with Linux's HID interface, my results have been alot less reliable. For USB writes to the C8051 endpoint, there are no problems. But it seems that if I open the USB interface, read data from the C8051 endpoint, and then close the USB interface, this process works every other time. It seems as though either something doesn't close properly with the Linux HID interface or something doesn't initialize properly but so far these are only preliminary guesses as to what is going on. The version of Linux I am using is OpenSUSE 11.1. The HID interface is an open source libhid-0-2.16. Does anyone have any incite into this problem? Are there known differences that may be relevant to this problem between SLABHIDDEvice.dll running on Windows and libhid-0-2.16 for Linux?

IP: Logged

Tsuneo
Member
posted July 20, 2010 10:20 PM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
I don't fiddle libhid at all, but I heard it is based on libusb.
For libusb, HID device should be detached from the default hiddev driver, using usb_detach_kernel_driver_np()

In this post on Microchip forum, xiaofan shows libusb code for HID which works successfully.
http://www.microchip.com/forums/tm.aspx?m=340898

Tsuneo

IP: Logged

Tsuneo
Member
posted July 21, 2010 07:11 AM     Click Here to See the Profile for Tsuneo   Click Here to Email Tsuneo     Edit/Delete Message
It may be a problem of the data toggle initialization at Set_Configuration and Set_Interface handler.
SiLabs USB examples don't initialize data toggle at Set_Configuration and Set_Interface handler. Data toggle is reset just at bus reset.

This problem doesn't reveal on the most of drivers on Windows and MacOS X.
- These drivers put Set_Configuration just once after bus reset.
- These drivers don't put Set_Interface, unless target interface have any alternate.

But libusb code (both on Linux and Win32) may put Set_Configuration twice or more, without preceding bus reset. Also, libusb code may put Set_Interface at any time.

Here is a fix of Set_Configuration handler.

C:\SiLabs\MCU\Examples\C8051F34x\USB_HID\HIDtoUARTExample\F3xx_USB0_Standard_Requests.c


void Set_Configuration (void) // This routine allows host to change
{ // current device configuration value

// Device must be addressed before configured
if ((USB0_STATE == DEV_DEFAULT) ||
// and request recipient must be the device
(SETUP.bmRequestType != IN_DEVICE) ||
// the index and length words must be zero
SETUP.wIndex.c[MSB] || SETUP.wIndex.c[LSB]||
SETUP.wLength.c[MSB] || SETUP.wLength.c[LSB] ||
SETUP.wValue.c[MSB] || (SETUP.wValue.c[LSB] > 1))
// This software only supports config = 0,1
{
Force_Stall (); // Send stall if SETUP data is invalid
}

else
{
if (SETUP.wValue.c[LSB] > 0) // Any positive configuration request
{ // results in configuration being set
// to 1
USB0_STATE = DEV_CONFIGURED;
EP_STATUS[1] = EP_IDLE; // Set endpoint status to idle (enabled)

POLL_WRITE_BYTE (INDEX, 2); // Change index to endpoint 1
// Set DIRSEL to indicate endpoint 1 is IN/OUT
POLL_WRITE_BYTE (EINCSR2, rbInSPLIT);
POLL_WRITE_BYTE (EINCSR1, rbInCLRDT | rbInFLUSH); // clear data toggle and flush FIFO<------------ add this line

// Enable double buffering on out endpoint
POLL_WRITE_BYTE (EOUTCSR2, rbOutDBOEN);

POLL_WRITE_BYTE (EOUTCSR1, rbOutCLRDT | rbOutFLUSH); // clear data toggle and flush FIFO <------------ add these lines
{ // clear double buffer
BYTE eoutcsrl;
do { // wait until FLUSH complete
POLL_READ_BYTE( EOUTCSR1, eoutcsrl );
} while ( eoutcsrl & rbOutFLUSH );
POLL_WRITE_BYTE( EOUTCSR1, rbOutFLUSH ); // clear double buffer
}

POLL_WRITE_BYTE (INDEX, 0); // Set index back to endpoint 0

Handle_In2();
}


As of Set_Interface,
HID interface doesn't have any alternate interface. Then, the firmware can reject this request at all.

C:\SiLabs\MCU\Examples\C8051F34x\USB_HID\HIDtoUARTExample\F3xx_USB0_Standard_Requests.c


void Set_Interface (void)
{
Force_Stall ();

/*
// Make sure request is directed at interface
if ((SETUP.bmRequestType != IN_INTERFACE) ||
// and all other packet values are set to zero
SETUP.wLength.c[MSB] ||SETUP.wLength.c[LSB]||
SETUP.wValue.c[MSB] ||SETUP.wValue.c[LSB] ||
SETUP.wIndex.c[MSB] ||SETUP.wIndex.c[LSB])
{
Force_Stall (); // Othewise send a stall to host
}
if (EP_STATUS[0] != EP_STALL)
{
POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND));
// Indicate SETUP packet has been
// serviced
}
*/
}

Tsuneo

[Revised]
July 30, 2010
Added data toggle clear for OUT endpoint, too, on Set_Configuration handler
Added FIFO flush to IN and OUT endpoints on Set_Configuration handler

[This message has been edited by Tsuneo (edited July 30, 2010).]

IP: Logged

hjsteger
New Member
posted July 23, 2010 01:05 PM     Click Here to See the Profile for hjsteger   Click Here to Email hjsteger     Edit/Delete Message
Thanks for this information.

I added these changes to the Set Configuration and Set Interface routines but they didn't fix the problem I am seeing.

I am going to use a USB Bus Analyzer and compare traces that I get using Windows and those when using Linux. Hopefully, I will see something significantly different between the two that will help pinpoint this problem.

IP: Logged

hjsteger
New Member
posted July 27, 2010 01:19 PM     Click Here to See the Profile for hjsteger   Click Here to Email hjsteger     Edit/Delete Message
Using a USB bus analyzer, I was able to capture Data Toggle errors that are atleast one cause for the problems with this USB-to-IIC Bridge using a Linux-based host. I have a screenshot of the analyzer trace but I don't see a way that I can attach a file to this posting. Is there a place where I can post this file?

IP: Logged

hjsteger
New Member
posted July 27, 2010 05:32 PM     Click Here to See the Profile for hjsteger   Click Here to Email hjsteger     Edit/Delete Message
I looked more carefully at the analyzer trace and found something strange. There's an OUT DATA0 transaction that the target ACKs followed by an IN DATA0 transaction. Under what conditions would a target successfully receive the data of an OUT packet but not transition its toggle bit? Doesn't the fact that the target ACKs the OUT DATA0 packet mean that the target received the data successfully? Shouldn't the target transition its toggle bit at this point?

IP: Logged

hjsteger
New Member
posted July 27, 2010 07:37 PM     Click Here to See the Profile for hjsteger   Click Here to Email hjsteger     Edit/Delete Message
Never mind that last posting - that was a newbie error. I figured out that each endpoint has its own toggle bit. The IN and the OUT toggle bits are separate.

My mistake!

IP: Logged

hjsteger
New Member
posted July 28, 2010 12:43 PM     Click Here to See the Profile for hjsteger   Click Here to Email hjsteger     Edit/Delete Message
Regarding the fix added to Set_Configuration, it seems that Set_Configuration is only called when the OS first recognizes the USB device. Is there a specific command supported by Linux's libhid that will call Set_Configuration?

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | MCU User Forum

Have you seen our MCU Knowledge Base?


Ultimate Bulletin Board 5.47b