Need Help with vUSB for bulk in and out

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

I'm implementing a device compliant to the USBTMC Class ( Class 0xFE, Subclass 0x03, Protocol 0x00).

Processor is ATTINY861A.

I set up the vUSB firmware to have this configuration

 

Configuration Descriptor
 Number of interfaces: 1
 Configuration value: 0x1
 Attributes: Bus powered
 Max power: 50 mA

Interface Descriptor: 0, Alternate setting: 0
 Number of endpoints: 2
 Interface class: 0xfe - Application Specific Interface
 Interface subclass: 0x3 - Test and Measurement
 Interface protocol: 0x0 - Unknown
 Endpoint address 0x1, Input, Bulk, max packet size: 64 bytes
 Endpoint address 0x1, Output, Bulk, max packet size: 64 bytes

 

No problem working with the control 0 endpoint, but i am unable to use the bulk out or in endpoint.

According the firmware documentation for OUT transaction directed to an endpoint > 0 the driver should call 

an user function 

 

usbFunctionWriteOut(data, len);

 

I wrote this function as a test for lighting a led. Just to see if it work.

When i send bulk data to device on endpoint 1 the function is never called.

 

I browse around the web to see other firmware implementation examples but it seem that most examples are only using control 0 endpoint of

are HID based.   I need to be perfectly compliant to the USBTMC standard since the device has to interwork with LABVIEW 2015.

 

I need a simple tutorial (or a working example that is not HID based) that use bulk in and out communication on endpoint > 0.

Tnx for any help or suggestion.

Fabio.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know anything about the Attiny. I don't think it has USB hardware.  You seem to indicate you have implemented it in software, and at full speed too.  That amazes me.  If you have successfully gone through initialization so the host recognizes the device, you've got most of the work done.

 

Now you have to recognize when data has come in on the user data endpoint, and let the task that wants the data, to know about it.

 

There is a lot of example code that is not HID (or DFU), and uses other than endpoint 0.  I don't know about example code where the low level USB is not done in USB hardware.  I implemented USB on an Xmega that has USB hardware, and that was hard enough.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Steve,

 

The OP is using the well known V-USB software implementation https://www.obdev.at/products/vu...

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I don't know it, how can it be well known.  wink  I see one problem.  Fcapozzi mentions 64 byte data packets.  Your link says low speed.  I don't believe those go together.  If I understand correctly, low speed requires 8 byte packets.

Last Edited: Sun. May 8, 2016 - 12:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The other question I have is about an accurate clock speed.  The Xmega's internal RC osc. is more than accurate enough.  I'm guessing the Attiny would require an external clock.  On the other hand, my knowledge of the Attiny is non-existant.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Steve,

 

The V-USB website talks of the clock requirements thus...

 

 

I have successfully used the ATTiny85 with the 16.5 MHz internal RC oscillator in a few HID keyboard applications.

 

Cheers,

 

Ross

 

Ross McKenzie ValuSoft Melbourne Australia

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The vUSB firmare is a nice piece of code, and you can find info on developers web site googling for "vUSB"

It is a firmware only implementation and does not require any USB peripheral on board the MCU. 

 

The reason for me to use vUSB stack is to drill down the usb specification and study what is behind the 4 pin connettor we all use everyday.

Even if the vUSB stack has a sort of documentation and some tutorials available on the net it is not so easy to implement a device without knowing well the usb specification and the specific class specification you choose to use.

 

My project is a concept proof work. I want to made a device compliant to the USBTMC Class Standard and to have it recognised by National Instrument Labview 2015, that is provided with a VISA  instrument class driver to interact with external instrument like oscilloscopes, wave generators, dmm and other stuff.

 

Steve is right when he says that the low speed USB standard does not allow 64 bulk pipes, but most OS host usb implementation does not complaint about it so for experimenting purpose is ok.

My goal is to have the device recognised by Labview and just exchange few packets.  Looking to some vUSB examples around is easy implement a device working on control 0 endpoint.  In many case people use some tricks to attach a device to the host.   The trick is to make the device belonging to the HID well known class (mouse, keyboards ecc) then send to device vendor specific class messages that are passed to the function layer untouched.  In this way you can implement a bidirectional communication on the control endpoint. This behaviour require that you develop using the libusb0 library ad host application that implement the command and response you want to have.  I need instead to follow the control message specification of the USBTMC class and also the bulk in and out message specification of the class. 

 

About using the bulk endpoints i did not find yet a clear vUSB documentation so any help will be appreciated. 

If someone want to join my project and form a group to develop a usbtmc compliant device using vUSB i will be happy to share what i found. 

 

Cheers, Fabio.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Fabio,

Perhaps this might help: http://terminal28.blogspot.com/2... ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

madara_x64 wrote:

Hello Fabio,

Perhaps this might help: http://terminal28.blogspot.com/2... ?

 

Well, tnx for hint ... read the document but i did not found what i am looking for.  I already set up a device that use control 0 and two Interrupt Endpoint (IN and OUT) and it works.  The max packet lenght has to be 8 byte max since internal rx buffer is sized this way (compliant to low speed device) and not 64 byte as i show on top of this message.

 

My problem is that if i change the Interrupt Endpoints  (Type 0x03) to be Bulk (0x02) [that is against low speed specification] the usbFunctionWriteOut is never called for Bulk OUT transaction and even if i prepare the data for Bulk IN request these data are never read. I explain this point better 

 

According firmware documentation basic mechanism to use Bulk/Interrupt Endpoint is :  

 

-  to implement the  usbFunctionWriteOut() that vUSB firmware calls when receiving a Bulk/Interrupt OUT transaction to pass the DATA packet. 

-  to check usbInterruptIsReady() to see if last pending IN endpoint data has been read by the Host and then use the usbSetInterrupt(buffer, len) to prepare the data

   to be sent for the next Bulk/Interrupt IN request.  We pass to this function a pointer to the buffer holding the data to be sent and the trasfer lentgh (len) that has to be from 0 to 8 byte max.

 

I tested that mechanism works perfectly when the endpoint is declared Interrupt (type 0x03) but does not work when endpoint is declared Bulk (0x02).  

The question at this point is Why !!, i am searching for an answer. 

 

Tnx, Fabio.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Fabio,

My bad - I thought perhaps usbFunctionWriteOut() wasn't being called at all (even in Interrupt mode), and that the solution would apply to this case as well (implement usbFunctionWrite() instead). However, if you cannot send IN reports and cannot receive OUT reports, I have no idea what the problem could be. Although, you did mention that bulk endpoints for low-speed devices were against the specification, as supported by the information on this page: https://msdn.microsoft.com/en-us...(v=vs.85).aspx

Microsoft do tend to be a bit pedantic about stuff, so its possible that if you're running on Windows things might not work as expected. Just in case you haven't already, you could try running this device with a Linux host and seeing how that goes.

I hope you figure this out soon.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Hi, i made some tests that shows that the is Operative system that complaints about the bulk pipes.  I explain better .. As i told before i was developing a device that should be compliant to USBTMC Class 

So i implemented a part of the usbtmc protocol. The communication between host and the instrument use bulk IN and OUT endpoints. There are specific messages sent in the Bulk OUT composed of an header and data.

The instrument prepare a response to each Bulk Out query using the Bulk IN endpoint building an header and the response data to be sent. As an example one of these messages the host send is the "request_dev_dep_msg_in" that transmit hex values in the bulk out   02 05 fa 00 f1 07 00 00 00 0a 00 00

When this message is decoded i programmed the device to answer with  02 05 fa 00 14 00 00 00 01 00 00 00 57 61 76 65 46 6f 72 6d 20 47 65 6e 65 72 61 74 6f 72 20 0a

After 12 byte header you can read "Waveform Generator"

Well, if i have the device configured with two interrupt endpoint and injecting the query using usbtool the response come back perfectly.  I can follow with Wireshark the URB Out message and IN messages

If i change only the endpoint type in bulk (0x02) in the working firmware, I found that usbtool on Windows 7 (and also Windows 10) does not send any URB Out message to device  and the query time out after 5 seconds.

Linux system has the usbtmc kernel module built in so when attaching the usb device to the bus it register a new usbtmc0 interface. The system change the bulk endpoint in interrupts automatically, but the kernel module when attempting to send bulk out data check for endpoint type and being interrupt generate a system error (Cannot write) 

So the possibility to use bulk endpoint on low device depends on the operative system. However i also found that using the bulk endpoint configured on device usbtool report an error saying that is unable to select configuration and claim the interface. 

My experiments show that using bulk out and in endpoint does not work on low device, and this is perfectly compliant to specification. The problem is that in the vUSB documentation seems that bulk can be used, but i did not figured out yet how to do. May be there is some trick or workaround i am not aware ... i hope. 

Sorry for message length, hope this can be usefull for others.  Fabio.

 

 

 

 

 

 

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Fabio,

Good to see that you've figured it out. Maybe the V-USB guys might be able to give some insight on it.

Thanks for the updates, and good luck!