Skip to main content
DFomi.1
Associate II
Mar 25, 2022 11:32 AM UTC
Question

ERR_MEM on lwip stack

Hello!

I use MCU STM32F429ZIT6. My task is to receive data on UART for several hours and copy them to ethernet.

My function to send data (I generated the code in the CubeMX program with no RTOS):

void sendstring (char* buf_str)

{

tcp_sent (ss->pcb, tcp_server_sent)

tcp_write (ss->pcb, (void*)buf_str, strlen(buf_str), 1);

tcp_recved (ss->pcb, strlen(buf_str));

}

In about half an hour (or 10 minutes, or 60 minutes) I can see, that my transmission is aborted. Вebugger crashes into hardfault. I noticed that tcp_write () function returns ERR_MEM infinitily and the condition

"tsp_sndbuf(ss->pcb) < strlen(buf_str)"

is true.

Do you help me?

Maybe I should change some parameters lake MEM_SIZE or PBUF_POOL_SIZE or something else.

This topic has been closed for replies.

2 replies

Bob S
Super User
Mar 25, 2022 3:08 PM UTC

Look at the source code for tcp_write() and read the comments in the function header. It explains why you might get ERR_MEM and what to do about it. Including using tcp_sndbuf() to figure out how much data you can send via tcp_write().

DFomi.1
DFomi.1Author
Associate II
Mar 26, 2022 7:58 AM UTC

Hello!

Thanks for your reply.

I call the function tcp_sndbuf(). And I can really see that I'm running out of memory.

But in my opinion this behavior is strange.

1) I made the send buffer very big

2) I don't have a lot of data

In the debug, I see that the buffer is cleared normally. I see 10164 free space, then 11782 free space. But at some point I see 38 free space and a memory error. What could go wrong? It was simply impossible to accumulate so much data. Maybe the buffer is not cleared? Why might this happen?

Please, help.