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.

[FAQ] MCU-PLUS-SDK-AM263X: How to increase number of UDP or TCP connections in LwIP examples?

Part Number: MCU-PLUS-SDK-AM263X

Tool/software:

Hi Team,

I am using the lwip examples provided in the am263x mcu_plus_sdk and trying to connect multiple UDP clients to UDP server. I am only able to connect 4 sockets and for the rest of the socket creation, I get an error stating socket creation failed. Is it a memory limitation? Can someone help me enable more sockets?

  • Note: This guide is valid for all the devices in the MCU_PLUS_SDK. For easy reference, the FAQ uses AM263x. To use it for other devices, just replace the AM263x references with the device of your choice.

    Hi,

    The LwIP stack and the am26x devices are capable of supporting a high number of simultaneous TCP/UDP connections. The out-of-box LwIP stack is configured to have 3 RAW connections, 4 UDP and 5 TCP active connections simultaneously. This is to avoid the bloating of the LwIP stack. For example. if you need 20 total active connections, please follow the steps below:

    1. In your SDK, navigate to: "\mcu_plus_sdk\source\networking\lwip\lwip-config\am263x\enet\lwipopts.h "
    2. For RAW APIs (native LwIP APIs), the MACRO MEMP_NUM_RAW_PCB, is set to 3 by default. To increase the number of RAW connections supported, increase this value.
    3. For UDP, the MACRO MEMP_NUM_UDP_PCB, is set to 4 by default. It means the number of UDP protocol control blocks is 4. You need one per active UDP "connection". Let's say you need 20 active UDP connections, then you will have to increase it to 20.
    4. For TCP, the MACRO MEMP_NUM_TCP_PCB, is set to 5 by default. It means the number of simultaneously active TCP connections. is 5. Let's say you need 20 active TCP connections, then you will have to increase it to 20.
      If you want to increase the number of TCP listening connections, increase the value of MEMP_NUM_TCP_PCB_LISTEN.
    5. If your application sends out a lot of data from a static memory, you would also need to increase MEM_NUM_PBUF value.
    6. If you require more memory pools, you will also need to increase the memory pools allocation in "\mcu_plus_sdk\source\networking\lwip\lwip-config\am263x\enet\lwippools.h ". Here increase the number of elements for the element size of 1568.

    LwIP library cannot be re-compiled from CCS. To re-compile the LwIP Stack by using the following steps:

    1. From the top-level mcu_plus_sdk folder, run the following commands. (Make sure you run these steps in the SDK that is linked to your CCS project). 

      # Add PROFILE=debug to build for debug
      # replace nortos with freertos if you want to build freertos based lwip libs
       
      # CLEAN
      gmake -sj -f makefile.am263x lwipif-cpsw-nortos_r5f.ti-arm-clang_clean
      gmake -sj -f makefile.am263x lwip-nortos_r5f.ti-arm-clang_clean
      gmake -sj -f makefile.am263x lwip-contrib-nortos_r5f.ti-arm-clang_clean
       
      # BUILD
      gmake -sj -f makefile.am263x lwipif-cpsw-nortos_r5f.ti-arm-clang
      gmake -sj -f makefile.am263x lwip-nortos_r5f.ti-arm-clang
      gmake -sj -f makefile.am263x lwip-contrib-nortos_r5f.ti-arm-clang

    2. Re-build your application and make sure the updated library is linked to the application.
    3. Try to establish multiple connections. You should now be able to open multiple simultaneous sockets for UDP and TCP.

    Additional references:

    Best Regards,
    Shaunak