cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746G Usb host custom Baud rate settings.

MZuba.1
Associate II

Dev Environment.

STM32CubeIDE

Version: 1.1.0

Build: 4551_20191014-1140 (UTC)

OS: Linux, v.5.3.0-28-generic, x86_64 / gtk 3.22.30

Java version: 1.8.0_202

OS. Ubuntu 18.06

Problem description:

I am trying to communicate with a VCP usb device whose Baud rate is 9600 fixed.

I can send commands to it using Putty/noserial the device is working fine and accepting commands according to its protocols.

The main work I need to do is to Interface this device via STM discovery board.

After reading user manual and different tutorials I saw VCP host mode is suitable for me. In my case the project is compiling without error. when i start debugging, my device turn on from the board power but do not respond to the commands i send to it.

Appli_state never go to APPLICATION_READY state instead is stays on APPLICATION_START state.

Kindly tell me how to correct it.

It seems line codding has problem.

hUsbHostFS.device.Data[]; is empty when device is disconnected and it get USB name when device is connected. my conclusion is hardware side is working but software has some problem maybe in line code setting related to baud rate.

So in cubeMX I made a project with following parameters.

Middleware->FREERTOS->CMSIS_V1

Connectivity-> USB_OTG_FS mode Host Only.

Middleware-> USB_HOST->Communication Host Class(VCP)

Middleware-> USB_HOST->Platform Settings->Drive_VBUS_FS->GPIO:Output and found solution is PD5.

The default thread is.

void StartDefaultTask(void const * argument)

{

 /* init code for LWIP */

 MX_LWIP_Init();//will be using in next stage of work

 /* init code for USB_HOST */

 MX_USB_HOST_Init();

   usbConfig();//user function defined in usb_host.c library to set buad rate and other parameters

//////////////////////////////////

 /* Infinite loop */

 for(;;)

 {

   uint8_t cdcbuffer[]="User Command";

   uint8_t cdclen=strlen(cdcbuffer);

   usbWrite(cdcbuffer,cdclen);

   osDelay(1);

 }

 /* USER CODE END 5 */

}

in usb_host.c following functions are created.

void usbConfig(void)

{

   CDC_LineCodingTypeDef *NewCoding;

   USBH_CDC_GetLineCoding(&hUsbHostFS, &NewCoding);

   NewCoding->b.dwDTERate=9600;//setting baud to 9600

   NewCoding->b.bDataBits=8;//data bits=8

   NewCoding->b.bParityType=0;//parity none

   NewCoding->b.bCharFormat=0;//stop bits=1

   USBH_CDC_SetLineCoding(&hUsbHostFS, NewCoding);

    if (USBH_Start(&hUsbHostFS) != USBH_OK)

    {

      Error_Handler();

    }

}

void usbWrite(uint8_t * data,uint8_t size)

{

   if(Appli_state==APPLICATION_READY)

   {

      USBH_CDC_Transmit(&hUsbHostFS, data, size);

   }

}

2 REPLIES 2
MZuba.1
Associate II

The problem is not resolved.

AChho.1
Associate

@MZuba.1​ i also face same issue but i resolved now.

Problem 1(Appli_state never go to APPLICATION_READY): this happens because code generated by stm32MX is standard not device specific. you need to read your USB device datasheet and see what parameters of bmRequestType, bRequest, wValue, wIndex, wLength is needed. Every device usb have different values . and then set it to usbh_cdc.c(SetLineCoding and GetLineCoding) functions.