cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F429ZI freezes with FreeRTOS and LWIP UDP when both send and received are used

Serge.ohmi
Associate II

Hello,

I'm using a NUCLEO144 board. I've enabled FREERTOS and LWIP.

I have:

  • one thread in charge of endlessly sending (netconn_sendto) out a message to a distant host and sleeps for a second osDelay(1000)
  • a second thread in charge of receiving data from the network, it binds to a specific port and endlessly try to read something from the network (netconn_recv)

From a host on the network, I:

  • Ping the card
  • I have a listener who displays the messages sent by the sending thread
  • I can send messages to the board.

Everything is working fine except when I send 2 messages.

The first one is sent fine, the second one freezes the board:

  • it does no longer answer ping,
  • it stops sending messages

I should have missed something could anyone help please?

thread start:

  /* init code for LWIP */
  MX_LWIP_Init();
 
  /* USER CODE BEGIN 5 */
  conn = netconn_new(NETCONN_UDP);
  netconn_bind(conn, IP_ADDR_ANY, 1700);
  LWIP_ERROR("udpecho: invalid conn", (conn != NULL), return;);
 
  osThreadDef(udpSrvTask, udpSrvTask, osPriorityNormal, 0, 128);
  udpSrvTaskHandle = osThreadCreate(osThread(udpSrvTask), NULL);
 
  osThreadDef(udpWriterTask, udpWriterTask, osPriorityNormal, 0, 128);
  udpWriterTaskHandle = osThreadCreate(osThread(udpWriterTask), NULL);

sender thread:

void  udpWriterTask(void const * argument)
{
//	  struct netconn *conn;
	  struct netbuf *tx_buf;
	  err_t err;
	  char *adr;
	  LWIP_UNUSED_ARG(argument);
      char cString[ 50 ];
	  uint32_t ulCount = 0UL;
	  uint32_t dest = inet_addr( "192.168.20.112" );
	  u16_t lgMsg;
 
//	  conn = netconn_new(NETCONN_UDP);
//	  netconn_bind(conn, IP_ADDR_ANY, 1700);
//	  LWIP_ERROR("udpecho: invalid conn", (conn != NULL), return;);
 
	  while (1)
	  {
	      tx_buf = netbuf_new();
	      sprintf( cString, "Standard send message number %lu\r\n", ulCount );
	      lgMsg=strlen(cString);
	      netbuf_alloc(tx_buf, lgMsg);
 
	      LWIP_UNUSED_ARG(adr);
 
	      pbuf_take(tx_buf->p, (const void *)cString, lgMsg);
 
	      err = netconn_sendto(conn, tx_buf, (const ip_addr_t *)&(dest), 1700 );
	      if(err != ERR_OK) {
	        LWIP_DEBUGF(LWIP_DBG_ON, ("netconn_send failed: %d\n", (int)err));
	      } else {
	        LWIP_DEBUGF(LWIP_DBG_ON, ("got %s\n", buffer));
	      }
	      netbuf_delete(tx_buf);
 
	      ulCount++;
	      osDelay(1000);
	  }
 
}

receiver thread:

void  udpSrvTask(void const * argument)
{
//	  struct netconn *conn;
	  struct netbuf *buf, *tx_buf;
	  err_t err;
	  char *adr;
	  LWIP_UNUSED_ARG(argument);
 
//	  conn = netconn_new(NETCONN_UDP);
//	  netconn_bind(conn, IP_ADDR_ANY, 1700);
//	  LWIP_ERROR("udpecho: invalid conn", (conn != NULL), return;);
 
	  while (1)
	  {
	    err = netconn_recv(conn, &buf);
	    if (err == ERR_OK)
	    {
		  adr=inet_ntoa(buf->addr);
	    }
	    netbuf_delete(buf);
	  }
 
}

struct netconn *conn;

is a global data, I previously included it in both thread, same result.

0 REPLIES 0