win32: simulated IO issue?

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: utzig, lbednarz, tfAteba, barthess, RoccoMarco

User avatar
russian
Posts: 323
Joined: Mon Oct 29, 2012 3:17 am
Location: Jersey City, USA
Has thanked: 14 times
Been thanked: 9 times

win32: simulated IO issue?

Postby russian » Tue Mar 04, 2014 4:55 am

I have recently discovered the magic of win32 ChibiOS port and I was hoping to use it for functional testing of my project.
Unfortunately I am having some weirdness with I-O which I am able to reproduce even with ch.exe - the Win32 demo:

connect to ch.exe via putty, paste a magic line into putty:

Code: Select all

q1q2q3q4q5w1w2w3w4w5r1r2r3r4r5t1t2t3t4t5y1y2y3y4y5

but on the screen you get

Code: Select all

q1q2q3q4q5w1w2w3t2t3t4t5y1y2y3y4 ?

The problem is not that the line is truncated, it has some of the characters missing! After 'w3' I am expecting to see 'w4' but I get 't2'? The whole 'r1' section is missing!!
Here is a screenshot:
Image

I am using 2.6.3, I am compiling with cygwin toolchain - I had to change one line in the Makefile and add winsock import into serial.h to get this compile.

As a reference, here is the same magic line sent into stm32f4-discovery-mems demo:
Image
On this screenshot you see that the whole line is there, it is not truncated and nothing is missing.

Please confirm that I am not crazy :)

User avatar
Giovanni
Site Admin
Posts: 13113
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 764 times
Been thanked: 646 times
Contact:

Re: win32: simulated IO issue?

Postby Giovanni » Tue Mar 04, 2014 9:09 am

Hi,

It is just that the shell has an hard limit for input lines, 64 bytes if I remember well. After the limit the line is processed.

Giovanni

User avatar
russian
Posts: 323
Joined: Mon Oct 29, 2012 3:17 am
Location: Jersey City, USA
Has thanked: 14 times
Been thanked: 9 times

Re: win32: simulated IO issue?

Postby russian » Tue Mar 04, 2014 1:34 pm

The problem is not that the line is truncated, it has some of the characters missing! After 'w3' I am expecting to see 'w4' but I get 't2'? The whole 'r1' section is missing!!

This works one way with stm32f4 and anther way with win32? Different buffer size?

Also, my magic line is 50 characters long.

User avatar
russian
Posts: 323
Joined: Mon Oct 29, 2012 3:17 am
Location: Jersey City, USA
Has thanked: 14 times
Been thanked: 9 times

Re: win32: simulated IO issue?

Postby russian » Tue Mar 04, 2014 4:11 pm

I've tried to investigate and here are my first findings:

original code of Win32/serial_lld.c is

Code: Select all

static bool_t inint(SerialDriver *sdp) {

  if (sdp->com_data != INVALID_SOCKET) {
    int i;
    uint8_t data[32];


    /*
     * Input.
     */
    int n = recv(sdp->com_data, data, sizeof(data), 0);


Here is an interesting observation: if I REDUCE this socket read buffer, I get DIFFERENT results - at least the bytes are not missing. The red is a picture with original ChibiOS code, the green is with REDUCED socket read buffer:

Image

Image

I am sorry but this does not look right at all. I would be happy to see a truncated message in Shell, but I need reliable IO which does not take random bytes out.

User avatar
Giovanni
Site Admin
Posts: 13113
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 764 times
Been thanked: 646 times
Contact:

Re: win32: simulated IO issue?

Postby Giovanni » Tue Mar 04, 2014 8:23 pm

This looks like some error in the simulated I/O, I will add this to the TODO list, not an high priority however.

Giovanni

User avatar
russian
Posts: 323
Joined: Mon Oct 29, 2012 3:17 am
Location: Jersey City, USA
Has thanked: 14 times
Been thanked: 9 times

Re: win32: simulated IO issue?

Postby russian » Tue Mar 04, 2014 8:30 pm

Giovanni wrote:not an high priority however.

This is understandable.

Do you want me to create a defect in SF tracker so that there is a ticket to track this issue?

User avatar
Giovanni
Site Admin
Posts: 13113
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 764 times
Been thanked: 646 times
Contact:

Re: win32: simulated IO issue?

Postby Giovanni » Tue Mar 04, 2014 8:43 pm

Sure, create it. Just put a link here as documentation.

Giovanni

User avatar
russian
Posts: 323
Joined: Mon Oct 29, 2012 3:17 am
Location: Jersey City, USA
Has thanked: 14 times
Been thanked: 9 times

Re: win32: simulated IO issue?

Postby russian » Tue Mar 04, 2014 9:38 pm

https://sourceforge.net/p/chibios/bugs/468/

Also here is funny observation: in the q1q2q3q4q5w1w2w3t2t3t4t5y1y2y3y4 line it looks like we have 16 characters, then exactly 16 characters are missing and then the transfer resumes. This must mean something :)

User avatar
Giovanni
Site Admin
Posts: 13113
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 764 times
Been thanked: 646 times
Contact:

Re: win32: simulated IO issue?

Postby Giovanni » Tue Mar 04, 2014 9:42 pm

Probably this is related to sockets being able to fill the input queue faster than the simulated ChibiOS application is able to consume, the result is the lost data.
You may try increasing the queue size in halconf.h.

Giovanni

theShed
Posts: 50
Joined: Tue Feb 26, 2013 3:43 pm
Location: The flatlands of East Anglia

Re: win32: simulated IO issue?

Postby theShed » Tue Mar 04, 2014 9:49 pm

Exacly the same thing happens with the POSIX (Linux) version.

Try changing the serial buffer size in the apps halconf.h to match the serial_lld buffer size
#define SERIAL_BUFFERS_SIZE 32
That seems to fix the Linux build.

I suspect that the input queue buffer is overflowing when it tries to jam 32 bytes into a 16 byte buffer.
Giovanni will have a better understanding of exactly what happens....

--
mike


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 5 guests