lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] UDP send example


From: Patrick Klos
Subject: Re: [lwip-users] UDP send example
Date: Fri, 10 Jul 2020 08:37:54 -0400
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]