FreeRTOS issue buffer ethernet in reception

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

@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?

Hi Tony, I used BufferAllocation_2.c. xNetworkBuffersInitialiseis 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

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?

#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 ) )

I wonder if the network buffers are lost somewhere.

Are you using UDP zero copy?

do you mean this?
#define ipconfigZERO_COPY_RX_DRIVER ( 1 )
#define ipconfigZERO_COPY_TX_DRIVER ( 1 )

No, use of FreeRTOS_sendto with FREERTOS_ZERO_COPY flag.

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

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

Ok for the same flags for recv.

But need to change somethings into ip-task?

Ideally, IP task shouldn’t be changed.
Please refer - Receiving UDP Data (zero copy interface)

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

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?

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?

@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 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]

1 Like

@tony-josi-aws

ok perfect and many thanks for explanation

Thanks for reporting back.

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.

1 Like

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