lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] ERR_MEM after write [LwIP 1.4]


From: Julio Cesar Aguilar Zerpa
Subject: [lwip-users] ERR_MEM after write [LwIP 1.4]
Date: Fri, 2 Jun 2017 12:33:27 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1

Hi there,

[using LwIP 1.4 - RAW API]

I'm sending data every 50ms with the following function.  As you can see: I check the value of tcp_sndbuf(tpcb) and it is always greater than buffer_size -> even after a while when the server cannot send data anymore and I get the error ERR_MEM.

static void tcpServer_sendRawScanBuffer(struct tcp_pcb *tpcb)
{
    if (!client_connected_)
    {
        debugSerial_display("Not connected. Could not send data buffer");
        return;
    }

    if (buffer_size > tcp_sndbuf(tpcb)) // <<<-------------- I test the value of tcp_sendbuf(tpcb). It is always greater than buffer_size
    {
        debugSerial_display("Not enough memory. Could not send data buffer");

        sys_timeout(130, (sys_timeout_handler)tcpServer_sendRawScanBuffer, tpcb);
        return;
    }

      err_t err = tcp_write(tpcb, raw_data_current->buffer, buffer_size, 0);

    if (err == ERR_OK)
    {
        // ask the TCP stack to send data now.
        err = tcp_output(tpcb);

        if (err != ERR_OK)
        {
            debugSerial_displayValue("tcp output scan data ERROR %d", err);
        }
    }
    else
    {
        debugSerial_displayValue("tcp write scan data ERROR %d", err);   // <<<-------------- I get this error with value -1 (ERR_MEM)

          if (err != ERR_MEM)
          {
              tcpServer_close(tpcb, NULL);
          }
    }

    sys_timeout(50, (sys_timeout_handler)tcpServer_sendRawScanBuffer, tpcb);
}

Below is the memory allocation of my board regarding the lwip parameters. I don't know how to interprete these values, so I also added the definitions of the memory parameters from the lwipopts.h. Maybe you guys know how to read these numbers :-) BTW, I am sending 2226 bytes every 50 ms.

ram_heap = 51.220 (bytes)

TCP_PCB_base = 612

TCP_PCB_LISTEN_base = 228

TCP_SEG_base = 644

SYS_TIMEOUT_base = 204

PBUF_base = 260

PBUF_POOL_base = 147k (!!!!)

// lwipopts.h

#define MEM_SIZE                         (50 * 1024) /* 50K  -> MAX RAM is 512k */
#define MEMP_NUM_PBUF          16
#define MEMP_NUM_TCP_PCB    4
#define PBUF_POOL_SIZE              (4 * MEMP_NUM_PBUF)

#define TCP_MSS                              2226
#define TCP_WND                           (2 * TCP_MSS)
#define TCP_SND_BUF                   (4 * TCP_MSS)
#define TCP_SND_QUEUELEN     ((4 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS))
#define MEMP_NUM_TCP_SEG     2 * TCP_SND_QUEUELEN
#define PBUF_LINK_HLEN               14      /* default is 14 */
#define ETH_PAD_SIZE                     0
#define PBUF_POOL_BUFSIZE        LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_HLEN)

I have reduced and increased the different MEMP_NUM_* values as well as MEM_SIZE and PBUF_POOL_SIZE without success.

I've attached a screenshot from wireshark, where I also don't know what happends. The board (with LwIP) has IP ending with 46 and the client (Laptop Ubuntu) has IP ending with 43.

The 2226 bytes are sent in 2 packages: 1514 + 820 including the headers for both packages. Just before the problem occurs, the board sends the first 1514 bytes and immediately afterwards it tries to restransmitt the same message whithout waiting for any kind of response from the client. Then the client sends an ACK, which I think it's for the first package because the board tries to send the first pacakge again (3rd time) after no ACK for the second package came, and then the second part (820) is sent. But after this point nothing else is being transmitted. Maybe you guys can find an explanation here.

I don't know what to check, how to fix or how to avoid the problem.

Does anyone have any ideas?

Thanks and Best Regards,

Julio

Attachment: wireshark.png
Description: PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]