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.

AM2634: UDP Client Implementation

Part Number: AM2634

Tool/software:

i team,

I am working on UDP client implementation on evaluation Board  so, i am editing this enet_cpsw_rawhttpserver_am263x-cc_r5fss0-0_nortos_ti-arm-clang Project.

Here i am facing an issue when ever evl board(UDP Client) send a data to the server(Computer) it deliver successfully but whenever server send data to client its not deliver to the client(Evl board).

7382.enet_cpsw_rawhttpserver_am263x-cc_r5fss0-0_nortos_ti-arm-clang.zip

Kindly Find out the test projct and please Let me know the issue. Your feedback is more appriciated 

  • Hi Aakash V,

    Can you please confirm the follwing. Not sure if I have the bandwidth right now to go through the whole code.

    1. Can you check lwip_stats (enter "lwip_stats") in CCS expressions window. Don't send any data from MCU to PC, only send data from PC to MCU (the case which you mentioned fails). Inside LwIP stats, check for memory related errors or UDP errors.

    Regards,
    Shaunak

  • Hi Shaunak,

    I tested with lwip_stats in expression i couldn't able to get the value.







    can you please check the zip file of my project which i mentioned above.

  • Hi Aakash V, 

    1. You need to pause your core and then check the stats.

    2. Just a request, the next time you send an application that has been modified by you, it would be great if you share some information about the modifications, code additions made by you/Lotus-Wireless. It is very difficult to just take a "zip" of your project and debug something which you have implemented without any walk-through of the code or any background on how you are testing it. I, at TI, am completely unaware of what you are doing. Also I recommend cleaning up your code (removing the API calls for httpd_init and the files for http server (as far as I am aware you are not using the HTTP server, but it would consume lwip pbufs and memory).

    3. You need to give me some inputs on how do you test the application that you have modified, I run an NCAT server on my linux PC connected to Port-1, I see no data coming onto server from client. I see that you have 2 MAC ports enabled. Which MAC port communicates with the UDP server? I see that the IP for the server is hard-coded to "192.168.2.2" but the netif for MAC port -1 gets IP address dynamically? Can you send some more information? 

    Regards,
    Shaunak

  • Hi Shaunak,


    1. I did Modifications are comment existing http_server application (add udp init, udp send udp receive) functions only rest of the things are same, i removed this fuctions HTTP server function as per your suggestion.

    #include "lwip/pbuf.h"
    #include "lwip/udp.h"
    #include "lwip/tcp.h"
    
    #include "stdio.h"
    #include "string.h"
    
    
    void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
    static void udpClient_send(void);
    
    struct udp_pcb *upcb;
    char buffer[100];
    int counter = 0;
    
    /* IMPLEMENTATION FOR UDP CLIENT :   source:https://www.geeksforgeeks.org/udp-server-client-implementation-c/
    
    1. Create UDP socket.
    2. Send message to server.
    3. Wait until response from server is received.
    4. Process reply and go back to step 2, if necessary.
    5. Close socket descriptor and exit.
    */
    
    
    void udpClient_connect(void)
    {
        err_t err;
    
        /* 1. Create a new UDP control block  */
        upcb = udp_new();
    
        /* Bind the block to module's IP and port */
        ip_addr_t myIPaddr;
        IP_ADDR4(&myIPaddr, 192, 168, 2, 200);
        udp_bind(upcb, &myIPaddr, 8);
    
    
        /* configure destination IP address and port */
        ip_addr_t DestIPaddr;
        IP_ADDR4(&DestIPaddr, 192, 168, 2, 2);
        err= udp_connect(upcb, &DestIPaddr, 7);
    
        if (err == ERR_OK)
        {
            /* 2. Send message to server */
            udpClient_send ();
    
            /* 3. Set a receive callback for the upcb */
            udp_recv(upcb, udp_receive_callback, NULL);
        }
    }
    
    static void udpClient_send(void)
    {
      struct pbuf *txBuf;
      char data[100];
    
      int len = sprintf(data, "sending UDP client message %d", counter);
    
      /* allocate pbuf from pool*/
      txBuf = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
    
      if (txBuf != NULL)
      {
        /* copy data to pbuf */
        pbuf_take(txBuf, data, len);
    
        /* send udp data */
        udp_send(upcb, txBuf);
    
        /* free pbuf */
        pbuf_free(txBuf);
      }
    }
    
    
    void udp_receive_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
    {
        /* Copy the data from the pbuf */
        strncpy (buffer, (char *)p->payload, p->len);
    
        /*increment message count */
        counter++;
    
        /* Free receive pbuf */
        pbuf_free(p);
    }
    

    My requirement to achieve :  when ever this line udp_recv() this should call this udp_receive_callback() function when ever send "hello" or any data but not triggering. so kindly explain this reason for this.

    3.   Hercules/sockettest software are using on windows platform.

  • Hi Aakash,

    This seems to be an implementation issue on your end and nothing to do with TI integration of LwIP. You can try asking this LwIP specific question on the actual LwIP Forum or the LwIP mailing list. As I mentioned before, TI does not own LwIP, it owns only the integration and porting of LwIP in the MCU_PLUS_SDK.

    We already have UDP examples as a part of LwIP stack in the source/networking/lwip/lwip-stack/src/core and source/networking/lwip/lwip-stack/src/apps/udpecho_raw folder. You can try referring them.

    Is the UdpClientSend() function a blocking call? Can you try to comment the udp send function and just try to receive data using udp_recv and confirm that when sending is disabled and only UDP receiving is enabled, you are still not able to receive data?

    I won't be able to prioritize and spend high bandwidth on this until I see an issue on TI software. This is unfortunately something related to your implementation. TI does have a UDP example in the SDK which does send and receive data to/from server.

    Best regards,
    Shaunak

  • Hi Shaunak,

    Thank you for your early replay,

    Is the UdpClientSend() function a blocking call? Can you try to comment the udp send function and just try to receive data using udp_recv and confirm that when sending is disabled and only UDP receiving is enabled, you are still not able to receive data?

    yes, i commented this UdpClientSend() so udp_recv() it is working fine. so, is there any other logic if you know kindly say. because i need to edit in this project only.  

  • Hi Aakash, so far my understanding is:

    UDP client -> UDP server is working

    UDP server -> UDP client is working.

    They are not working only when being called simultaneously because something is blocking the udp_send function. As mentioned earlier, since the issue is not in TI drivers or stack I can't spend much time here since this is something incorrect in your end application (which is not owned by TI). I cannot spend my bandwidth debugging your application when there is nothing wrong with TI's offering. I can only provide a few debugging tips:

    1. Check the UdpClientSend() function logic and check why the udp_recv is not being called, what is blocking the send process? Are the packets not being handed over by LwIP to the ethernet driver? Your callback for receive has not been registered because the send function is blocking.

    2. If you wish to simultaneously send and receive at the same time, you will have to re-evaluate your logic, because this linear code will execute the next step (receive) only after previous (send) is completed and the code returns from UdpClientSend().

    3. Keep halting your core and keep checking the lwip_stats to see if there is something not matching your expected scenario.

    Regards,
    Shaunak Deshpande