cancel
Showing results for 
Search instead for 
Did you mean: 

udp_recv() callback function problem

Julian Winpenny
Associate II
Posted on December 06, 2017 at 13:17

LwIp

MCU: STM32F765

Custom hardware

STM32Cube FW_F7 V1.8.0

udp_recv() callback function has stopped working since last STM32CubeMX update (4.23)

Anyone know what is wrong please?

void UDP_ConnectTask(void * pvParameters)

{

int rc1, rc2;

uint16_t localport;

RestoreDataServerParams();

/* Remote address */

UDPDataServer.addr = ipaddr_addr(UDPDataServerAddressString);

// netconn_gethostbyname ('hostname', UDPDataServer.addr)

UDPDataServerPort = atoi(UDPDataServerPortString);

localport = 1091;

while(true)

{

datapcb = udp_new();

if (datapcb == NULL)

{

printf('udp_new failed!\n');

}

/* bind to any IP address */

if ( (rc1 = udp_bind(datapcb, IP_ADDR_ANY, localport)) != ERR_OK)

{

printf('udp_bind failed!\n');

}

else

{

/* set udp_echo_recv() as callback function

for received packets */

udp_recv(datapcb, udp_recv_funct, NULL);

}

if ( rc1 == ERR_OK )

{

do

{

printf('Connecting to UDP server\r\n');

rc2 = udp_connect(datapcb, &UDPDataServer, UDPDataServerPort);

if ( rc2 == ERR_OK )

{

printf('UDP data client connected\r\n');

UPDDataConnectionValid = true;

IsUDPClientConnected = true;

while ( UPDDataConnectionValid )

{

osDelay(1);

}

printf('Connection invalid\r\n');

vTaskSuspend(xUDPRecvTaskHandle);

}

if ( rc2 != ERR_ABRT )

{

printf('UDP connect client error (%d)\r\n', rc2);

netconn_delete(UDP_nc);

break;

}

osDelay(1000);

} while (true);

}

else

{

printf('Unable to create new network connection\r\n');

}

}

}

/*

* @brief Callback function for handling received UDP data

*/

void udp_recv_funct(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)

{

char *data;

#if SHOW_RX_HEX

uint8_t j = 0;

#endif

#define LINE_LEN 16

if (p != NULL)

{

#if SHOW_RX_CH | SHOW_RX_HEX

printf('UDP Rx: \r\n');

#endif

data = p->payload;

for ( int i = 0; i < p->len; i++ )

{

/* Write to receive fifo */

//fifo_write_u8( *data, &UDPrxFifo );

if ( i < sizeof(SocketRxBuf) )

{

SocketRxBuf[i] = *data;

#if SHOW_RX_HEX

printf('%02X ', *data);

if ( ++j == LINE_LEN )

{

j = 0;

printf('\r\n');

}

#else

#if SHOW_RX_CH

printf('%c', *data);

#endif

#endif

data++;

}

}

#if SHOW_RX_CH | SHOW_RX_HEX

putstr('\r\n');

#endif

NumBufInFromSocket = p->len;

/* Notify Eric */

xQueueSend( xUDPDATARx, ( void * ) &SocketRxBuf, 0 );

/* free the pbuf */

pbuf_free(p);

}

}
1 REPLY 1
Julian Winpenny
Associate II
Posted on December 06, 2017 at 13:28

When UDP pcaket sent to the device

LwIP stack responds with ICMP 70 Destination unreachable (Port unreachable)