LWIP Problem UDP

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
stormracer
Posts: 14
Joined: Mon Jun 11, 2012 9:50 pm

LWIP Problem UDP

Post by stormracer »

Hello
i'm working on a project with LWIP on the stm32f4 discovery. Therefor i have three threads which handles the ethernet connection.
One thread receive packages and put them on can bus. Another receive can packages an send them on udp. A third thread send on udp parallel.

My problem is, when only the can bus threads are active all is working, but when i enable the third thread the other doesn't receive packages any more.

My code for udp is:
UDP receive

Code: Select all

conn = netconn_new(NETCONN_UDP);
if((t = netconn_bind(conn, IP_ADDR_ANY, 1242)) != ERR_OK)
   chprintf((BaseSequentialStream *)&SD1, "ERROR %d\r\n", t);
   for(;;){
      err = netconn_recv(conn, &buf);
   ...
   }
}

UDP send

Code: Select all

conn = netconn_new( NETCONN_UDP );
netconn_bind(conn, IP_ADDR_ANY, 1234 ); //local port
netconn_connect(conn, IP_ADDR_BROADCAST, 1235 );
buf = netbuf_new();
for(;;){
   netconn_send(conn, buf);
   ...
}


UDP send parallel

Code: Select all

conn = netconn_new( NETCONN_UDP );
//netconn_bind(conn, IP_ADDR_ANY, 1240 ); //local port
netconn_connect(conn, IP_ADDR_BROADCAST, 1241 );
buf = netbuf_new();
for(;;){
   netconn_send(conn, buf);
   ...
}

If I enable this code the other thread doesn't receive anything. Without this all is working.

A port scan with nmap shows that the port 1242 is "1242/udp open|filtered unknown".

Christian
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: LWIP Problem UDP

Post by Giovanni »

I am not an lwIP expert, are those lwIP functions reentrant? if not you cannot call them from different threads.

Just to be sure, check thread stacks.

Giovanni
mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Been thanked: 1 time

Re: LWIP Problem UDP

Post by mabl »

Looks good to me. Note that you might run out of netconn/udp buffers or so. Check the return error codes and have a look at the Lwip error statistics (see the console example in the lwip contrib repo.)

@Givoanni: netconn is reentrant. RAW API is not.
stormracer
Posts: 14
Joined: Mon Jun 11, 2012 9:50 pm

Re: LWIP Problem UDP

Post by stormracer »

Hello,
thanks for the hint with the statistics. But i found no error or problem.

I have attached a test output after sending 15 UDP Packets, i expect 15 answer packets but i got only one. After the third thread is ready reinitialized, i got no packet.

Code: Select all

Stats UDP
recv 15
cachehit 0
checkerr 0
drop 0
err 0
fw 0
lenerr 0
memerr 0
opterr 0
proterr 0
rterr 0
xmit 4

Stats SYS
sys mbox 4
sys mutex 0
sys sem 5

Stats MEM
mem avail 1600
mem err 0
mem illegal 0
mem max 208
mem used 208

Stats Link
Recv 19
cachehit 0
checkerr 0
drop 0
err 0
fw 0
lenerr 0
memerr 0
opterr 0
proterr 0
rterr 0
xmit 6


I think the stats are Okay.

Christian
Post Reply