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.

Learn to use lwip

Other Parts Discussed in Thread: ENERGIA

Hi,

I'm a beginner in microprocessor programming. I'd like to send some UDP Packets to my AM335x Starter Kit, process the content and send back some packets. My only experience since now in Ehternet programming is using the UDP Class in Energia, wich has a pretty straightforward interface for a beginner like me. But lwip in the AM335x's StarterWare seems to be a bit more complicated. Browsing through the examples brought more questions then answers to me.

What I think I got so far, is that incomming packets generate a interrupt, which initiates a DMA transfer. Did I get it right so far? But how do I use this data then? How is any function called that handles this data? How do I get the system to call my function after receiving packets and pass a pointer to the received data to my function so that it might process the data? And how do I send  data from the board?

I think I'm really missing the basic concept behind all this. So I would be glad if anyone just could describe what happens after receiving a UDP packet, so that I knew what I should look for in the ethernet examples (even if they are TPC and noch UDP examples).

  • Okay... I went through every line of code in the enetEcho example and read the lwip rawapi documentation. I think I now understand a bit more. So I tried to replace the echo_init() function in the example with an own udp_service_init() function, that I wrote by myself, based on the information I got from the different sources. It compiles, but won't work. This is my code, that should receive an udp packet and send it back. It gets an IP Adress after booting, but then, nothing happens. Anyone here who might give a comment on that?

    /*
     * udpServices.c
     *
     *  Created on: 03.08.2016
     *      Author: Janos Buttgereit
     */
    
    #include "udpServices.h"
    #include "lwip/udp.h"
    
    struct ip_addr janosMacIP;
    
    struct udp_pcb *toMatlabUDP;
    
    #define MAX_SIZE                           4096
    
    /*Global copy buffer for echoing data back to the sender */
    unsigned char udpdata[MAX_SIZE];
    
    err_t incommingUDP(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port){
    	struct pbuf *first_p = p;
    	char *data;
    	unsigned int cnt = 0, i;
    	unsigned int len, tot_len;
    	  tot_len = p->tot_len;
    
    	  //pbuf is a linked list
    	  do {
    	        data = (char*)p->payload;
    	        len  = p->len;
    	        for(i = 0; i < len; i++, cnt++)
    	        {
    	            udpdata[cnt] = data[i];
    	        }
    	        //now process the next pbuf until the next pointer points to NULL
    	        p = p->next;
    
    	    }while(p!=NULL);
    
    
    	//first test: send data right back
    	err_t err;
    
    	err = udp_send(toMatlabUDP, first_p);
    
    	pbuf_free(first_p);
    
    	return ERR_OK;
    };
    
    void udp_service_init(){
    
    	IP4_ADDR(&janosMacIP, 192, 167, 1, 102);
    	//which IP Adress & port should be listened to?
    	udp_bind(toMatlabUDP, &janosMacIP, 5050);
    
    	//to which IP Adress & port should the data be sent?
    	udp_connect(toMatlabUDP, &janosMacIP, 5051);
    
    	//which function ist called if new data arrives?
    	udp_recv(toMatlabUDP, (udp_recv_fn)incommingUDP, NULL);
    };
    

  • Janos,

    Could you resolve your issue? or still seeing it?