cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f4 Virtual Comm not talking to custom app

cleonb322
Associate III
Posted on September 07, 2017 at 06:02

I am working with the STM32f4 Virtual Comm (code generated by the stmCube). I was able to communicate with my custom app written in c# with visual studio 2012; however, recently it stops communicating with the App. it throws an exception 'This parameter is incorrect'. i don't believe my firmware is wrong because i can communicate just fine with Tera Term also, I don't believe my c# code is incorrect because I can open other comm port with it.

is there a bug in visual studio serial port? 

this is my c# serial init code:

serial_port.PortName = port;//this is 'COM3'

serial_port.DataBits = 8;

serial_port.Parity = Parity.None;

serial_port.StopBits = StopBits.One;

serial_port.BaudRate = 112500;

serial_port.Handshake = Handshake.None;

// Set the read/write timeouts

serial_port.ReadTimeout = 1000;

serial_port.WriteTimeout = 1000;

serial_port.ReadBufferSize = 1024;

serial_port.WriteBufferSize = 1024;
3 REPLIES 3
cleonb322
Associate III
Posted on September 07, 2017 at 06:10

I think i found the problem: In 

static

int8_t

CDC_Control_FS

(

uint8_t

cmd,

uint8_t

* pbuf,

uint16_t

length) function 

the following lines were missing.

case

CDC_GET_LINE_CODING:

pbuf[

1

] = (

uint8_t

)(

115200

>>

8

);

pbuf[

2

] = (

uint8_t

)(

115200

>>

16

);

pbuf[

3

] = (

uint8_t

)(

115200

>>

24

);

pbuf[

4

] =

0

;

// stop bits (1)

pbuf[

5

] =

0

;

// parity (none)

pbuf[

6

] =

8

;

// number of bits (8)

Radek RIPA
ST Employee
Posted on September 07, 2017 at 14:57

Hello,

you are right you are missing the CDC_GET_LINE_CODING and SET_LINE_CODING function.

The VCP still thinks that you are an COM port. For this PC sends the configuration and then reads it back.

If this function is not filled the is possible that the pbuf is filled with random stack values and the PC will receive invalid parameters and error is triggered.

I recommend to use this code:

case CDC_SET_LINE_CODING: 
 ctrl_buffer[0]=pbuf[0];
 ctrl_buffer[1]=pbuf[1];
 ctrl_buffer[2]=pbuf[2];
 ctrl_buffer[3]=pbuf[3];
 ctrl_buffer[4]=pbuf[4];
 ctrl_buffer[5]=pbuf[5];
 ctrl_buffer[6]=pbuf[6];
 break;
case CDC_GET_LINE_CODING: 
 pbuf[0]=ctrl_buffer[0];
 pbuf[1]=ctrl_buffer[1];
 pbuf[2]=ctrl_buffer[2];
 pbuf[3]=ctrl_buffer[3];
 pbuf[4]=ctrl_buffer[4];
 pbuf[5]=ctrl_buffer[5];
 pbuf[6]=ctrl_buffer[6];
 break;�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

And define array for storage:

/* USER CODE BEGIN PRIVATE_VARIABLES */
uint8_t ctrl_buffer[7];
/* USER CODE END PRIVATE_VARIABLES */�?�?�?

Best regards

Radek

Posted on September 08, 2017 at 03:36

thanks.

I wonder why it works without it on 'Tera Term' .