cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 - Detection of USB Data Stick Plugged In

Rogers.Gary
Senior II
Posted on March 19, 2016 at 22:19

Hi:

On an STM32F405, I am using ports PA9 through PA12 connected through to a USB Mini B connector. The intention is to use the port so I can plug in a USB stick and transfer data to it.

To drive USB power, I have a STMPS2141STR switch. I don't want the switch to be enabled unless the USB stick is plugged in. I do not understand the USB interface mechanism that would allow this detection to happen so the STMPS2141STR switch should be enabled only when the USB has a stick installed.

Can someone please explain?

Thank you.

#usb #stm32f4 #host #host #usb #usb #power
8 REPLIES 8
re.wolff9
Senior
Posted on March 20, 2016 at 20:16

Detecting an USB device that is inserted works by seeing that the device pulls the USB-D+ line to 5V through a 1.5K resistor. 

With the power to the stick being ''off'', my guess is that the stick will not be able to pull the USB-D+ line high because it doesn't have an internal battery. (but I haven't opened all off them to be sure that none have an internal battery.... :) ) 

So the only way that I can think of is that you enable the power every second for a few miliseconds to see if something becomes active. 

Or you can enable the pullup of the pin and do an ADC conversion to see if something changes. 

On the other hand, just enabling the power with nothing connected is unlikely to cost you more than a few microamps with modern hardware. 

Posted on March 21, 2016 at 20:33

Or perhaps EXTI?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Rogers.Gary
Senior II
Posted on March 21, 2016 at 21:34

thanks for the responses guys.

clive1, does the ST USB library somewhere in the code do this already, or does it need to be set up by the user?

I'm asking because it seems odd that this feature would not be included (in a written library) for a device that is usually set up for lowest possible power consumption, or when switching on external device power.

Thanks,

Gary

Posted on March 22, 2016 at 11:01

It is not something I have dwelled upon.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
tsuneo
Senior
Posted on March 22, 2016 at 11:19

> On an STM32F405, I am using ports PA9 through PA12 connected through to a USB Mini B connector. The intention is to use the port so I can plug in a USB stick and transfer data to it.

You should have an adaptor, which connects the ''Mini B connector'' on board to your USB stick, mini-B plug <--> standard A receptacle. Is the ID pin wired to GND at the mini-B plug end of this adaptor?

As some Android phones/tablets wrongly mount micro-B receptacle for OTG, like Nexus 7, adaptors of microB plug <--> standard A receptacle are popular on the market. ''Working'' adaptors of this kind drop ID pin into GND at the microB plug. I'm not sure, if this theory would be applied to your adaptor, but it's feasible.

If the ID pin would be dropped in GND, plug-in of this adaptor to your STM32F board is detected at the ID port (PA10). When PA10 is assigned to OTG_FS_ID function, this port is internally pulled up.

OTG_FS_GINTSTS.CIDSCHG (USB_OTG_GINTSTS_CIDSCHG)

To detect the change on ID pin, you may poll on (or assign interrupt to) this bit.

To clear this bit, write 1 to the CIDSCHG bit (rc_w1).

OTG_FS_GINTMSK.CIDSCHGM (USB_OTG_GINTMSK_CIDSCHGM)

The mask bit of above change bit.

OTG_FS_GOTGCTL.CIDSTS (USB_OTG_GOTGCTL_CIDSTS)

Current ID pin status is read from this bit.

While the ID port is kept in low, ie. while the adaptor is plugged in, enable VBUS power.

Tsuneo

Rogers.Gary
Senior II
Posted on March 22, 2016 at 17:58

hi,

thanks for the information. attached is a clip of the schematic's usb connection to the pcb mounted usb mini connector. the lower part shows the net pins at the controller. I used a Molex pcb connector that carries all signals to the 405 controller.

I want to use a mini b female pcb connector due to board size constraints. An adapter would be used to connect the mini-b to the usb stick.

If I understand correctly, does it mean that using the A to mini B adapter probably grounds the ID pin? If this is the case, it seems that power is only enabled once the adapter is plugged in, so the circuit I have should work. Does this agree with what I think you are saying?

Thanks!

________________

Attachments :

usb_cct.JPG : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0ne&d=%2Fa%2F0X0000000bdl%2FAyargFhsp3K0Zuitr7AgmnuvVqjSOnnxxnF8s__ApGE&asPdf=false
tsuneo
Senior
Posted on March 23, 2016 at 17:13

> If I understand correctly, does it mean that using the A to mini B adapter probably grounds the ID pin? If this is the case, it seems that power is only enabled once the adapter is plugged in, so the circuit I have should work. Does this agree with what I think you are saying?

That's right.

If your mini-B adapter wouldn't ground the ID pin, you could replace the board receptacle with micro-B. There are so many variations of micro-B ''OTG'' adapter products for Android on the market, (''OTG adapter'' = ID pin is grounded) For example,

http://www.amazon.com/Adapter-Samusung-Android-Windows-Function/dp/B00LN3LQKQ/ref=pd_vtph_147_tr_img_2?ie=UTF8&refRID=090TFM5EHV106YTQSRRT

http://www.amazon.com/Adapter-LDesign%C2%AE-Android-Smartphone-Samsung/dp/B015XA3W0G/ref=pd_sim_147_4?ie=UTF8&dpID=31V3Yrajw2L&dpSrc=sims&preST=_AC_UL160_SR123%2c160_&refRID=0DJSSDQTR9SY8DKQ8E2B

http://www.amazon.com/Degree-Angled-Adapter-Galaxy-Tablet/dp/B00M7X6XNG/ref=pd_sim_147_12?ie=UTF8&dpID=41sT%2BesOXHL&dpSrc=sims&preST=_AC_UL160_SR160%2c160_&refRID=1M443Y4ENXJ5KE1VFMVM

Tsuneo

Rogers.Gary
Senior II
Posted on March 29, 2016 at 05:27

great, thanks for taking the time to answer my questions and the insight into the USB interface, Tsuneo.