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.

AM2732: LWIP: how to increase the max transfer size for netconn_write()

Part Number: AM2732


Hi,

My customer would like to transfer big size of data from ethernet but failed.

I tried to add below code in C:\ti\mcu_plus_sdk_am273x_08_04_00_17\examples\networking\lwip\enet_cpsw_tcpclient\app_tcpclient.c and also failed to transfer the data successfully. The return error code is -14, which means "/** Connection reset. */".

static const uint32_t APP_CLIENT_TX_MSG2[6400] = {2};

err = netconn_write(pConn, APP_CLIENT_TX_MSG2, sizeof(uint32_t)*6000, NETCONN_COPY);
if (err == ERR_OK)
{
printf("APP_CLIENT_TX_MSG2 6000 was sent to the Server\r\n");
}
else
{
DebugP_log("couldn't send APP_CLIENT_TX_MSG2 6000 packet to server\r\n");
continue;
}

If the size for netconn_write is sizeof(uint32_t)*5500, it can work ok.

How to increase the transfer size of netconn_write()?

Is the max size of netconn_write() related to below macro? If yes, what's the relationship? 

C:\ti\mcu_plus_sdk_am273x_08_04_00_17\source\networking\lwip\lwip-config\am273x\lwipopts.h

/* TCP Maximum segment size. */
#define TCP_MSS 1460

/* TCP sender buffer space (bytes). */
#define TCP_SND_BUF  (16 * TCP_MSS) 

/* TCP sender buffer space (pbufs). This must be at least = 2 *
TCP_SND_BUF/TCP_MSS for things to work. */
#define TCP_SND_QUEUELEN (8 * TCP_SND_BUF/TCP_MSS)

/* TCP writable space (bytes). This must be less than or equal
to TCP_SND_BUF. It is the amount of space which must be
available in the tcp snd_buf for select to return writable */
#define TCP_SNDLOWAT (TCP_SND_BUF/2)

/* TCP receive window. */
#define TCP_WND (TCP_SND_BUF)

/* Maximum number of retransmissions of data segments. */
#define TCP_MAXRTX 12

/* Maximum number of retransmissions of SYN segments. */
#define TCP_SYNMAXRTX 4

#define DEFAULT_THREAD_STACKSIZE (5 * 1024)
#define TCPIP_THREAD_STACKSIZE (8 * 1024)

Thanks,

Chris

  • Hi Chris,

    I have started to look into this issue. Will be updating you for the progress

  • Chris, What is the size of packets you want to transfer, Limitation is it should be less than 1500 bytes, i.e standard ethernet packet. Are you trying jumbo ethernet frames?

    BR

    Nilabh A.

  • Nilabh,

    It is ok to use standard packet size. I just want to send a big buffer data to call netconn_write once. Would you pls help to check again?

    Thanks,

    Chris

  • Hi Chris,

    Let me check on my side and get back.

    BR

    Nilabh A.

  • Nilabh,

    Any update?

    Thanks,

    Chris

  • Hi Chris,

    I am looking into it. Please expect a reply by early next week.

    BR

    Nilabh A.

  • Is there any new discovery of the problem?This problem is very important for our products.

  • Hi Chris,

    Firstly, lets discuss on why netconn_write worked with "sizeof(uint32_t)*5500,".

    If you check the default memory configurations, the size of TCP send buffer is calculated as=> TCP_SND_BUF  (16 * TCP_MSS) = 23,360 bytes

    The data that you were trying to send was 5500*4 22,000 bytes.

    TCP_SND_BUF had a limit of 23,360 bytes and your data was 22,000 bytes. In the other case, you were trying to send data of size (6000*4) = 24,000 bytes when you had a default limit of 23,360 bytes.

    Secondly, to increase the maximum transfer size, you have to make sure the TCP_SND_BUF > data_to_send

    If you change TCP_SND_BUF to 18*TCP_MSS, it will allow you to transfer data upto 26,280 bytes, which will let you send the data of size sizeof(uint32_t)*6000

     

    Thanks, and BR,

    Shaunak

  • Shaunak,

    Thanks for your reply. My customer would like to send bigger package one time and they tried to change TCP_SND_BUF to 140*TCP_MSS but met new error.

    C:/ti/mcu_plus_sdk_am273x_08_04_00_17/source/networking/lwip/lwip-stack/src/core/init.c:151:2: error: "If you want to
    use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h (or enable window scaling)"
    #error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h (or e...

    Then I enabled window scaling by change below code at C:\ti\mcu_plus_sdk_am273x_08_04_00_17\source\networking\lwip\lwip-stack\src\include\lwip/opt.h.

    #if !defined LWIP_WND_SCALE || defined __DOXYGEN__
    #define LWIP_WND_SCALE 1 //0
    #define TCP_RCV_SCALE 14//0
    #endif

    Then I rebuid the lib and met new errors.

    Compiling: lwip-freertos.am273x.r5f.ti-arm-clang.debug.lib: C:/ti/mcu_plus_sdk_am273x_08_04_00_17/source/networking/lwip/lwip-stack/src/core/init.c
    C:/ti/mcu_plus_sdk_am273x_08_04_00_17/source/networking/lwip/lwip-stack/src/core/init.c:297:2: error:
    "lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN. If you know what you
    are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
    #error "lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN. If you know ...
    ^
    C:/ti/mcu_plus_sdk_am273x_08_04_00_17/source/networking/lwip/lwip-stack/src/core/init.c:309:2: error:
    "lwip_sanity_check: WARNING: TCP_SNDLOWAT must at least be 4*MSS below u16_t overflow!"
    #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must at least be 4*MSS below u16_t overflow!"
    ^
    C:/ti/mcu_plus_sdk_am273x_08_04_00_17/source/networking/lwip/lwip-stack/src/core/init.c:318:2: error:
    "lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE *
    (PBUF_POOL_BUFSIZE - protocol headers). If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1
    to disable this error."
    #error "lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZ...
    ^
    3 errors generated.
    gmake[1]: *** [makefile.stack.am273x.r5f.ti-arm-clang:237: init.obj] Error 1
    gmake: *** [makefile.am273x:212: lwip-freertos_r5f.ti-arm-clang] Error 2

    Then I define LWIP_DISABLE_TCP_SANITY_CHECKS to 1. I rebuild and met error again.

    C:/ti/mcu_plus_sdk_am273x_08_04_00_17/source/networking/lwip/lwip-stack/src/core/tcp.c:937:61: error: result of
    comparison of constant 102200 with expression of type 'u16_t' (aka 'unsigned short') is always false
    [-Werror,-Wtautological-constant-out-of-range-compare]
    if (TCP_SEQ_GEQ(new_right_edge, pcb->rcv_ann_right_edge + LWIP_MIN((TCP_WND / 2), pcb->mss))) {
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    C:/ti/mcu_plus_sdk_am273x_08_04_00_17/source/networking/lwip/lwip-stack/src/include\lwip/def.h:66:32: note: expanded
    from macro 'LWIP_MIN'
    #define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y))
    ^
    C:/ti/mcu_plus_sdk_am273x_08_04_00_17/source/networking/lwip/lwip-stack/src/include\lwip/priv/tcp_priv.h:112:59: note:
    expanded from macro 'TCP_SEQ_GEQ'
    #define TCP_SEQ_GEQ(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) >= 0)
    ^
    1 error generated.
    gmake[1]: *** [makefile.stack.am273x.r5f.ti-arm-clang:237: tcp.obj] Error 1
    gmake: *** [makefile.am273x:212: lwip-freertos_r5f.ti-arm-clang] Error 2

    It seems related to the first error we met.

    Would you pls help again on how to support TCP_SND_BUF to 140*TCP_MSS?

    Thanks,

    Chris

  • Hi Chris, I spent some time and realized I had wrongly understood the problem.

    The issue was that we are facing a failure in memory allocation for the large sized packet, but there is no error/assert in the program for this condition.

    I do have a temporary fix for the same to help you send large packets for now:

    --- "a/.\\source\\networking\\lwip\\lwip-config\\am273x\\lwippools.h"
    +++ "b/.\\source\\networking\\lwip\\lwip-config\\am273x\\lwippools.h"
    @@ -8,9 +8,9 @@
      
     #if MEM_USE_POOLS
     LWIP_MALLOC_MEMPOOL_START
    -LWIP_MALLOC_MEMPOOL(25, 128)
    -LWIP_MALLOC_MEMPOOL(18, 1568)
    -LWIP_MALLOC_MEMPOOL(4, 4096)
    +LWIP_MALLOC_MEMPOOL(100, 128)
    +LWIP_MALLOC_MEMPOOL(100, 1792)
    +LWIP_MALLOC_MEMPOOL(14, 4096)
     LWIP_MALLOC_MEMPOOL_END
     #endif /* MEM_USE_POOLS */

    Terminal output: 

    ==========================
      CPSW LWIP TCP CLIENT    
    ==========================
    EnetPhy_bindDriver: PHY 0: OUI:080028 Model:23 Ver:01 <-> 'dp83867' : OK
    PHY 0 is alive
    Starting lwIP, local interface IP is dhcp-enabled
    Host MAC address-0 : 70:ff:76:1d:ec:f2
    [LWIPIF_LWIP] NETIF INIT SUCCESS
    [LWIPIF_LWIP] Enet has been started successfully
    Enet IF UP Event. Local interface IP:0.0.0.0
    Waiting for network UP ...
    Waiting for network UP ...
    Network Link UP Event
    Waiting for network UP ...
    Waiting for network UP ...
    Enet IF UP Event. Local interface IP:192.168.1.4
    Network is UP ...
     TCP Client Menu: 
     Enter TCP server IPv4 address:(example: 192.168.101.100)
    192.168.1.3
     IP eneterd is: 192.168.1.3 
    <<<< ITERATION 1 >>>>
     Connecting to: 192.168.1.3:8888 
    Connection with the server is established
    APP_CLIENT_TX_MSG2 6000 was sent to the Server
    Successfully received the packet 0
    Connection closed
    

    I have filed a bug for the same: [MCUSDK-8854] Enet_cpsw_tcpclient failing to send large sized data, no warning/assert - Texas Instruments JIRA (ti.com)

    Thanks, and BR,

    Shaunak