On 7/10/2020 9:04 AM, Jon Bean wrote:
Patrick, you are correct its an issue with the addr. I think its
because I am assigning it in the rx function, but then the addr
pointer is destroyed so I end up with a NULL pointer. Is there some
way to copy the address in LWIP? I had some issues with the code you
sent. I had to use addr->addr as it didn't like addr.ip4.addr.
Thanks
Jon
You don't want a pointer to the IPv4 address. You want to copy the
structure to your own copy. You should probably just do something like
this:
Declare the global udp_addr structure:
ip_addr_t udp_addr; (instead of "ip_addr_t *udp_addr;)
Then in your receive code:
memcpy((void *)&udp_addr, (void *)&addr, sizeof(ip_addr_t));
Now you have a real copy of the originating IP address.
Your send code might want to check the udp_addr.addr has actually been
set before you try to use it?
I've been using LwIP with the TIVA platform over 5 years (maybe 7?) and
it has been working quite well for me. I'm sure you'll be able to get
things working without too much (more) trouble.
Patrick
On 10/07/2020 13:37, Patrick Klos wrote:
On 7/10/2020 8:19 AM, Jon Bean wrote:
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
I would double check exactly what's in your udp_addr and udp_port
variables.
Add this line (or something equivalent) to your eth_udp_rx() function:
printf("eth_udp_rx: addr=%08x port=%04x udp_addr=%08x
udp_port=%04x\n",
addr.ip4.addr, port, udp_addr.ip4.addr,
udp_port);
(what version of LwIP are you using? I still have 1.4.1 on my TIVA
Launchpad)
See if (make sure) you get the same numbers to start with.
Patrick
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
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users