Skip to main content
romybompart
Associate III
January 15, 2014
Question

USB OTG HS Host in Mode FS internal PHY and USB OTG FS Device

  • January 15, 2014
  • 11 replies
  • 6730 views
Posted on January 15, 2014 at 19:14

I�m trying to use the STM32F407 as Host and Device simultaneously, my hardware configuration is the following:

-PA12, PA11, PA9 OTG FS as a Device 

- PB14, PB15 OTG HS as a Host with Embedded PHY 

If I define the preprocessor symbols: 

USE_USB_OTG_HS and USE_USB_OTG_FS

The USB works ok as a Host, and the Device goes on and off, It seems that it is going to work but at the end the computer doesn't recognize it. 

Also, I have tested defining just the preprocessor macro USE_USB_OTG_FS, and in this case the USB works well as a Device. I believe that the library is only implemented to work in HS or FS Mode

So, this is my question, Does any body has implemented USB as a device and host simultaneously using separated peripheral ? I mean i want to use the HS as Host with no external PHY and the FS as a Device.

#stm32f4 #usb #usb #usb #usb #stm32f407 #otg #host #host
This topic has been closed for replies.

11 replies

chen
Associate II
January 16, 2014
Posted on January 16, 2014 at 12:38

Hi

''So, this is my question, Does any body has implemented USB as a device and host simultaneously using separated peripheral ?''

I do not think you can do this!

It is not possible (at least with the current USB specification) to have more than 1 host on the USB bus.

ie Why would you have the STM32 be a USB Host and a USB device at the same time?!?

It is common to have a Composite USB device - that is the STM32 behaves as multiple USB devices eg USB HID and USB CDC together at the same time.

The other alternative is called USB OTG - USB On The Go :

This allows a 'device' to switch between being a USB Host

(ie when the device is not connected to another host and a device is plugged into the STM32 USB)

and a USB device

(ie when the STM32 is plugged into a USB Host eg PC)

This is probably why you see :

''The USB works ok as a Host, and the Device goes on and off''

romybompart
Associate III
January 16, 2014
Posted on January 16, 2014 at 14:55

Thank you Chen_chung, 

      I would like connect for example: a keyboard or a mouse, and the same time send data to the computer when it is required.

      Due to your answer I have new Questions:  

        1.- Can I configure the USB as a Device by default work with this until a condition that makes desinitialize USB, and then Configure the USB as a HOST ?

         2.- How Can I implement the USB OTG with different port pins to be able to use Type-A and Type-B Connector at each port pits respectively ?

         3. How would you implement this application.

chen
Associate II
January 16, 2014
Posted on January 16, 2014 at 15:20

Hi

''I would like connect for example: a keyboard or a mouse, and the same time send data to the computer when it is required. ''

This is not possible. The STM32 can only be a Host or a Device - it cannot do be both at the same time.

To connect to a Keyboard or mouse it must be a Host.

To connect to a host computer it must be a Device.

''        1.- Can I configure the USB as a Device by default work with this until a condition that makes desinitialize USB, and then Configure the USB as a HOST ?''

Yes, that is what USB OTG is designed to do. However, it cannot be both at the same time, the STM32 must change over from being a device to host or visa vera.

''2.- How Can I implement the USB OTG with different port pins to be able to use Type-A and Type-B Connector at each port pits respectively ?''

No. The STM32 is only designed to have 1 USB port. This can be either a TypeA (normally for Host) or a TypeB (normally for device).

To connect the same port pins to both types of connector would be like connecting the USART port pins to 2x 9w D type - What do you think is going to happen when you connect 2 serial devices to the 1 port?

''3. How would you implement this application.''

What you ask is not possible - cannot be both Host and Device at the same time.

The only way to do it is to have 2 USB peripherals - one acting as a Host and one acting as target.

I do not think any of the STM32s range have 2 USB peripherals (but I have not really looked either)

From the sound of what you have done - you almost have the OTG part working.

You just have to make the switch between host/device work.

romybompart
Associate III
January 16, 2014
Posted on January 16, 2014 at 15:41

Ok Chen_Chung, 

      It is helpful. I will try to Implement the USB OTG. But You didn't answer my first question as I want, I mean, I probably can implement this hardware:

 

-PA12, PA11, PA9 OTG FS as a Device 

- PB14, PB15 OTG HS as a Host with Embedded PHY 

     So by software I can Switch between one to other, Initialising the DEVICE (in pins PA12, PA11, PA9) at the first time and then with some hardware/software condition I can turn it Off (Deinitialize it). When it is turned off I will be able to configure the HOST in the other pins. Is it possible? 

     I have read from the Reference Manual that the STM32F407 has two peripherals: USB OTG FS and USB OTG HS, so what I believe is the USB peripherals can work independently once at time. Do I misunderstand the reference manual?... 

Note: I have understood that I can't use both at the same time. 

chen
Associate II
January 16, 2014
Posted on January 16, 2014 at 16:18

Hi

'' I have read from the Reference Manual that the STM32F407 has two peripherals: USB OTG FS and USB OTG HS, so what I believe is the USB peripherals can work independently once at time. Do I misunderstand the reference manual?... ''

Errm - Yes.

Maybe you can then. I was under the impression that there is only 1 USB peripheral but looking at the block diagram - they are indeed 2 separate peripherals a Full speed and a High Speed.

I do not know?!?. I have not tried it.

romybompart
Associate III
January 16, 2014
Posted on January 16, 2014 at 16:32

Great Chen_Chung. 

     I will try to do it. Because It is appropriate to use a type A connector and type B connector. 

     I will post my result. 

 Cheers. 

billr1
Explorer
January 19, 2014
Posted on January 19, 2014 at 18:05

Bompart.Romy, please keep us updated on your progress. I am wanting to do exactly the same thing - one of the USB ports as host for keyboard or mouse and the other USB port for CDC device to talk to a PC.

romybompart
Associate III
February 23, 2014
Posted on February 23, 2014 at 17:36

Hi Bill, 

    I did it.. I achieved mix USB OTG HS HOST and USB OTG FS DEVICE. It works Great... !!! 

brianvajda9
Visitor II
March 12, 2014
Posted on March 12, 2014 at 23:24

What did you do to get both a device and host working? I'm running into issues as well and any help would be appreciated.

anil2
Associate
March 13, 2014
Posted on March 13, 2014 at 14:11

Hi Bompart.Romy, 

Can you help us about using mix USB OTG HS HOST and USB OTG FS DEVICE with ST USB OTG library?

Steven Pearce
Associate
May 21, 2018
Posted on May 21, 2018 at 11:55

HI cakali.anil,

Was Bompart.Romy able to help you about using mix USB OTG HS HOST and USB OTG FS DEVICE with ST USB OTG library?

I have a similar task.