cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
1,018 Views
Registered: ‎02-12-2018

unexplained "ERR_MEM" when calling tcp_write (sometimes can't recover)

Jump to solution

Hi,
I'm using the Virtex Ultrascale VCU118, with the Xiling soft Ethernet IP.
Sometimes when the system is under load I'm getting "ERR_MEM" return value from "tcp_write".
according to everything I saw online, I never should have got to the point where I get this return value since before I'm calling "tcp_write", I'm calling "tcp_sndbuf" to see if there's enough space in the pbuf, and there is.

Also, sometimes it ever recovers anf I keep on getting "ERR_MEM" for every "tcp_write".

any suggestions?

code:

uint16_t usAvailable;

usAvailable = tcp_sndbuf(pcb);
if (usAvailable > size)
{
     nErr = tcp_write(pcb, (void *)(address),size, 0);
}

 

FYI: I thought that tcp_sndbuf might also be returning the "ERR_MEM", but it's not, it's returning a valid number.

 

any suggestions? 

 

Thank you,

Gilad

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Participant
Participant
903 Views
Registered: ‎02-26-2019

Hello Again,

To get rid of this error I am using the following routine:

I define this variable to enable sending without wait

u8_t apiflags = TCP_WRITE_FLAG_COPY;// | TCP_WRITE_FLAG_MORE;

 

Then in the sending function I do the following:

_Bool HEAD_FLAG = true; // Used to breake the while loop
while(HEAD_FLAG)
{
if((tcp_sndbuf(send_pcb) > sendpacketheader.packet_length))// To check there is a space in the sending buffer (Same as what you're doing)
{
if(send_pcb->state == CLOSED || (eth_link_status != ETH_LINK_UP))//Checke if the connection is OK
{
xil_printf("tcpip_headerpacket_send send_pcb->state: %d\r\n", send_pcb->state);
active=false;
tcp_abort(send_pcb);
break;
}
err = tcp_write(send_pcb, (uint8_t *)&sendpacketheader.packet_header, sendpacketheader.packet_length, apiflags); // 
if (err != ERR_OK) {
xil_printf("TCP client: Error on tcp_write: %d\r\n", err);
return err;
}
err = tcp_output(send_pcb); // This part sends the packet directly without waiting to filling the buffer. // I think you're missing this part
if (err != ERR_OK) {xil_printf("TCP client: Error on tcp_output: %d\r\n", err); return err; }

HEAD_FLAG = false;
}

// Here I used this function to receive ACK from the other side because if there is no space in the buffer I have to wait it for free space 

// by regular check of the received ACK which means the other side has received some packets

xemacif_input(echo_netif); 

}

 

 

Hope it hepls you.

 

Good Luck

View solution in original post

6 Replies
Highlighted
Participant
Participant
904 Views
Registered: ‎02-26-2019

Hello Again,

To get rid of this error I am using the following routine:

I define this variable to enable sending without wait

u8_t apiflags = TCP_WRITE_FLAG_COPY;// | TCP_WRITE_FLAG_MORE;

 

Then in the sending function I do the following:

_Bool HEAD_FLAG = true; // Used to breake the while loop
while(HEAD_FLAG)
{
if((tcp_sndbuf(send_pcb) > sendpacketheader.packet_length))// To check there is a space in the sending buffer (Same as what you're doing)
{
if(send_pcb->state == CLOSED || (eth_link_status != ETH_LINK_UP))//Checke if the connection is OK
{
xil_printf("tcpip_headerpacket_send send_pcb->state: %d\r\n", send_pcb->state);
active=false;
tcp_abort(send_pcb);
break;
}
err = tcp_write(send_pcb, (uint8_t *)&sendpacketheader.packet_header, sendpacketheader.packet_length, apiflags); // 
if (err != ERR_OK) {
xil_printf("TCP client: Error on tcp_write: %d\r\n", err);
return err;
}
err = tcp_output(send_pcb); // This part sends the packet directly without waiting to filling the buffer. // I think you're missing this part
if (err != ERR_OK) {xil_printf("TCP client: Error on tcp_output: %d\r\n", err); return err; }

HEAD_FLAG = false;
}

// Here I used this function to receive ACK from the other side because if there is no space in the buffer I have to wait it for free space 

// by regular check of the received ACK which means the other side has received some packets

xemacif_input(echo_netif); 

}

 

 

Hope it hepls you.

 

Good Luck

View solution in original post

Highlighted
Observer
Observer
867 Views
Registered: ‎02-12-2018

Thank you!
I'll Give it a try

0 Kudos
Highlighted
Moderator
Moderator
825 Views
Registered: ‎08-25-2009

Hi @lampertg ,

If you've got this resolved, could you please mark the relavent thread as "Accepted Solution" so it will benifit other forum users? Thank you!

 

"Don't forget to reply, kudo and accept as solution."
Highlighted
Observer
Observer
817 Views
Registered: ‎02-12-2018

Sure, It's in my pipeline, as soon as I'll test it and see that it's working, I'll mark it as resolved.

thank you!

0 Kudos
Highlighted
Observer
Observer
749 Views
Registered: ‎02-12-2018

@hossam1984 Thanks again!
the error didn't go away, but it improved the performance (fewer occurrences).

I'll mark it as solved since it is a partial solution.

Highlighted
Participant
Participant
361 Views
Registered: ‎02-16-2018

Hi,

You might want to consider this solution to your problem:

https://forums.xilinx.com/t5/Ethernet/ERR-MEM-on-tcp-write-from-a-corrupt-memory-table-standalone-BSP/m-p/1141250 

The solution is to disable interrupts in ram.c to prevent the Xilinx BSP Hardware layer from interrupting mem_malloc within tcp_write

Best regards
Martin

0 Kudos