cancel
Showing results for 
Search instead for 
Did you mean: 

USB on STm32F411RE

quentin23
Associate II
Posted on April 07, 2016 at 11:07

Hi,

I'm trying to handle a printer via USB with my 

http://www.st.com/web/en/catalog/tools/PF260320

 but I'm facing a problem. Indeed, when my board send the first request for the enumeration, it goes in a waiting time forever :

phost -> gState                = HOST_ENUMERATION

phost -> EnumState        = ENUM_IDLE

phost -> RequestState     = CMD_WAIT

and

phost -> Control -> state = CTRL_SETUP_WAIT

When I check the DP and DM line, there are indeed communication between my printer and the board but I don't know what the message means.

For the Hardware, I have 

http://i.imgur.com/7EWn2w6.png?1

 (sorry but there is a bug when I try  to put a picture or a code block...). The LP2980-5 is a linear regulator supplied with 10V.

For the Code, I'm inspired by a MSC_HOST application from STM324xG_Eval. Here the main part of usb_conf.c (I attach the complete file just in case):

void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)

{

    GPIO_InitTypeDef  GPIO_InitStruct;

  

/* Configure USB FS GPIOs */

__HAL_RCC_GPIOA_CLK_ENABLE();

//__HAL_RCC_GPIOH_CLK_ENABLE();

GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 

GPIO_InitStruct.Pin = GPIO_PIN_6;

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 

/* Enable USB FS Clocks */ 

__HAL_RCC_USB_OTG_FS_CLK_ENABLE();

/* Set USBFS Interrupt to the lowest priority */

HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0);

/* Enable USBFS Interrupt */

HAL_NVIC_EnableIRQ(OTG_FS_IRQn);

}

USBH_StatusTypeDef USBH_LL_Init(USBH_HandleTypeDef *phost)

{  

  /* Set the LL driver parameters */

  hhcd.Instance = USB_OTG_FS;

  hhcd.Init.Host_channels = 11; 

  hhcd.Init.dma_enable = 0;

  hhcd.Init.low_power_enable = 0;

  hhcd.Init.phy_itface = HCD_PHY_EMBEDDED; 

  hhcd.Init.Sof_enable = 0;

  hhcd.Init.speed = HCD_SPEED_FULL;

  /* 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;

}

USBH_StatusTypeDef USBH_LL_DriverVBUS(USBH_HandleTypeDef *phost, uint8_t state)

{

    if(state == 0)

   {

        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET);

    }

    else

   {

        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET);

    }

   

    HAL_Delay(200);

     return USBH_OK;  

}

Except for the Vbus pin, I didn't change much. I although tried to use the mass storage class with a usb stick to be sur the problem didn't come from my printer class. It didn't change anything as expected.

Has anyone succeed to use this board as USB host ? 

For the others, is there a obvious problem that I don't get ?

Thank you.

#msc #usb #host
2 REPLIES 2
tsuneo
Senior
Posted on April 07, 2016 at 21:02

Hi hivert,

On your schematic, the connection of D+/D- lines is swapped.

The right connection is,

PA11 -- D- (DM)

PA12 -- D+ (DP)

> Has anyone succeed to use this board as USB host ?

I tested CubeMX MSC (Mass-Storage Class) host on NUCLEO-F411RE board. Generated code worked for a USB stick without any change, at least on these steps.

enumeration and initial MSC setup

- GetMaxLUN

- INQUIRY

- TEST UNIT READYY

- READ CAPACITY 10

(observed on a hardware bus analyzer)

CubeMX: 4.0

STM32Cube_FW_F4_V1.0

I attached CubeMX setting file (zip) to this post.

As of the hardware connection,

1) clock source - MCO from ST-Link

My NUCLEO-F411RE (MB1136 C-02 revision) has default MCO connection from on-board ST-Link. If your board would be C-01 revision, solder the jumpers, following to section ''5.6.1 OSC clock supply'' of the NUCLEO64 manual (

http://www2.st.com/content/ccc/resource/technical/document/user_manual/98/2e/fa/4b/e0/82/43/b7/DM001058pdf/files/DM001058pdf/jcr:content/translations/en.DM001058pdf

).

2) Connection to USB type-A connector

NUCLEO-F411RE type-A

PA12 CN10 pin12 -- D+

PA11 CN10 pin14 -- D-

+5V CN7 pin18 -- VBUS (5V)

GND CN10 pin 9 -- GND

Try this one as the start point of your project.

Tsuneo

________________

Attachments :

cubemx_nucleo_f411re_msc_host.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0bO&d=%2Fa%2F0X0000000bb0%2FtYhjRvfFODfmTrpTX8Go0nahX_0j0l8XKoX7vyGef_A&asPdf=false
quentin23
Associate II
Posted on April 08, 2016 at 15:48

Hi Tsuneo and thank you a lot for your help. Its works perfectly fine now and my printer is detected.

I'm not quite sure what was wrong before but nevermind.

PS : I see you are the one who have helped for printer class [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/USB%20printer%20class&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=1210]here so double-thanks for you.