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