2019-06-10 01:15 AM
Hello,
I'm using a NUCLEO144 board. I've enabled FREERTOS and LWIP.
I have:
From a host on the network, I:
Everything is working fine except when I send 2 messages.
The first one is sent fine, the second one freezes the board:
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.