Hi Patrick
That solved the crashing problem thanks. Problem is that I never receive
the data. If I send from the receive function it works fine. But doing
it from the LWIP timer handler it never arrives. The udp_sendto function
returns without any errors, just no data arrives. Any idea why?
Thanks
Jon
On 10/07/2020 13:06, Patrick Klos wrote:
On 7/10/2020 6:44 AM, Jon Bean wrote:
Hi
I am trying to setup an application on a Texas Instruments TIVA micro
controller. What I am trying to do is first receive a UDP packet from
a pc to the board. I then want to be able to send packets back when I
have data to send. I have managed to do this using the UDP echo
example. But this send a packet back when it gets a response. I tried
calling my send function from a loop in main. But it just crashed. I
asked on the TI form and was told I need to call the udp_sendto
function from an interrupt. I cahnged the code so that it is aclled
from the LWIP timer handler. But its still crashing. Can anyone see
an issue with the code below or have a working example? Thanks
The udp_addr and udp_port vars are what I set when I get the receive
packet from the host. The new_udp_pcb is created in my setup function.
void eth_udp_tx()
{
struct pbuf *p;
uint8_t buf[4];
p = pbuf_alloc(PBUF_TRANSPORT, 4, PBUF_POOL);
p->len = 4;
p->tot_len = 4;
p->payload = buf;
if (p)
{
udp_sendto(new_udp_pcb, p, udp_addr, udp_port);
pbuf_free(p);
}
}
I'm pretty sure it's a bad idea to replace the point in p->payload
with your own pointer. That might be your entire problem? Copy your
data to the payload buffer provided and try that.
Also note, you don't have to set p->len or p->totlen - LwIP handles
that for you in most or all cases.
If that doesn't work, here is the code I use to send a simple UDP
packet: (udp_data is an array of bytes)
p = pbuf_alloc(PBUF_TRANSPORT, sizeof(udp_data), PBUF_RAM);
if (p)
{
memcpy(p->payload, udp_data, sizeof(udp_data));
i = udp_sendto(udp_pcb, p, &broadcast_address,
my_ip_port);
if (i != ERR_OK)
{
printf("Got error %d when sending UDP packet!\n", i);
}
else
{
if (debug)
printf("Sent (%d.%03d microseconds [%d])\n",
subtick/120, ((subtick%120)*1000)/120, subtick);
}
pbuf_free(p);
}
else
{
printf("Couldn't allocate a pbuf!!\n");
}
Good luck!
Patrick Klos
Klos Technologies, Inc.
_______________________________________________
lwip-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/lwip-users