LWIP - OUT OF MEMORY Topic is solved

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
User avatar
Skadi
Posts: 60
Joined: Fri Apr 17, 2015 5:10 pm
Has thanked: 4 times
Been thanked: 3 times

LWIP - OUT OF MEMORY

Post 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);
    }
 }

}
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: LWIP - OUT OF MEMORY

Post 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
User avatar
Skadi
Posts: 60
Joined: Fri Apr 17, 2015 5:10 pm
Has thanked: 4 times
Been thanked: 3 times

Re: LWIP - OUT OF MEMORY

Post 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
User avatar
Skadi
Posts: 60
Joined: Fri Apr 17, 2015 5:10 pm
Has thanked: 4 times
Been thanked: 3 times

Re: LWIP - OUT OF MEMORY

Post 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
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: LWIP - OUT OF MEMORY

Post 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!)
Post Reply