STM32H743 FreeRTOS+TCP issue with ZERO Copy, this time UDP

Hello again,

I have some news to share. I’ve created a function to check within vReleaseNetworkBufferAndDescriptor if the UDP network buffers that I allocate at startup through FreeRTOS_GetUDPPayloadBuffer are being released. It is actually the case:

Below you can see the check:

void vReleaseNetworkBufferAndDescriptor( NetworkBufferDescriptor_t * const pxNetworkBuffer )
{
    BaseType_t xListItemAlreadyInFreeList;
    bool houstonWeHaveAProblem = false;

    if(ext_adc_check_buff_add_reserved(&( pxNetworkBuffer->pucEthernetBuffer[ sizeof( UDPPacket_t ) ] ))) {
      houstonWeHaveAProblem = true;
    }

This part of the code is triggered wich eventually releases the allocated UDP buffers for Zero-Copy:

        /* When a packet has been transmitted, the descriptor must be
         * prepared for a next transmission.
         * When using zero-copy, the network buffer must be released
         * ( i.e. returned to the pool of network buffers ). */

        if( ( ulISREvents & EMAC_IF_TX_EVENT ) != 0U )
        {
            vClearOptionBit( &( ulISREvents ), EMAC_IF_TX_EVENT );

            if( xSemaphoreTake( xTransmissionMutex, 10000U ) != pdFAIL )
            {
                ETH_Clear_Tx_Descriptors( &( xEthHandle ) );
                xSemaphoreGive( xTransmissionMutex );
            }
        }

and then:

                #if ( ipconfigZERO_COPY_TX_DRIVER != 0 )
                    {
                        NetworkBufferDescriptor_t * pxNetworkBuffer;
                        uint8_t * ucPayLoad;

                        ucPayLoad = ( uint8_t * ) xDMATxDescriptor->DESC0;

                        if( ucPayLoad == NULL )
                        {
                            /* No buffer is assigned or DMA still OWNs this descriptor. */
                            break;
                        }

                        pxNetworkBuffer = pxPacketBuffer_to_NetworkBuffer( ucPayLoad );

                        if( pxNetworkBuffer != NULL )
                        {
                            vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
                        }
                    }
                #endif /* if ( ipconfigZERO_COPY_TX_DRIVER != 0 ) */

From the comment I understand that this behavior is indeed wanted. It seems that the buffers allocated when in ZERO-Copy need to be released after each transmission. This is quite a killer for my application as I use the buffers in an ISR continuously and I can not call every time I send a packet FreeRTOS_GetUDPPayloadBuffer to allocate a new one, as it is not permitted in the ISR.

Is there a fundamental reason behind releasing the allocated buffers when in ZERO-Copy always after each transmission?, or would be ok to modify this?

I am now reassigning a new buffer for the SAI ISR to fill in once I send each packet by using FreeRTOS_GetUDPPayloadBuffer and it is working fine. I would say I have a solution working but I think it would be good to document somewhere (maybe I’ve overseen it) that FreeRTOS_GetUDPPayloadBuffer just works for 1 packet.

I’ve seen at least one post in the past from somebody who was using as well FreeRTOS_GetUDPPayloadBuffer to preassign buffers, so the info will be surely help for future developments.

It would be of course great to find a solution to keep the FreeRTOS_GetUDPPayloadBuffer buffers reserved without impact in performance until they are explicitly released by the application. This would spare me one call to FreeRTOS_GetUDPPayloadBuffer per packet and the related speed impact (my STM32H7 is at its limits :wink: ).

Thank again for your support!, I am really happy with FreeRTOS+TCP, it is perfectly stable (in comparison to LWIP which was very unreliable and stopping working after a few dozen hours) and very fast

1 Like

Thank you reporting back your solution. We will update the documentation.

Hi Gaurav, so the FreeRTOS_GetUDPPayloadBuffer will be kept as it is. There is no intention to modify it or add a function which would reserve the buffers until they are explicitly released by the application?