AnsweredAssumed Answered

LWIP Free rtos UDP loopback: what is my mistake??

Question asked by dieter 123 on Aug 12, 2017

Hi

2 questions here:

1. Why do I need the osDelay(1) before netbuff_delete()? Without it I get a statistical bug/crash.  

2. why do I need lines x1-x3. Without it no second connection is possible.

 

/*----------------------------------------------------------------------
-------------*/
static void udpecho_thread(void *arg)
{
  err_t err, recv_err;

 

  LWIP_UNUSED_ARG(arg);
  uint8_t send_buffer[32]={0xff};
  uint16_t len = 0;

 


  conn = netconn_new(NETCONN_UDP);
  if (conn!= NULL)
  {
    err = netconn_bind(conn, IP_ADDR_ANY, ARTNET_PORT);

 

    if (err == ERR_OK)
    {
      while (1)
      {

 

        recv_err = netconn_recv(conn, &buf);

 

        if (recv_err == ERR_OK)
        {
          addr = netbuf_fromaddr(buf);
          port = netbuf_fromport(buf);
          len = netbuf_len(buf);
          
          if (len < 700)
            netbuf_copy(buf, &MyData, len);
          if (len > 32)
            netbuf_ref ( buf,send_buffer , 32);
          netconn_connect(conn, addr, port);
          
          netconn_send(conn,buf);
          // why do i need this delay??????????
          osDelay(1);
          netbuf_delete(buf);

 

          //if I uncomment this 3 lines , every thing works fine
          //X1 netconn_delete(conn);
          //X2 conn = netconn_new(NETCONN_UDP);
          //X3 err = netconn_bind(conn, IP_ADDR_ANY, ARTNET_PORT);
      }
      else
      {
        netconn_delete(conn);
      }
     }
  }
 }
}

Outcomes