This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

lwip api build issue

Hi

Is anyone aware of any issues regarding the use of the lwip api within Starterware?

I have added in some example code (from Design and Implementation of the lwip TCP/IP stack) into a working example project (enetlwip using CCS v5).

I get build errors - first with LWIP_NETCONN not appearing to be set correctly - corrected this, now a whole lot of code appears to throw up errors.  Must an api library be built first?

Regards

Chris

Code as follows:

conn = netconn_new(NETCONN_UDP);

// setup the IP address of remote host ipAddress.

addr = htonl(0xC0A80101);

// connect to the remote host on port number 7000

netconn_connect(conn, &ipAddress, 7000);

// create new netbuf

buf = netbuf_new();

data = netbuf_alloc(buf, 10);

// create some data

for(i = 0; i < 10; i++)

data[i] = i;

// send the data

netconn_send(conn, buf);

// reference the text into the netbuf

netbuf_ref(buf, text, sizeof(text));

// send the text

netconn_send(conn, buf);

// clean up

netconn_delete(conn);

netbuf_delete(buf);

  • Hi Cris,

    I've not used the netcon API, but I have had success with lwIP's low level interface.  I might suggest using it...  This code snip from an older post (http://e2e.ti.com/support/embedded/starterware/f/790/t/171893.aspx) may help.  It sends a periotic broadcast over udp, so you would use your address in place of the broadcast one.  Also, you can delete the ref count code lines which we used for finding a problem in the sitaraif.c driver.  Hope this helps.

    struct udp_pcb* pcb = udp_new();
    struct pbuf *p;
    udp_bind(pcb, IP_ADDR_ANY, 1235);
    char msg[80];
    int packet = 0;

    /* Loop forever. All the work is done in interrupt handlers. */
    while(1)
    {

    packet++;
    p = pbuf_alloc(PBUF_TRANSPORT, sizeof(msg), PBUF_RAM); // allocate a pbuf, (ref=1)
    if (!p || 1!=p->ref)
    {
    UARTPuts("pbuf_alloc failed!\n", -1);
    while (1) ;
    }
    sprintf(msg, "test packet %d", packet);
    memcpy(p->payload, msg, strlen(msg));
    UARTprintf("packet %d, PBuf at 0x%08X, ref = %d sending...", packet, p, p->ref);
    udp_sendto(pcb, p, IP_ADDR_BROADCAST, 1234);
    delay(500); // half second delay - should have plenty of time to send
    UARTprintf("ref is now %d \n", p->ref);
    pbuf_free(p); // ref should be zero after we free.
    }
    }

    Hope this helps.

    Cheers,

    -Jay

  • Hi Jay

    Thanks for the response.

    Yes, I have subsequently moved down to the low level LWIP (after more reading it suggested that threading (and therefore an o/s) is required for the netconn system. I abandoned that and have been able to modify the lwip_echo example to do both TCP and UDP echoing as below:

    Regards

    Chris

    //***********************************************************

    //  UDP receive

    //***********************************************************

    void udp_receive(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)

    {

          udp_connect( pcb, addr, port );

          // now echo rec'd data

          udp_send( pcb, p );

          pbuf_free(p);

    }

     

    //***********************************************************

    //  UDP initialisation - listen

    //***********************************************************

    void UDP_init(void)

    {

          struct udp_pcb *pcb;

     

          pcb = udp_new();

          udp_bind( pcb, IP_ADDR_ANY, UDP_SERVER_PORT );

          // receive callback

          udp_recv( pcb, udp_receive, (void*)0 );

    }