using microcontroller to manage USB host enumeration

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
pendragon_01
 
Posts: 27
Joined: Fri Jul 04, 2014 12:15 pm

using microcontroller to manage USB host enumeration

Post by pendragon_01 »

I have several tinkering project going. one is using a smartphone in usb otg host mode to power a custom built peripheral. I know the phone will only supply 100mA typically, but this peripheral requires 500mA. To get more that 100mA via usb there is a process of enumeration and negotiation that has to take place between the device and the peripheral. however in this case the peripheral that i am connecting is a "dumb" component and cannot communicate with the phone. I was thinking of integrating trinket or teensy or any other microcontroller from adafruit into the peripheral solely to manage the usb handshake. Is this a function that microcontrollers can perform?

Thanks!
pendy

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: using microcontroller to manage USB host enumeration

Post by Franklin97355 »

To get more that 100mA via usb there is a process of enumeration and negotiation
It all depends on what this entails

pendragon_01
 
Posts: 27
Joined: Fri Jul 04, 2014 12:15 pm

Re: using microcontroller to manage USB host enumeration

Post by pendragon_01 »

USB enumeration is the process of detecting, identifying and loading drivers for a USB device.
Once the USB host (smartphone in this case) has established a USB device is connected, and at what speed it should communicate, then the host will attempt to read the USB device's descriptors to identify the USB device and its connectivity, configuration and interface needs.
This process basically follows a question and answer process. The USB host will send a Get_Device_Descriptor command and then the USB device responds with a data packet. This back and forth occurs until the USB host has fully identified the USB device, loads the appropriate driver and then the two devices live happily ever after.

Since my USB device is dumb and can't communicate, i was thinking that a microcontroller could act as its proxy, handle the enumeration process on its behalf and facilitate the connection.

Does that sound doable?

pendy

User avatar
cstratton
 
Posts: 294
Joined: Wed Sep 29, 2010 3:52 pm

Re: using microcontroller to manage USB host enumeration

Post by cstratton »

Yes, it is a function a microcontroller with a typical device-side USB interface can perform.

If the smartphone will grant the request is an entirely different question. Realistically, most PC/hub hosts have the same power limit regardless if you ask for more or not - they simply use PTC resettable fuses. A smartphone with a charge pump to generate VBus from a 3.7-4.2v battery may have harder limits.

pendragon_01
 
Posts: 27
Joined: Fri Jul 04, 2014 12:15 pm

Re: using microcontroller to manage USB host enumeration

Post by pendragon_01 »

Thanks for the info. Does any of adafruit's boards have baked in USB OTG Host controller functionality?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: using microcontroller to manage USB host enumeration

Post by adafruit_support_mike »

Nope. The ATmega32u4 chip has built-in USB support, but only as a client. It won't work as a host.

pendragon_01
 
Posts: 27
Joined: Fri Jul 04, 2014 12:15 pm

Re: using microcontroller to manage USB host enumeration

Post by pendragon_01 »

So if i integrated trinket or teensy (purely in a client role) into my custom built peripheral to give it the ability to communicate with the host, the Android device, then my custom peripheral,now augmented by the usb compliant mcu, should be able to perform this enumeration process correct?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: using microcontroller to manage USB host enumeration

Post by adafruit_support_mike »

A Trinket won't work. It uses the ATtiny85 microcontroller, which doesn't have built-in USB capacity. Our bootloader pretends to be a USB device long enough to load a new program, but that isn't the same as having full USB support.

The Teensy 2.0 uses an ATmega32u4, so it can enumerate as a USB client.

pendragon_01
 
Posts: 27
Joined: Fri Jul 04, 2014 12:15 pm

Re: using microcontroller to manage USB host enumeration

Post by pendragon_01 »

excellent. i really appreciate the assist!

pendragon_01
 
Posts: 27
Joined: Fri Jul 04, 2014 12:15 pm

Re: using microcontroller to manage USB host enumeration

Post by pendragon_01 »

Hey there
What is the significance of the digital I/O specs of the teensy board - 25, 5v specifically?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: using microcontroller to manage USB host enumeration

Post by adafruit_support_mike »

I'm not sure what you mean by "significance" in this context.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: using microcontroller to manage USB host enumeration

Post by paulstoffregen »

We had a very similar, perhaps duplicate, thread over on the PJRC forum.

I wrote a detailed answer about how to modify the Teensy core library for this application.

http://forum.pjrc.com/threads/26350-tee ... #post52397

In case this isn't a duplicate, hopefully that will help. If it is a duplicate thread, at least anyone finding it here can follow this link to how to edit the source code. (if this thread was also duplicated on even more forums, I'd appreciate if the original author could take a moment to repost the answer or a link to the answer everywhere else this question was asked)

pendragon_01
 
Posts: 27
Joined: Fri Jul 04, 2014 12:15 pm

Re: using microcontroller to manage USB host enumeration

Post by pendragon_01 »

@paul - hey! thanks for posting over here. feel free to chime in on the question.
adafruit_support_mike wrote:I'm not sure what you mean by "significance" in this context.
@adafruit support mike - i was hoping for simple layperson explanation of the digital i/o figures (25, 5v) for teensy and what they mean for project implementation.

thanks.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: using microcontroller to manage USB host enumeration

Post by paulstoffregen »

I'm afraid you're going to have to make the small step from "simple layperson" to "novice with Arduino" to truly understand pretty much any explanation. There are many excellent books and numerous online tutorial. Many are here on Adafruit's site. Here's one specific to Teensy.

http://www.pjrc.com/teensy/tutorial.html

Regarding your original question, you can see in tutorial #2 (RGB LED) how 3 of the pins are used to control the color of the LED. In tutorial #3, two more pins are used to connect pushbuttons. That's 5 of the 25 total pins.

As you build projects with Teensy, or any Arduino compatible board, the pins get used up as you connect stuff to the board. Almost all pins can be used as ordinary digital. Some pins have special functions like PWM, analog input, etc. Each thing you try to connect needs a certain number of pins, and sometimes some of the special feature only available on certain pins. Smaller (and usually less expensive) boards have fewer pins, and less pins with the special features, with limits how many things you can connect.

A board with more pins, and more of the special features on more pins, lets you build bigger projects, but (usually) the cost goes up. For example, a Trinket costs much less, but there's only 5 pins, so just that RGB LED and 2 buttons would use them all up. A Teensy 2.0 has 25 pins, which is much more, but still nowhere near the 54 digital + 16 analog you get with Arduino Mega.

User avatar
paulstoffregen
 
Posts: 444
Joined: Sun Oct 11, 2009 11:23 am

Re: using microcontroller to manage USB host enumeration

Post by paulstoffregen »

@pendragon_01 - Did you repost this same question to more forums? Really, that's ok with me. I've already gone to the trouble of writing 2 lengthy answers for you. If you did ask this elsewhere, could you at least follow up by reposting the answer or a link to the answer on the other forums?

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”