LWIP STM32F7 UDP Rx Callback Data is not equal to Data Length
Hello together,
I'm using a STM32F769-DISCO Board with STM Cube IDE.
LWIP is activated.
No DHCP, static IP.
Most of the LWIP is default only disabled the DHCP and TCP parts.
First, sending UDP packages is working fine.
My Issue is:
that the receiving udp callback function delivers a udp data length of 22 (p->len = 22). But I only receive 2 Bytes of data in the Rx-buffer (p->payload). The 2 Bytes are filled correctly with data. The rest of the data array is 0.
Does someone have any advise regarding LWIP UDP receiving?
I tried allocating (pbuf_alloc) the buffer and using pbuf_take() , but I did not see any difference.
I think there could be some issues with the buffer address, but I'm honestly at a loss here...
Here the udp init and the receive callback function in "lwip.c":
uint8_t testbuffer[100] = { 0 };
err_t udpServer_init(void)
{
err_t err = ERR_OK;
ip4_addr_t destIPAddr;
ip4_addr_t myIPAddr;
upcb = udp_new();
IP4_ADDR(&myIPAddr, UDP_SERVER_IP_1, UDP_SERVER_IP_2, UDP_SERVER_IP_3, UDP_SERVER_IP_4); //stm ip
err = udp_bind(upcb, &myIPAddr, 52605);
if(upcb == NULL)
{
return ERR_MEM;
}
// Load the static IP of the destination address
IP4_ADDR(&destIPAddr, UDP_CLIENT_IP_1, UDP_CLIENT_IP_2, UDP_CLIENT_IP_3, UDP_CLIENT_IP_4);
// Connect to the other port
err = udp_connect(upcb, &destIPAddr, UDP_CLIENT_PORT);
if(err == ERR_OK)
{
//send msg to server
ZKW_eFLAT_query_status();
// Set the receive function
udp_recv(upcb, udp_receive_callback, NULL);
}
else
{
udp_remove(upcb);
}
return err;
}
void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
uint32_t len = 0;
uint8_t idata[100] = { 0 };
len = p->len;
if(len == 22)
{
strncpy(testbuffer, (char*) p->payload, p->len);
/* allocate pbuf from pool*/
if(p != NULL)
{
/* copy data to pbuf */
for(uint8_t i = 0; i <= 100; i++)
{
idata[i] = testbuffer[i];
}
/* free pbuf */
pbuf_free(p);
}
}
}
Thank you very much
