cancel
Showing results for 
Search instead for 
Did you mean: 

Configure USB-OTG HS in FS Mode on STM32F407 host

vlr
Associate II
Posted on September 24, 2015 at 14:45

I�m trying to use the STM32F407 as Host, i use Olimex STM32-P407 eval, my hardware configuration is the following:

- PB14, PB15, PB13  (DM, DP, VBUS) OTG HS as a Host with Embedded PHY

I

'm trying to

initialize

the mini USB-

OTG HS

present

on OLIMEX and use FS Mode.

This is my

initialization

present on file ''usbh_conf.c'':

void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)

{

  GPIO_InitTypeDef  GPIO_InitStruct;

 

  if(hhcd->Instance == USB_OTG_HS)

  {

    /* Configure USB HS GPIOs */       

    __GPIOB_CLK_ENABLE();

    __GPIOC_CLK_ENABLE();    

   

    /* Configure DM DP Pins */

    GPIO_InitStruct.Pin = GPIO_PIN_14 | GPIO_PIN_15;             

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;   

    GPIO_InitStruct.Alternate = GPIO_AF12_OTG_HS_FS;

    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);   

    

    /* This for ID line debug */

    GPIO_InitStruct.Pin = GPIO_PIN_12;                               

    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS_FS;

    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    

    /* Configure Power Switch Vbus Pin */

    GPIO_InitStruct.Pin = GPIO_PIN_13;

    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;                                               

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    

    /* Enable USB HS Clocks */

    __USB_OTG_HS_CLK_ENABLE();

    

    HAL_NVIC_SetPriority(OTG_HS_IRQn, 0, 0);

   /* Enable USB HS Interrupt */

    HAL_NVIC_EnableIRQ(OTG_HS_IRQn);      

  }

}

The Power Switch configuration is:

USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, uint8_t state)

{

  if(state == 0)

  {

    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_SET);   

  }

  else

  {

    HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_RESET);   

  }

 

  HAL_Delay(200);

  return USBH_OK;  

}

The Initialization of the Low Level portion of the Host driver is:

USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost)

{

  /* Set the LL driver parameters */

  hhcd.Instance = USB_OTG_HS;       

  hhcd.Init.Host_channels = 11;

  hhcd.Init.dma_enable = 0;

  hhcd.Init.low_power_enable = ENABLE;    

  hhcd.Init.phy_itface = HCD_PHY_EMBEDDED;

  hhcd.Init.Sof_enable = 0;

  hhcd.Init.speed = HCD_SPEED_FULL;      

  hhcd.Init.vbus_sensing_enable = DISABLE;

  /* Link the driver to the stack */

  hhcd.pData = phost;

  phost->pData = &hhcd;

  /*Initialize the LL Driver */

  HAL_HCD_Init(&hhcd);

 

  USBH_LL_SetTimer(phost, HAL_HCD_GetCurrentFrame(&hhcd));

 

  return USBH_OK;

}

QUESTION

:

1) It's correct configuration? In this mode i see 5V on VBUS, but my phone don't charge when i connect it.

2)

Why

VBUS

is

configured

in this mode

(

GPIO_MODE_INPUT

)?

3) T

he

configuration

for the Power

switch

is correct?

4)

My goal

is that

by connecting the

phone to

OLIMEX

she

finds out that the

phone is connected and charge it

. H

ow can I

manage and

configure

the interrupt

?

Thanks for your help.

#vbus #stm32f4 #usb #otg #host #cell
1 REPLY 1
adam23
Associate II
Posted on September 25, 2015 at 11:14

Regarding the VBUS you have to check the board schemtics, but most probably the ''INPUT'' is not correct. The recommended setup for various VBUS supplied devices is to have the there extra HW to supply them as the GPIO port can not feed the current.

Also check the setup of VBUS defines in USB configuration.