New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB host mode #212

Closed
dpgeorge opened this Issue Jan 23, 2014 · 17 comments

Comments

Projects
None yet
4 participants
@dpgeorge
Copy link
Contributor

dpgeorge commented Jan 23, 2014

Does anyone have any experience getting USB host mode working on the STM32F4 series? I've tried to no avail to get it working on the pyboard.

I'm forcing it to be in pure host mode, pretty much copying from the STM USB HID host example, but it does not work. Seems that it doesn't even register when a USB device is plugged in (it does not generate an interrupt).

Any thoughts?

@dhylands

This comment has been minimized.

Copy link
Contributor

dhylands commented Jan 23, 2014

I've not worked with the STM32's prior to this, but some things to look for (based on work I've done on other chips):

  • make sure that the right clocks are turned on. Most peripherals are dead without the clocks being enabled
  • make sure that the appropriate internal voltage regulators are enabled (if applicable)
  • make sure that the peripheral is enabled, and its possible that you may need to disable device mode.
  • check the pin mux. If host and device are logically different blocks then they may have different pin mux settings
  • double check requirements for pullup/down resistors on D+ and D- lines. I seem to recall that they're different for host versus device. I also seem to recall having MOSFET controlled resistors on our D+/D- lines, but that may have been for simulating unplugging the cable. Its been a few years, so I've forgotten a bunch of the details.
@dpgeorge

This comment has been minimized.

Copy link
Contributor Author

dpgeorge commented Jan 23, 2014

Thanks for the tips. Unfortunately still no luck:

  1. I enable the GPIOA (the port with the USB pins), OTG_FS and SYSCLK clocks.
  2. Voltage regs N/A.
  3. Peripheral is enabled when clocks turn on. It's forced to host mode (device mode is not compiled in).
  4. DP and DM are configured as "alternate function" pins so the OTG peripheral can use them.
  5. Pull up/down set-up N/A, done by the peripheral.

Note that it's exactly the same peripheral as is used in device mode, so the clocks and pins should be correct. I force host mode (I checked the relevant bit in the register is set for this), and disable SRP and HNP so it only needs DM and DP to work. The interrupt is enabled and functioning.

@dhylands

This comment has been minimized.

Copy link
Contributor

dhylands commented Jan 23, 2014

So then, it seems like the next thing to do is to look at some working code (either one of the examples provided by STM or something like this:
http://vedder.se/2012/12/stm32f4-discovery-usb-host-and-mp3-player/

I'm assuming that your board is wired up to provide power to the USB bus? I see that the discovery board uses a gpio to enable power to the usb connector. It looks like the pyboard just has a zero ohm resistor to populate?

@torwag

This comment has been minimized.

Copy link
Contributor

torwag commented Jan 23, 2014

Looking out wether you really get stable 5V after plug-in the device would
be my first shoot.
Make sure you really test under load. I had quite a few occasions where
LEDs of devices lighted up but the device itself was non-functional and not
recognized.
Did you test this with a powered USB hub in between?

On 23 January 2014 22:02, Dave Hylands notifications@github.com wrote:

So then, it seems like the next thing to do is to look at some working
code (either one of the examples provided by STM or something like this:
http://vedder.se/2012/12/stm32f4-discovery-usb-host-and-mp3-player/

I'm assuming that your board is wired up to provide power to the USB bus?
I see that the discovery board uses a gpio to enable power to the usb
connector. It looks like the pyboard just has a zero ohm resistor to
populate?


Reply to this email directly or view it on GitHubhttps://github.com//issues/212#issuecomment-33168111
.

@dpgeorge

This comment has been minimized.

Copy link
Contributor Author

dpgeorge commented Jan 23, 2014

Okay, I'll try next with that mp3 example with my discovery board...

I have a beefy 4700uF capacitor on the supply line to keep the 5V stable. That should be enough for a USB mouse or keyboard.

Didn't try with a powered USB hub.

@dhylands

This comment has been minimized.

Copy link
Contributor

dhylands commented Jan 23, 2014

I was able to build the USB/MP3 project from http://vedder.se/2012/12/stm32f4-discovery-usb-host-and-mp3-player/ and flash onto my discovery board, and get it to work with some of my thumb drives.

This 1Gb thumb drive worked
http://www.ebay.com/itm/5-Pcs-1GB-1G-USB-2-0-Flash-Memory-Drive-Thumb-Swivel-Fold-Design-Red-/130976880970?ssPageName=ADME:L:OC:CA:3160

This 16 Gb one also worked:
http://www.amazon.ca/gp/product/B007CEBVRI/ref=oh_details_o09_s00_i00?ie=UTF8&psc=1

An older 250 Mb flash drive which works fine under ubuntu did not work.

I also have a USB-to-SD card adapter in which I tried several sd cards, none of which worked.

@dpgeorge

This comment has been minimized.

Copy link
Contributor Author

dpgeorge commented Jan 23, 2014

I also have a USB-to-SD card adapter in which I tried several sd cards, none of which worked.

Does this mean it didn't try enumerating? Or it tried, but failed?

@dhylands

This comment has been minimized.

Copy link
Contributor

dhylands commented Jan 23, 2014

I also have a USB-to-SD card adapter in which I tried several sd cards, none of which worked.

Does this mean it didn't try enumerating? Or it tried, but failed?

I'm not sure. The red and green LEDs came on but the red & orange ones don't flash and no audio was produced.

Looking at the code in usbh_usr.c I think that
GPIO 14 (Red) means USBH_USR_DeviceAttached was called
GPIO 12 (Green) means USBH_USR_MSC_Application was called (which seems to imply the enumeration was done, and the card was mounted).

I just know that I had some mp3s on the sdcard and they didn't start playing. The same sd card in a different USB-to-SD card adapter worked fine.

The USB-to-SD card adapter that worked was a simple one like this: http://www.kingston.com/us/flash/readers#fcr-mrg2

With my old thumb drive, only the Red LED comes on.

The USB-SD card adapter that didn't work has 2 slots, one for SD and one for microsd. Mine was like this one: http://www.kingston.com/us/flash/readers#fcr-mlg3 (but the older G2 version)

@dpgeorge

This comment has been minimized.

Copy link
Contributor Author

dpgeorge commented Jan 23, 2014

Right, well, I'm not even getting to the USBH_USR_DeviceAttached stage (on the pyboard)....

@dhylands

This comment has been minimized.

Copy link
Contributor

dhylands commented Jan 24, 2014

And for what its worth, I also tested one of my working thumb drives both with an OTG to A cable (the cable ties the ID pin to ground). I measured PA10 and got zero volts.

I also tried a regular USB to Micro-A cable and an A-to-A gender bender adpater and this also worked. For this scenario, the ID pin is left floating, and I measured PA10 at 2.93V. The USB_OTG_BSP_Init function sets up PA10 with a pullup, so that agrees.

@dpgeorge

This comment has been minimized.

Copy link
Contributor Author

dpgeorge commented Jan 25, 2014

Ok, I got the MP3 player code working on my STM32F4 discovery board. I converted it to recognise HID devices, and it works with a mouse and keyboard (enumerates and gets events). Then I got the same code running on the pyboard, and it works! So the pyboard can do USB host.

Now I just have to work out what's wrong with my original code. That should be easy :)

@dhylands

This comment has been minimized.

Copy link
Contributor

dhylands commented Jan 25, 2014

It's always comforting to find out its not a hardware problem :)

@dpgeorge

This comment has been minimized.

Copy link
Contributor Author

dpgeorge commented Jan 26, 2014

Now working! I can use a USB keyboard plugged into the pyboard to type in Python commands (using an LCD screen to see the output).

Bug was a constant I changed in the STM USB libraries (USB_OTG_MAX_TX_FIFOS) in order to reduce RAM usage of the USB driver. This change works for device mode but not for host mode.

@dpgeorge dpgeorge closed this Jan 26, 2014

@dhylands

This comment has been minimized.

Copy link
Contributor

dhylands commented Jan 26, 2014

Sweet!

@torwag

This comment has been minimized.

Copy link
Contributor

torwag commented Jan 26, 2014

congrats !!! We should establish a donor-for-bug-fix system. One pint of
beer for each nasty bug ;)

On 26 January 2014 18:51, Damien George notifications@github.com wrote:

Closed #212 #212.


Reply to this email directly or view it on GitHubhttps://github.com//issues/212
.

@jobbyworld

This comment has been minimized.

Copy link

jobbyworld commented Sep 7, 2016

Hello, does the usb host mode can ne use on pyboad with Python
Which pins should be used ?
Many Thanks

@dpgeorge

This comment has been minimized.

Copy link
Contributor Author

dpgeorge commented Sep 8, 2016

Hello, does the usb host mode can ne use on pyboad with Python

No, it's not yet fully supported by the software (only in an experimental build).

tannewt added a commit to tannewt/circuitpython that referenced this issue Aug 31, 2017

Update README (micropython#212)
* Add README navigation and minor edits
* Simplify links
* Clean up markdown style warnings
* Update links
* Edit grammar and style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment