Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

USB CDC Serial sometimes slow to recv data

Status
Not open for further replies.

iamthemik3

Newbie level 2
Joined
Aug 3, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
I'm working on a cross-platform serial library (in C) to communicate to a USB CDC microcontroller (msp430). I have been noticing that when I run my program in linux, it works fantastically well. However, on Mac OSX or Windows 7/XP, every once i a while a packet of data takes a significant time to be received by my program. Since the behavior is pretty specific, I'll explain the gory details of what I am doing and when the lag occurs.

For flow control reasons and to keep buffer sizes small on the microcontroller, I designed a simple handshaking scheme to transfer data.
Ideally, my PC program and the microcontroller (MCU) would communicate in a packet format as follows:


PC <-- MCU - MCU sends the PC a 4-byte header to the PC
PC <-- MCU - MCU sends a 128-byte payload
PC --> MCU - PC sends a 4-byte acknowledgement that it is ready for the next packet
...repeat...


The above works fine when my program runs on linux (which is enough confirmation for me that it is not a microcontroller issue)

When running the program on OSX or Windows, it is able to recv about a dozen packets correctly and then it does this:

PC <-- MCU - MCU sends the PC a 4-byte header to the PC
PC x-- MCU - MCU transmits the 128-byte payload, but the PC doesn't recv it immediately
.......... - MCU is now waiting for an ACK while the PC program is waiting for the payload
...The MCU times out after several seconds of waiting (as it should). Then the PC finally gets the payload.

So, why does this happen?
Each packet transaction normally happens very quickly. Does the PC get overwhelmed with all the activity? Buffers shouldn't be filling up since I don't allow them to because of the handshaking. Increasing the timeout period on each end doesn't really help either (and a 10 second timeout is way too much anyways)

I have attached the source code for the abstraction layer that handles sending and getting data from the serial device. One thing to note is that I originally wrote it using only POSIX calls to make it easy to port to the other OS's. I rewrote portions for windows to use the native API and it reduced the frequency of these "stalls" occuring but it still messes up sometimes.

View attachment serial_io.zip

Hopefully I explained what I am observing well enough. Let me know if I need to clarify anything.
-Alex
 

The PC shouldn't get overwhelmed. Have you tried hooking up a CATC analyzer to see what is actually happening on the USB bus?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top