# FreeRTOS issue buffer ethernet in reception

**URL:** <https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144>\
**Category:** Libraries\
**Tags:** debug\
**Created:** [August 8, 2024, 1:57pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144 "2024-08-08T13:57:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 8, 2024, 1:57pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/1 "2024-08-08T13:57:39Z")

</div>

Hello, when installing stack Ethernet with freeRTOS-TCP library and receives some udp packet, the function pxGetNetworkBufferWithDescriptor return error or malloc failed.  
Seem that missing the memory or somethings like that. Thanks

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [August 8, 2024, 3:11pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/2 "2024-08-08T15:11:18Z")

</div>

@FraGu

If `pxGetNetworkBufferWithDescriptor` returns `NULL`. Then it means either the network buffers are not initialized (see `xNetworkBuffersInitialise`) or there isn’t enough memory in the system.

Which buffer allocation scheme are you using, BufferAllocation\_1.c or BufferAllocation\_2.c?

---

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 8, 2024, 3:26pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/3 "2024-08-08T15:26:41Z")

</div>

Hi Tony, I used BufferAllocation\_2.c. `xNetworkBuffersInitialise`is call correctly

I have 192kb for heap freeRTOS (my board is stm32h735). The error is:

```
if( pxReturn == NULL )
{
    iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER();
}

```

or malloc failed.

Thanks

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [August 8, 2024, 3:38pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/4 "2024-08-08T15:38:11Z")

</div>

How much network buffers have you configured in your project? (check whats `ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS` defined to in your FreeRTOSIPConfig.h)

Also, whats your `configTOTAL_HEAP_SIZE`?

---

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 8, 2024, 3:59pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/5 "2024-08-08T15:59:52Z")

</div>

#define ipconfigNUM\_NETWORK\_BUFFER\_DESCRIPTORS ( 64 )

Happens with this 2 settings  
//#define configTOTAL\_HEAP\_SIZE ( ( size\_t )( 64 \* 1024 ) )  
#define configTOTAL\_HEAP\_SIZE ( ( size\_t )( 192 \* 1024 ) )

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [August 8, 2024, 4:15pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/6 "2024-08-08T16:15:14Z")

</div>

I wonder if the network buffers are lost somewhere.

Are you using UDP zero copy?

---

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 8, 2024, 4:16pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/7 "2024-08-08T16:16:42Z")

</div>

do you mean this?  
#define ipconfigZERO\_COPY\_RX\_DRIVER ( 1 )  
#define ipconfigZERO\_COPY\_TX\_DRIVER ( 1 )

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [August 8, 2024, 4:30pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/8 "2024-08-08T16:30:29Z")

</div>

No, use of [`FreeRTOS_sendto`](https://www.freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/08-sendto) with `FREERTOS_ZERO_COPY` flag.

---

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 8, 2024, 4:44pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/9 "2024-08-08T16:44:31Z")

</div>

you mean

FreeRTOS\_sendto( xSocket, out, strlen( out ), FREERTOS\_ZERO\_COPY, &dest, sizeof(dest) );

The same for FreeRTOS\_recvfrom?

In any case the issue happens only install ethernet IP task and the board receive test broadcast packet into my local lan

Tomorrow morning I’ll try in my lab with your suggestion and then I’ll let you know asap

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [August 8, 2024, 4:52pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/10 "2024-08-08T16:52:04Z")

</div>

> [@FraGu](#):
>
> The same for FreeRTOS\_recvfrom?

yes, check if there is case were the received network buffer is not returned back (lost) to the TCP stack.

---

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 8, 2024, 5:04pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/11 "2024-08-08T17:04:17Z")

</div>

Ok for the same flags for recv.

But need to change somethings into ip-task?

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [August 9, 2024, 5:03am UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/12 "2024-08-09T05:03:35Z")

</div>

Ideally, IP task shouldn’t be changed.  
Please refer - [Receiving UDP Data (zero copy interface)](https://www.freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/04-Tutorial/13-Receiving-UDP-data-zero-copy)

---

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 9, 2024, 6:53am UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/13 "2024-08-09T06:53:24Z")

</div>

Ok I try now but yesterday happens this issue only with ethernet task installation and many packets udp broadcast in the lan from another pc. I let you know asap for my test. Thanks

---

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 9, 2024, 9:43am UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/14 "2024-08-09T09:43:02Z")

</div>

Hi Tony,  
the issue happens like this:  
I simply open a UDP socket on port X and I just listen without any reception (no rx and no tx).

if I receive UNICAST packets like ping everything is OK.

if I receive BROADCAST packets on port X the system fails after a few seconds

For receive broadcast packets need setting something into socket option?

---

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 9, 2024, 10:12am UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/15 "2024-08-09T10:12:40Z")

</div>

Hi Tony, other debug.

if I call in the loop the function the situation is ok

lBytes = FreeRTOS\_recvfrom( xSocket, &ptr, 0, FREERTOS\_ZERO\_COPY, &xClient, &xClientAddressLength );

it seems that if broadcast packets for an open UDP socket are not read, the packets remain in the list without being freed. What do you think?

Maybe could be happens for unicast packet without call FreeRTOS\_recvfrom?

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [August 10, 2024, 2:40pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/16 "2024-08-10T14:40:22Z")

</div>

@FraGu

Yes, if you are not receiving packets on the socket, they will remain in the `pxSocket->u.xUDP.xWaitingPacketsList` list without getting freed until you run out of network buffers.

Have you defined the config - [`ipconfigUDP_MAX_RX_PACKETS`](https://www.freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/06-Configuration#ipconfigudp_max_rx_packets) in your FreeRTOSIPConfig.h? If it is enabled, you can define the maximum number of packets that can exist in the Rx queue of a UDP socket. Unless you receive packets to your application from the list (using `FreeRTOS_recvfrom`), the subsequent packets will be dropped (network buffers will be freed) till there is more space in the list by the IP-task.

You can customise this value per UDP socket with the `FREERTOS_SO_UDP_MAX_RX_PACKETS` socket option. [[refer](https://www.freertos.org/Documentation/03-Libraries/02-FreeRTOS-plus/02-FreeRTOS-plus-TCP/09-API-reference/11-setsockopt)]

---

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 10, 2024, 3:12pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/17 "2024-08-10T15:12:01Z")

</div>

@tony-josi-aws

ok perfect and many thanks for explanation

---

<div class="post-metadata">

**Author:** ![tony-josi-aws](https://avatars.discourse-cdn.com/v4/letter/t/a6a055/32.png) [@tony-josi-aws](https://forums.freertos.org/u/tony-josi-aws)\
**Post date:** [August 10, 2024, 3:26pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/18 "2024-08-10T15:26:59Z")

</div>

Thanks for reporting back.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [August 11, 2024, 4:35pm UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/19 "2024-08-11T16:35:25Z")

</div>

> Maybe could be happens for unicast packet without call FreeRTOS\_recvfrom?

@tony-josi-aws explains it well, there is a self defense mechanism against UDP attacks. As soon as a UDP message buffer is full, subsequent packets will be dropped.

It is recommended to define `FREERTOS_SO_UDP_MAX_RX_PACKETS` in your FreeRTOSIPConfig.h file.

---

<div class="post-metadata">

**Author:** ![FraGu](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@FraGu](https://forums.freertos.org/u/FraGu)\
**Post date:** [August 12, 2024, 6:11am UTC](https://forums.freertos.org/t/freertos-issue-buffer-ethernet-in-reception/21144/20 "2024-08-12T06:11:16Z")

</div>

ok Thanks. I’ll define this settings into my library TCP
