cancel
Showing results for 
Search instead for 
Did you mean: 

USB_virtual com port

silicon2
Associate II
Posted on June 16, 2010 at 09:23

USB_virtual com port

#virtual-com-port #seteptxvalid #usb
15 REPLIES 15
tsuneo
Senior
Posted on May 17, 2011 at 13:54

> I try to use usart1 with virtual com port. I try to set proper configuration.

When your PC application changes baudrate (or data bits, stop bits, etc.), the CDC PC class driver notifies the change to the CDC device using Set_Line_Coding request.

On the Virtual_COM_Port example of STM32_USB-FS-Device_Lib_V3.2.0,

the stack calls USART_Config() ( hw_config.c ) to set up the USART, from the Set_Line_Coding request handler. At the end of this function, it passes the parameters to COM1 using STM_EVAL_COMInit()

bool USART_Config(void)

{

  ...

  ...

  /* Configure and enable the USART */

  STM_EVAL_COMInit(COM1, &USART_InitStructure);

  return (TRUE);

}

The source code of STM_EVAL_COMInit() lies in Utilities\STM32_EVAL\stm32_eval.c

Trace the problem knowing this code flow.

> If I reset microcontroller(stm32f103). The bDeviceState == UNCONNECTED.

On your board, is the external D+ pull-up resistor controlled by a MCU port pin through a transistor?

This circuit cuts off the D+ pull-up on MCU reset. The host detects it and recognizes disconnection of USB. When the firmware enables the D+ pull-up again on the USB initialization, the host detects the connection of the board. And host starts enumeration. In the course of enumeration, bDeviceState returns to CONFIGURED, when Set_Configuration comes.

If the D+ pull-up is fixed without MCU control, this re-enumeration doesn't occur.

You'll see an example at the left-bottom of the second page of this schematic.

Schematic of Keil MCBSTM32 board

http://www.keil.com/mcbstm32/mcbstm32-schematics.pdf

On this schematic, R29 (1k5) is the D+ pull-up resistor. This resistor is controlled by transistors, which connects to PD2 port over J1 (Usually, Pch-MOSFET is applied, instead of these NPN transistors)

This board mounts USBLC6-2 for ESD protection. It's wrong choice.

This ESD protection chip is good for the downstream ports of hub, but not good for the device USB port. For device protection, a chip with diodes just on lower-sides (GND-D+ and GND-D-) is chosen, without high-sides (D+ - VBUS, D- - VBUS).

ST should line up this type of ESD protection other than USBLC6-2, too.

You'll see almost the same (unrefined) circuit on the ST eval board, too.

STM3210E-EVAL

http://www.st.com/stonline/products/literature/um/14220.pdf

Tsuneo

silicon2
Associate II
Posted on May 17, 2011 at 13:54

Hi,

I have another problem. I try to use usart1 with virtual com port. I try to set proper configuration. I think something change my settings,because if I use another program without USB  USART will work correct. I my program I get data from usart1 but I set 9600B 8NoneParity 1Stop. But I barley read data if I set my pc on 9600B 7NoneParity 1Stop.

I observe bDeviceState and if I plug USB device the bDeviceState will become CONFIGURED. If I reset microcontroller(stm32f103). The bDeviceState == UNCONNECTED. I try to use  Virtual_Com_Port_SetConfiguration and other functions from usb_prop.c but I can't succeed to get bDeviceState==CONFIGURED.

silicon2
Associate II
Posted on May 17, 2011 at 13:54

Hi,

bool USART_Config(void)

I try to comment STM_EVAL_COMInit() but no better results.

I try to find STM_EVAL_COMInit() in all files and comment. I try to write my configuration for USART1

   

    USART_InitStructure.USART_BaudRate = 9600;

    USART_InitStructure.USART_WordLength = USART_WordLength_8b;

    USART_InitStructure.USART_StopBits = USART_StopBits_1;

    USART_InitStructure.USART_Parity = USART_Parity_No;

    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

    USART_Init(USART1, &USART_InitStructure);

   

    /* Enable USART1 Receive and Transmit interrupt */

      USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

      USART_ITConfig(USART1, USART_IT_TXE, ENABLE);

   

    USART_Cmd(USART1, ENABLE);

But no better results.

I will try to trace more.

r,S

silicon2
Associate II
Posted on May 17, 2011 at 13:54

Hi,

Does anyone succeed to set up own boudrate of USART1 while using virtual com port. I did't find solution.

r,S

tsuneo
Senior
Posted on May 17, 2011 at 13:54

> I try to comment STM_EVAL_COMInit() but no better results.

It suggests that the USART setting is accidentally changed by the firmware without the supposed function. Wrong pointer operation?

Using debugger, find a code range in which the USART setting is accidentally altered. Narrow down the code range using breakpoints, until the range is distilled into a single code line.

Tsuneo

atobindustries
Associate II
Posted on September 29, 2011 at 22:54

Hello, chinzei.tsuneo

Your explaination is quite elegant. If it wasn't for this site, I would have never been able to use the Virtual Com.

I can send a message to the PC without any problems using:

USB_SIL_Write(EP1_IN,''test'',4); SetEPTxValid(ENDP1);

But how do you receive data from the PC? I looked at the usb_istr.c file, but can't figure it out. It appears to be interrupting all the time. I want to be able to run a routine for decoding the data from the PC. Coming from an 8-bit 8051 background, it was just a matter of testing the RI bit. I did see in the sample code that there is a CALLBACK for EP3_OUT, but I'm having no luck reading anything from the PC.

I have looked at some other code and they seem to be using timer to periodically check if a command has been received. I don't know which way to go. Why are there no clear cut examples for recieving data from a PC using Virtual ComPort?

Do you have code for getting data from the PC?

I have attached the code I am using.

Thanks,

________________

Attachments :

main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0aV&d=%2Fa%2F0X0000000bar%2Fst_FCchWJZEwD4txqHOdyKR7f9R128FSDz_mtd7b8W0&asPdf=false