Page 1 of 1

LWIP - OUT OF MEMORY

Posted: Tue Jun 06, 2017 7:58 pm
by Skadi
Hi,

I'm struggling to read out data via ethernet when I execute the function (FUNCTION()) below a second time.

I'm using LWIP. I send two commands to the microcontroller, the number of samples and iterations.
When I do that once, everything works as it should. But if the function is excecuted a second time the microcontroller seems to get stuck (increase of supply current).

I checked the receive errors recv_err. When I excecute the function a second time the secend receive error returns -1, which stands for Out of memory. I have no clue how to fix this, is the use of NETCONN_COPY a problem? If so, how can I delete the memory occupied by "NETCONN_COPY". I can not use NETCONN_NOCOPY, otherwise my data inside the for loop gets corrupted.

I am grateful for every advice, I already spent two days trying to fix the proplem

BR
Skadi

Code: Select all

static void FUNCTION(struct netconn *conn) {

    struct netbuf *buf;
    unsigned int *data;
    uint16_t len;
    err_t recv_err;

    uint16_t samples;
    uint16_t iterations;
    unsigned int k;

    recv_err = netconn_recv(conn, &buf);

    if (recv_err == ERR_OK) {

        netbuf_data(buf, (void **)&data, &len);
        samples = data[0];

    recv_err = netconn_recv(conn, &buf);

    if (recv_err == ERR_OK) {

        netbuf_data(buf, (void **)&data, &len);
        iterations = data[0];

      for(k=0; k<iterations; k++){

   >> DO SOMETHING leading to DATA <<

         netconn_write(conn, DATA, samples, NETCONN_COPY);
    }
        netbuf_delete(buf);
    }
 }

}

Re: LWIP - OUT OF MEMORY

Posted: Tue Jun 06, 2017 9:22 pm
by Giovanni
Hi,

I cannot help much with lwIP. There are a couple of open problems regarding lwIP in the bug reports forum, you may try to see if the proposed solutions work for you.

viewtopic.php?f=35&t=3866
viewtopic.php?f=35&t=3855

Giovanni

Re: LWIP - OUT OF MEMORY

Posted: Tue Jun 06, 2017 10:23 pm
by Skadi
Hi Giovanni,

thank you for the quick reply!

The first link looks promising. I will have a closer look tomorrow, enough for today ;) .


THX
Skadi

Re: LWIP - OUT OF MEMORY

Posted: Wed Jun 07, 2017 10:34 am
by Skadi
Hi Giovanni,

I had a closer look at both links. I wasn't able to fix my problem according to them.

To fix the problem, I send boht values samples and iterations at once. I have no clue why this makes a difference, but it works fine for me. I will test my program extensively and look if it is stable ;) .

BR
Skadi

Re: LWIP - OUT OF MEMORY

Posted: Wed Jun 07, 2017 2:41 pm
by steved
I've just posted updates to the latest version of lwIP - V2.0.2
Always possible that might affect your problem (and they could do with more testing!)