cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F2xx VCP Open Port Failed

ho
Associate II
Posted on October 20, 2014 at 07:48

I am using STM32F2xx and I emulate it as a VCP driver, I used the sample code from STM32 for the USB device example

I wrote a .NET application to open the serial port communication, but I have problem to open the port.

The error stack is below:

System.IO.IOException The parameter is incorrect

My problem could be well summarised in the link below, I have the identical problem with it! I could open the serial port using a terminal program(TeraTerm) but my application cant open

http://stackoverflow.com/questions/14885288/io-exception-error-when-using-serialport-open

I believe it is the firmware problem, anyone face this problem and managed to solve this?
11 REPLIES 11
Amel NASRI
ST Employee
Posted on October 20, 2014 at 11:05

I believe it is the firmware problem, anyone face this problem and managed to solve this?

Which firmware do you mean?

Is this related to your thread ''

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F2xx%20USB%20VCP%20firmware%20example

'' in which you confirmed that it is working fine? Or this is a new issue?

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

ho
Associate II
Posted on October 20, 2014 at 11:24

Yes, that is working fine and this is a new issue.

This doest not happen all the time, sometimes it occurs sometimes it doesnt, even using the same firmware 

chen
Associate II
Posted on October 20, 2014 at 11:56

Hi

First verify that the problem is in the STM32 and not your .net code.

Do this by using another program (eg terminal emulator) with the STM32 USB CDC device.

Your problem may be with your 'faulty .net' code.

If the PC does not close (and release) the COMM port then the USB disconnect and USB connect/re-enumeration will fail because the COMM port is in use still.

ho
Associate II
Posted on October 20, 2014 at 12:27

Yup I have verified the problem,

when I failed to open using my .NET application, I used terminal emulator (TeraTerm) application to open it, and it can open without any problem.

Then, I close the TeraTerm application, and retry to open the port using .NET it fails again.

chen
Associate II
Posted on October 20, 2014 at 12:50

Hi

''when I failed to open using my .NET application, I used terminal emulator (TeraTerm) application to open it, and it can open without any problem.

Then, I close the TeraTerm application, and retry to open the port using .NET it fails again.''

This points to your .net application being the problem NOT the STM32 USB CDC device implementation.

This is the wrong forum to ask about .Net stuff.

Try a Windows .Net forum.

ho
Associate II
Posted on October 21, 2014 at 02:50

Thank you, I will check again!

I have one more question, currently I am sending 512 bytes every second from my STM using the STM VCP driver

I am able to receive the data in my PC, but it takes about 8 second before the data is callback into my application, 

I notice that the PC needs to wait for 4096 bytes before the data is callback,

Is there anyway I can set the STM VCP driver or the firmware for the data receive buffer to be smaller (512 bytes) so it can callback faster or set the latency timer to 1ms?

chen
Associate II
Posted on October 21, 2014 at 10:11

''I am able to receive the data in my PC, but it takes about 8 second before the data is callback into my application, 

I notice that the PC needs to wait for 4096 bytes before the data is callback,

Is there anyway I can set the STM VCP driver or the firmware for the data receive buffer to be smaller (512 bytes) so it can callback faster or set the latency timer to 1ms?''

It is unclear from you post whether your problem is on the PC send/receive or in the STM32.

Yes, both have issues :

The PC VCP driver has issues about buffer size and emptying it.

Depending on how the STM32 has been implemented, it too can have problems with buffer latency.

I am affraid that I do not have a solution for this, we worked around the issues.

ho
Associate II
Posted on October 21, 2014 at 10:22

I have problem when I receive the data in PC using the STM VCP,

it needs to wait 4096 bytes to fill up before I receive the data..

May I know how do you work around it?

I need it to get the data every 1 ms (timeout) or set the buffer to be 512 bytes.

chen
Associate II
Posted on October 21, 2014 at 11:10

''I have problem when I receive the data in PC using the STM VCP,

it needs to wait 4096 bytes to fill up before I receive the data..

May I know how do you work around it?''

The main work around was on the PC side but that does not sound like your problem.

(The work around was to do a Send of data followed by another send with no data, for some reason this would force the PC USB VCP driver to send a packet if it was less than 64bytes)

You problem is the STM32 side.

Look at your implementation for

uint16_t USBDataTx( uint8_t * Buf, uint32_t Len )

How does it interact with the buffer

APP_Rx_Buffer

and the index pointer into it

APP_Rx_ptr_in

Do a search for these 2 and work out what the STM USB driver is doing with these!