STM32F407 + LWIP + UDP: receiving is stopped after 9packets

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Adam
Posts: 18
Joined: Thu Sep 05, 2013 1:53 pm

STM32F407 + LWIP + UDP: receiving is stopped after 9packets

Post by Adam »

Hi!

I´m using mcu STM32F407VGT6 with ChibiOS + LWIP stack. I trying to receive broadcast packets.
I´m using blocking function netconn_recv. After reset, I can receive exactly first 9 incomming packets, then receiving is stopped a fuction still waits for incomming packets. I confident, that packets are comming (checked by wireshark).
Here is my code of receiving thread:

Code: Select all

WORKING_AREA(waThread_NetworkCTRL, 2048);
msg_t Thread_NetworkCTRL(void *arg) {

  LWIP_UNUSED_ARG(arg);
  chRegSetThreadName("NetworkCtrl");

  static struct netconn *conn_ctrl_recv;
  static struct netbuf *recv_buf;

  err_t err;

  conn_ctrl_recv = netconn_new(NETCONN_UDP); // create new connection
  err = netconn_bind(conn_ctrl_recv, IP_ADDR_ANY, port_ctrl); // bind the connection

  while(1){
    // create buffer
    recv_buf = netbuf_new();
    //receive
    err = netconn_recv(conn_ctrl_recv, &recv_buf);

    if(err == ERR_OK){
      printMsg("Incomming packet!\n");
    }
    netbuf_free(recv_buf);
    netbuf_delete(recv_buf);
  }
  netconn_disconnect(conn_ctrl_recv);
  return (msg_t)0;
}


And here is simple python script for generating broadcast packets:

Code: Select all

import socket
import time

UDP_IP = "192.168.10.255"
UDP_PORT = 33001
MESSAGE = "ETC:NOTIFY;"

MESSAGE.encode ('utf-8')
UDP_IP.encode ('utf-8')

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
while(1):
  sock.sendto(bytes(MESSAGE, "utf-8"), (UDP_IP, UDP_PORT))
  time.sleep(1) # delays for 5 seconds



Do you know how to solve my problem? Debug is "ON", but cant catch anything.

Thank you!

Adam
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F407 + LWIP + UDP: receiving is stopped after 9pack

Post by Giovanni »

Hi,

What is the state of the system after the 9 packets? crashed or threads continue running?

Giovanni
Adam
Posts: 18
Joined: Thu Sep 05, 2013 1:53 pm

Re: STM32F407 + LWIP + UDP: receiving is stopped after 9pack

Post by Adam »

I dont have the device with me at this moment, so i cant tell you state of thread or chibios exactly. But answer for your question is: the device is not crashing, after 9 packets everything works except receiving next packets. The behavior of device i can describe this way: after receive nineth packet, program go to the function netconn_recv() and waits for 10th packet, but never come. However 10th packet is already send from transmitter. When i pause debugger, MCU is paused in "idle thread".

Thank you, Giovanni.

Adam
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F407 + LWIP + UDP: receiving is stopped after 9pack

Post by Giovanni »

Hi,

There are several entities involved:
1) Hardware.
2) MAC driver.
3) lwIP interface layer.
4) lwip thread.
5) lwIP.
6) Application.

We need to check from 1 to 6. First, after the 9th packet, does the MAC driver continue to receive frames (a breakpoint in the ISR could tell us this). Then does the lwip thread continue to serve those frames and send them to lwIP (again a breakpoint in the thread could reveal this) and so on.

You need to understand where the flow stops. I never used lwIP much so I can't help at that level.

Also, do the debugging at -O0 optimization and enable the debug options in chconf.h, something could get caught by an assertion.

Giovanni
Adam
Posts: 18
Joined: Thu Sep 05, 2013 1:53 pm

Re: STM32F407 + LWIP + UDP: receiving is stopped after 9pack

Post by Adam »

Hi Giovanni,

debug is already turned on, as well compiler optimize -O0.
Nothing is catched. When I pause the device, the state of receiving thread after 9th packets is WTSEM. I found part of code, where thread is waiting: its in function

Code: Select all

msg_t chSemWaitTimeoutS(Semaphore *sp, systime_t time) 


here is trace log of called functions:

Code: Select all

netconn_recv(conn_ctrl_recv, &recv_buf);
netconn_recv_data(struct netconn *conn, void **new_buf);
sys_arch_mbox_fetch(&conn->recvmbox, &buf, 0);
chMBFetchS(*mbox, (msg_t *)msg, tmo)
chSemWaitTimeoutS(&mbp->mb_fullsem, time); <-- here is waiting.


Where can I find ISR´s of MACdriver?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F407 + LWIP + UDP: receiving is stopped after 9pack

Post by Giovanni »

Hi,

In ./os/hal/platforms/stm32/mac_lld.c, there is a specific section in the file for ISRs.

Giovanni
Adam
Posts: 18
Joined: Thu Sep 05, 2013 1:53 pm

Re: STM32F407 + LWIP + UDP: receiving is stopped after 9pack

Post by Adam »

It seems the problem is solved! The problem was in a bad use netbuf buffer.

This is WRONG:

Code: Select all

static struct netbuf *recv_buf;
recv_buf = netbuf_new();
netconn_recv(conn_ctrl_recv, &recv_buf);


This is CORRECT:

Code: Select all

static struct netbuf *recv_buf;
netconn_recv(conn_ctrl_recv, &recv_buf);


Conclusion:
Dont create new netbuf buffer before use netconn_recv()!

Giovanni, thank you for your help!

Adam
Post Reply